Commit f5a240b6 authored by Brian Liu Xu's avatar Brian Liu Xu Committed by Commit Bot

Fix Views bug causing layers to get stuck at 100% DPI pixel boundaries

This patch fixes logic for snapping layers to physical pixel boundaries,
when pixel canvas is not enabled, by allowing the subpixel offset to be
dynamically computed. Previously, layers could get stuck at 100% DPI
pixel boundaries (making some UI blurry on platforms where fractional
scale factors are used, e.g. Windows), as once an explicit value was
set, the offset would no longer be dynamically computed.

This patch
 - Updates SnapLayerToPixelBoundary to stop View from setting explicit
   subpixel offsets for non-pixel-canvas platforms so that they may be
   auto computed.
 - Updates view_unittest.

Bug: 992730
Change-Id: I8e8c87107f13157e92f125bcfb281226ebc6c422
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761301Reviewed-by: default avatarMalay Keshav <malaykeshav@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Brian Liu Xu <brx@microsoft.com>
Auto-Submit: Brian Liu Xu <brx@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#689171}
parent 5115dce6
...@@ -2386,19 +2386,13 @@ void View::SnapLayerToPixelBoundary(const LayerOffsetData& offset_data) { ...@@ -2386,19 +2386,13 @@ void View::SnapLayerToPixelBoundary(const LayerOffsetData& offset_data) {
DCHECK_EQ(layer()->parent(), layer_beneath->parent()); DCHECK_EQ(layer()->parent(), layer_beneath->parent());
#endif // DCHECK_IS_ON() #endif // DCHECK_IS_ON()
if (snap_layer_to_pixel_boundary_ && layer()->parent() && if (layer()->GetCompositor() && layer()->GetCompositor()->is_pixel_canvas()) {
layer()->GetCompositor()) { gfx::Vector2dF offset = snap_layer_to_pixel_boundary_ && layer()->parent()
if (layer()->GetCompositor()->is_pixel_canvas()) { ? offset_data.GetSubpixelOffset()
layer()->SetSubpixelPositionOffset(offset_data.GetSubpixelOffset()); : gfx::Vector2dF();
for (ui::Layer* layer_beneath : layers_beneath_) layer()->SetSubpixelPositionOffset(offset);
layer_beneath->SetSubpixelPositionOffset(
offset_data.GetSubpixelOffset());
}
} else {
// Reset the offset.
layer()->SetSubpixelPositionOffset(gfx::Vector2dF());
for (ui::Layer* layer_beneath : layers_beneath_) for (ui::Layer* layer_beneath : layers_beneath_)
layer_beneath->SetSubpixelPositionOffset(gfx::Vector2dF()); layer_beneath->SetSubpixelPositionOffset(offset);
} }
} }
......
...@@ -4656,6 +4656,14 @@ TEST_F(ViewLayerTest, SnapLayerToPixel) { ...@@ -4656,6 +4656,14 @@ TEST_F(ViewLayerTest, SnapLayerToPixel) {
GetRootLayer()->GetCompositor()->SetScaleAndSize( GetRootLayer()->GetCompositor()->SetScaleAndSize(
2.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation()); 2.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation());
EXPECT_EQ("0.00 0.00", ToString(v11->layer()->GetSubpixelOffset())); EXPECT_EQ("0.00 0.00", ToString(v11->layer()->GetSubpixelOffset()));
// DSF reset followed by DSF change should update the offset.
GetRootLayer()->GetCompositor()->SetScaleAndSize(
1.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation());
EXPECT_EQ("0.00 0.00", ToString(v11->layer()->GetSubpixelOffset()));
GetRootLayer()->GetCompositor()->SetScaleAndSize(
1.5f, size, allocator.GetCurrentLocalSurfaceIdAllocation());
EXPECT_EQ("0.33 0.33", ToString(v11->layer()->GetSubpixelOffset()));
} }
TEST_F(ViewLayerTest, LayerBeneathTriggersPaintToLayer) { TEST_F(ViewLayerTest, LayerBeneathTriggersPaintToLayer) {
...@@ -5018,6 +5026,14 @@ TEST_F(ViewLayerPixelCanvasTest, SnapLayerToPixel) { ...@@ -5018,6 +5026,14 @@ TEST_F(ViewLayerPixelCanvasTest, SnapLayerToPixel) {
GetRootLayer()->GetCompositor()->SetScaleAndSize( GetRootLayer()->GetCompositor()->SetScaleAndSize(
2.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation()); 2.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation());
EXPECT_EQ("0.00 0.00", ToString(v3->layer()->GetSubpixelOffset())); EXPECT_EQ("0.00 0.00", ToString(v3->layer()->GetSubpixelOffset()));
// DSF reset followed by DSF change should update the offset.
GetRootLayer()->GetCompositor()->SetScaleAndSize(
1.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation());
EXPECT_EQ("0.00 0.00", ToString(v3->layer()->GetSubpixelOffset()));
GetRootLayer()->GetCompositor()->SetScaleAndSize(
1.33f, size, allocator.GetCurrentLocalSurfaceIdAllocation());
EXPECT_EQ("0.06 -0.44", ToString(v3->layer()->GetSubpixelOffset()));
} }
TEST_F(ViewLayerPixelCanvasTest, LayerBeneathOnPixelCanvas) { TEST_F(ViewLayerPixelCanvasTest, LayerBeneathOnPixelCanvas) {
......
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