Commit 5b7677f5 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

aura: Work around race condition in ui::Compositor::SetScaleAndSize

The aura::Window LocalSurfaceId is updated after device scale factor
change via
- aura::Window::OnDeviceScaleFactorChanged, which is called by
- ui::Layer::OnDeviceScaleFactorChanged, which is called by
- ui::Compositor::SetScaleAndSize

But ui::Compositor::SetScaleAndSize takes the aura::Window's
LocalSurfaceId as a parameter.

This means that ui::Compositor::SetScaleAndSize's LocalSurfaceId
argument will be incorrect any time that the DeviceScaleFactor
changes.

Note that the way that aura::Window updates its LocalSurfaceId for
bounds' changes is different. It does not implicitly update the
bounds of its root layer, rather, it requires that the root layer's
bounds be updated before calling ui::Compositor::SetScaleAndSize.

Add a function aura::Window::SetDeviceScaleFactor, to match
aura::Window::SetBounds, which will update the layer's properties
and cause the generation of a new LocalSurfaceId. Make this call in
WindowTreeHost::UpdateRootWindowSizeInPixels (next to the corresponding
call to aura::Window::SetBounds).

Bug: 818085
Change-Id: I929a6e641aa3aa1253e99647ce3bfe05ca7c482a
Reviewed-on: https://chromium-review.googlesource.com/961450
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarFady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542948}
parent 58c96d3d
......@@ -767,6 +767,17 @@ 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) {
if (visible == layer()->GetTargetVisibility())
return; // No change.
......
......@@ -217,6 +217,11 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
// LayoutManager may adjust the 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.
// If present, the window's parent's LayoutManager may adjust the bounds.
void SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen_coords,
......
......@@ -123,6 +123,7 @@ void WindowTreeHost::UpdateRootWindowSizeInPixels(
gfx::ScaleRect(gfx::RectF(bounds), 1.0f / device_scale_factor_);
window()->layer()->transform().TransformRect(&new_bounds);
window()->SetBounds(gfx::ToEnclosingRect(new_bounds));
window()->SetDeviceScaleFactor(device_scale_factor_);
}
void WindowTreeHost::ConvertDIPToScreenInPixels(gfx::Point* point) const {
......
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