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

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: use cc::MathUtil::Round instead 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
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "cc/base/math_util.h"
9 #include "cc/layers/layer.h"
8 #include "ui/compositor/compositor.h" 10 #include "ui/compositor/compositor.h"
9 #include "ui/compositor/compositor_switches.h" 11 #include "ui/compositor/compositor_switches.h"
10 #include "ui/compositor/layer.h" 12 #include "ui/compositor/layer.h"
11 #include "ui/gfx/display.h" 13 #include "ui/gfx/display.h"
12 #include "ui/gfx/point.h" 14 #include "ui/gfx/point.h"
13 #include "ui/gfx/point_conversions.h" 15 #include "ui/gfx/point_conversions.h"
14 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
15 #include "ui/gfx/rect_conversions.h" 17 #include "ui/gfx/rect_conversions.h"
16 #include "ui/gfx/size.h" 18 #include "ui/gfx/size.h"
17 #include "ui/gfx/size_conversions.h" 19 #include "ui/gfx/size_conversions.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Use ToEnclosingRect() to ensure we paint all the possible pixels 65 // Use ToEnclosingRect() to ensure we paint all the possible pixels
64 // touched. ToEnclosingRect() floors the origin, and ceils the max 66 // touched. ToEnclosingRect() floors the origin, and ceils the max
65 // coordinate. To do otherwise (such as flooring the size) potentially 67 // coordinate. To do otherwise (such as flooring the size) potentially
66 // results in rounding down and not drawing all the pixels that are 68 // results in rounding down and not drawing all the pixels that are
67 // touched. 69 // touched.
68 return gfx::ToEnclosingRect( 70 return gfx::ToEnclosingRect(
69 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale), 71 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale),
70 gfx::ScaleSize(rect_in_dip.size(), scale))); 72 gfx::ScaleSize(rect_in_dip.size(), scale)));
71 } 73 }
72 74
75 #if !defined(NDEBUG)
76 namespace {
77
78 void CheckSnapped(float snapped_position) {
79 const float kEplison = 0.0001f;
80 float diff = std::abs(snapped_position - static_cast<int>(snapped_position));
81 DCHECK_LT(diff, kEplison);
82 }
83
84 } // namespace
85 #endif
86
87 void SnapLayerToPhysicalPixelBoundary(ui::Layer* snapped_layer,
88 ui::Layer* layer_to_snap) {
89 DCHECK_NE(snapped_layer, layer_to_snap);
90 DCHECK(snapped_layer);
91 DCHECK(snapped_layer->Contains(layer_to_snap));
92
93 gfx::Point view_offset_dips = layer_to_snap->GetTargetBounds().origin();
94 ui::Layer::ConvertPointToLayer(
95 layer_to_snap->parent(), snapped_layer, &view_offset_dips);
96 gfx::PointF view_offset = view_offset_dips;
97
98 float scale_factor = GetDeviceScaleFactor(layer_to_snap);
99 view_offset.Scale(scale_factor);
100 gfx::PointF view_offset_snapped(cc::MathUtil::Round(view_offset.x()),
danakj 2014/07/17 15:12:14 MathUtil is not meant to be used outside of cc. I
101 cc::MathUtil::Round(view_offset.y()));
102
103 gfx::Vector2dF fudge = view_offset_snapped - view_offset;
104 fudge.Scale(1.0 / scale_factor);
105 layer_to_snap->SetSubpixelPositionOffset(fudge);
106 #if !defined(NDEBUG)
107 gfx::Point p;
108 Layer::ConvertPointToLayer(layer_to_snap->parent(), snapped_layer, &p);
109 cc::Layer* cc_layer = layer_to_snap->cc_layer();
110 gfx::PointF origin = cc_layer->position();
111 CheckSnapped((p.x() + origin.x()) * scale_factor);
112 CheckSnapped((p.y() + origin.y()) * scale_factor);
113 #endif
114 }
115
73 } // namespace ui 116 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698