Commit effe2887 authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

aura: Special-case allocation of LocalSurfaceId for root.

A LocalSurfaceId allocation/renewal for an aura::Window happens in
response to a bounds or dsf-change to its corresponding ui::Layer.
The root window is special in this regard, since its state can be
changed only by the WindowTreeHost, and should happen before the
ui::Compositor is updated for the new bounds/dsf (since it needs
to provide the LocalSurfaceId to the ui::Compositor).

Window::SetDeviceScaleFactor() is no longer needed after this. So
remove that.

BUG=821987

Change-Id: I3eb674b1c59a2728315125b6eb14b610033f6bf4
Reviewed-on: https://chromium-review.googlesource.com/1012932Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551180}
parent 1ac67ba2
...@@ -68,7 +68,8 @@ void WindowPortLocal::OnPreInit(Window* window) {} ...@@ -68,7 +68,8 @@ void WindowPortLocal::OnPreInit(Window* window) {}
void WindowPortLocal::OnDeviceScaleFactorChanged( void WindowPortLocal::OnDeviceScaleFactorChanged(
float old_device_scale_factor, float old_device_scale_factor,
float new_device_scale_factor) { float new_device_scale_factor) {
if (last_device_scale_factor_ != new_device_scale_factor && if (!window_->IsRootWindow() &&
last_device_scale_factor_ != new_device_scale_factor &&
local_surface_id_.is_valid()) { local_surface_id_.is_valid()) {
last_device_scale_factor_ = new_device_scale_factor; last_device_scale_factor_ = new_device_scale_factor;
local_surface_id_ = parent_local_surface_id_allocator_.GenerateId(); local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
...@@ -94,7 +95,8 @@ void WindowPortLocal::OnVisibilityChanged(bool visible) {} ...@@ -94,7 +95,8 @@ void WindowPortLocal::OnVisibilityChanged(bool visible) {}
void WindowPortLocal::OnDidChangeBounds(const gfx::Rect& old_bounds, void WindowPortLocal::OnDidChangeBounds(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) { const gfx::Rect& new_bounds) {
if (last_size_ != new_bounds.size() && local_surface_id_.is_valid()) { if (!window_->IsRootWindow() && last_size_ != new_bounds.size() &&
local_surface_id_.is_valid()) {
last_size_ = new_bounds.size(); last_size_ = new_bounds.size();
local_surface_id_ = parent_local_surface_id_allocator_.GenerateId(); local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
if (frame_sink_) if (frame_sink_)
......
...@@ -487,7 +487,8 @@ void WindowPortMus::OnPreInit(Window* window) { ...@@ -487,7 +487,8 @@ void WindowPortMus::OnPreInit(Window* window) {
void WindowPortMus::OnDeviceScaleFactorChanged(float old_device_scale_factor, void WindowPortMus::OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) { float new_device_scale_factor) {
if (local_surface_id_.is_valid() && local_layer_tree_frame_sink_) { if (!window_->IsRootWindow() && local_surface_id_.is_valid() &&
local_layer_tree_frame_sink_) {
local_surface_id_ = parent_local_surface_id_allocator_.GenerateId(); local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
local_layer_tree_frame_sink_->SetLocalSurfaceId(local_surface_id_); local_layer_tree_frame_sink_->SetLocalSurfaceId(local_surface_id_);
} }
......
...@@ -1092,7 +1092,6 @@ void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, ...@@ -1092,7 +1092,6 @@ void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window,
} }
return; return;
} }
const float device_scale_factor = window->GetDeviceScaleFactor(); const float device_scale_factor = window->GetDeviceScaleFactor();
ScheduleInFlightBoundsChange( ScheduleInFlightBoundsChange(
window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds), window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds),
......
...@@ -764,17 +764,6 @@ void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { ...@@ -764,17 +764,6 @@ void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
} }
} }
void Window::SetDeviceScaleFactor(float device_scale_factor) {
float old_device_scale_factor = layer()->device_scale_factor();
layer()->OnDeviceScaleFactorChanged(device_scale_factor);
// If we are currently not the layer's delegate, we will not get the device
// scale factor changed notification from the layer (this typically happens
// after animating hidden). We must notify ourselves.
if (layer()->delegate() != this)
OnDeviceScaleFactorChanged(old_device_scale_factor, device_scale_factor);
}
void Window::SetVisible(bool visible) { void Window::SetVisible(bool visible) {
if (visible == layer()->GetTargetVisibility()) if (visible == layer()->GetTargetVisibility())
return; // No change. return; // No change.
......
...@@ -217,11 +217,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate, ...@@ -217,11 +217,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
// LayoutManager may adjust the bounds. // LayoutManager may adjust the bounds.
void SetBounds(const gfx::Rect& new_bounds); void SetBounds(const gfx::Rect& new_bounds);
// Explicitly set a device scale factor for the window. Note that the
// window's device scale factor is also set when adding its ui::Layer to the
// layer tree of a ui::Compositor.
void SetDeviceScaleFactor(float device_scale_factor);
// Changes the bounds of the window in the screen coordinates. // Changes the bounds of the window in the screen coordinates.
// If present, the window's parent's LayoutManager may adjust the bounds. // If present, the window's parent's LayoutManager may adjust the bounds.
void SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen_coords, void SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen_coords,
......
...@@ -37,9 +37,20 @@ ...@@ -37,9 +37,20 @@
namespace aura { namespace aura {
namespace {
const char kWindowTreeHostForAcceleratedWidget[] = const char kWindowTreeHostForAcceleratedWidget[] =
"__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__";
bool ShouldAllocateLocalSurfaceId() {
// When running with the window service (either in 'mus' or 'mash' mode), the
// LocalSurfaceId allocation for the WindowTreeHost is managed by the
// WindowTreeClient and WindowTreeHostMus.
return Env::GetInstance()->mode() == Env::Mode::LOCAL;
}
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WindowTreeHost, public: // WindowTreeHost, public:
...@@ -65,8 +76,8 @@ void WindowTreeHost::InitHost() { ...@@ -65,8 +76,8 @@ void WindowTreeHost::InitHost() {
display::Screen::GetScreen()->GetDisplayNearestWindow(window()); display::Screen::GetScreen()->GetDisplayNearestWindow(window());
device_scale_factor_ = display.device_scale_factor(); device_scale_factor_ = display.device_scale_factor();
InitCompositor();
UpdateRootWindowSizeInPixels(); UpdateRootWindowSizeInPixels();
InitCompositor();
Env::GetInstance()->NotifyHostInitialized(this); Env::GetInstance()->NotifyHostInitialized(this);
} }
...@@ -117,10 +128,20 @@ gfx::Transform WindowTreeHost::GetInverseRootTransformForLocalEventCoordinates() ...@@ -117,10 +128,20 @@ gfx::Transform WindowTreeHost::GetInverseRootTransformForLocalEventCoordinates()
} }
void WindowTreeHost::UpdateRootWindowSizeInPixels() { void WindowTreeHost::UpdateRootWindowSizeInPixels() {
#if DCHECK_IS_ON()
// Validate that the LocalSurfaceId does not change
bool compositor_inited = !!compositor()->root_layer();
auto store_local_surface_id =
compositor_inited ? window()->GetLocalSurfaceId() : viz::LocalSurfaceId();
#endif
gfx::Rect transformed_bounds_in_pixels = gfx::Rect transformed_bounds_in_pixels =
GetTransformedRootWindowBoundsInPixels(GetBoundsInPixels().size()); GetTransformedRootWindowBoundsInPixels(GetBoundsInPixels().size());
window()->SetBounds(transformed_bounds_in_pixels); window()->SetBounds(transformed_bounds_in_pixels);
window()->SetDeviceScaleFactor(device_scale_factor_); #if DCHECK_IS_ON()
if (compositor_inited && ShouldAllocateLocalSurfaceId()) {
DCHECK_EQ(store_local_surface_id, window()->GetLocalSurfaceId());
}
#endif
} }
void WindowTreeHost::ConvertDIPToScreenInPixels(gfx::Point* point) const { void WindowTreeHost::ConvertDIPToScreenInPixels(gfx::Point* point) const {
...@@ -338,12 +359,12 @@ void WindowTreeHost::OnHostResizedInPixels( ...@@ -338,12 +359,12 @@ void WindowTreeHost::OnHostResizedInPixels(
display::Screen::GetScreen()->GetDisplayNearestWindow(window()); display::Screen::GetScreen()->GetDisplayNearestWindow(window());
device_scale_factor_ = display.device_scale_factor(); device_scale_factor_ = display.device_scale_factor();
// The layer, and the observers should be notified of the // Update the state of the root window.
// transformed size of the root window.
UpdateRootWindowSizeInPixels(); UpdateRootWindowSizeInPixels();
// The compositor should have the same size as the native root window host. // Allocate a new LocalSurfaceId for the new state.
// Get the latest scale from display because it might have been changed. if (ShouldAllocateLocalSurfaceId())
window_->AllocateLocalSurfaceId();
compositor_->SetScaleAndSize(device_scale_factor_, new_size_in_pixels, compositor_->SetScaleAndSize(device_scale_factor_, new_size_in_pixels,
window()->GetLocalSurfaceId()); window()->GetLocalSurfaceId());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment