Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1778)

Side by Side Diff: ui/compositor/dip_util.cc

Issue 375693006: Snap layers in views to physical pixel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/dip_util.h" 5 #include "ui/compositor/dip_util.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "ui/compositor/compositor.h" 8 #include "ui/compositor/compositor.h"
9 #include "ui/compositor/compositor_switches.h" 9 #include "ui/compositor/compositor_switches.h"
10 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Use ToEnclosingRect() to ensure we paint all the possible pixels 63 // Use ToEnclosingRect() to ensure we paint all the possible pixels
64 // touched. ToEnclosingRect() floors the origin, and ceils the max 64 // touched. ToEnclosingRect() floors the origin, and ceils the max
65 // coordinate. To do otherwise (such as flooring the size) potentially 65 // coordinate. To do otherwise (such as flooring the size) potentially
66 // results in rounding down and not drawing all the pixels that are 66 // results in rounding down and not drawing all the pixels that are
67 // touched. 67 // touched.
68 return gfx::ToEnclosingRect( 68 return gfx::ToEnclosingRect(
69 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale), 69 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale),
70 gfx::ScaleSize(rect_in_dip.size(), scale))); 70 gfx::ScaleSize(rect_in_dip.size(), scale)));
71 } 71 }
72 72
73 void SnapLayerToPhysicalPixelBoundary(ui::Layer* snapped_layer,
74 ui::Layer* layer_to_snap) {
75 DCHECK_NE(snapped_layer, layer_to_snap);
76 if (!snapped_layer || !snapped_layer->Contains(layer_to_snap))
danakj 2014/07/15 21:11:02 Could these be DCHECKs instead? Also can we DCHECK
oshima 2014/07/15 22:28:42 Done.
77 return;
78
79 gfx::Point view_offset_dips = layer_to_snap->GetTargetBounds().origin();
80 ui::Layer::ConvertPointToLayer(
81 layer_to_snap->parent(), snapped_layer, &view_offset_dips);
82 gfx::PointF view_offset = view_offset_dips;
83
84 float scale_factor = GetDeviceScaleFactor(layer_to_snap);
85 view_offset.Scale(scale_factor);
86 gfx::PointF view_offset_snapped(std::round(view_offset.x()),
87 std::round(view_offset.y()));
jamesr 2014/07/08 01:00:59 this moves the layer towards (0, 0). If this is u
88
89 gfx::Vector2dF fudge = view_offset_snapped - view_offset;
90 fudge.Scale(1.0 / scale_factor);
91 layer_to_snap->SetSubpixelPositionOffset(fudge);
92 }
93
73 } // namespace ui 94 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | ui/compositor/layer_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698