OLD | NEW |
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/layers/layer.h" | 8 #include "cc/layers/layer.h" |
9 #include "ui/compositor/compositor.h" | 9 #include "ui/compositor/compositor.h" |
10 #include "ui/compositor/compositor_switches.h" | 10 #include "ui/compositor/compositor_switches.h" |
11 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
12 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
13 #include "ui/gfx/geometry/dip_util.h" | 13 #include "ui/gfx/geometry/dip_util.h" |
14 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
15 #include "ui/gfx/geometry/point_conversions.h" | 15 #include "ui/gfx/geometry/point_conversions.h" |
16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/geometry/rect_conversions.h" | 17 #include "ui/gfx/geometry/rect_conversions.h" |
18 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
19 #include "ui/gfx/geometry/size_conversions.h" | 19 #include "ui/gfx/geometry/size_conversions.h" |
20 | 20 |
21 #if DCHECK_IS_ON | 21 #if DCHECK_IS_ON() |
22 #include "ui/compositor/layer_animator.h" | 22 #include "ui/compositor/layer_animator.h" |
23 #endif | 23 #endif |
24 | 24 |
25 namespace ui { | 25 namespace ui { |
26 | 26 |
27 float GetDeviceScaleFactor(const Layer* layer) { | 27 float GetDeviceScaleFactor(const Layer* layer) { |
28 return layer->device_scale_factor(); | 28 return layer->device_scale_factor(); |
29 } | 29 } |
30 | 30 |
31 gfx::Point ConvertPointToDIP(const Layer* layer, | 31 gfx::Point ConvertPointToDIP(const Layer* layer, |
(...skipping 24 matching lines...) Expand all Loading... |
56 gfx::Size ConvertSizeToPixel(const Layer* layer, | 56 gfx::Size ConvertSizeToPixel(const Layer* layer, |
57 const gfx::Size& size_in_dip) { | 57 const gfx::Size& size_in_dip) { |
58 return gfx::ConvertSizeToPixel(GetDeviceScaleFactor(layer), size_in_dip); | 58 return gfx::ConvertSizeToPixel(GetDeviceScaleFactor(layer), size_in_dip); |
59 } | 59 } |
60 | 60 |
61 gfx::Rect ConvertRectToPixel(const Layer* layer, | 61 gfx::Rect ConvertRectToPixel(const Layer* layer, |
62 const gfx::Rect& rect_in_dip) { | 62 const gfx::Rect& rect_in_dip) { |
63 return gfx::ConvertRectToPixel(GetDeviceScaleFactor(layer), rect_in_dip); | 63 return gfx::ConvertRectToPixel(GetDeviceScaleFactor(layer), rect_in_dip); |
64 } | 64 } |
65 | 65 |
66 #if DCHECK_IS_ON | 66 #if DCHECK_IS_ON() |
67 namespace { | 67 namespace { |
68 | 68 |
69 void CheckSnapped(float snapped_position) { | 69 void CheckSnapped(float snapped_position) { |
70 const float kEplison = 0.0001f; | 70 const float kEplison = 0.0001f; |
71 float diff = std::abs(snapped_position - gfx::ToRoundedInt(snapped_position)); | 71 float diff = std::abs(snapped_position - gfx::ToRoundedInt(snapped_position)); |
72 DCHECK_LT(diff, kEplison); | 72 DCHECK_LT(diff, kEplison); |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 #endif | 76 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
87 gfx::PointF view_offset = view_offset_dips; | 87 gfx::PointF view_offset = view_offset_dips; |
88 | 88 |
89 float scale_factor = GetDeviceScaleFactor(layer_to_snap); | 89 float scale_factor = GetDeviceScaleFactor(layer_to_snap); |
90 view_offset.Scale(scale_factor); | 90 view_offset.Scale(scale_factor); |
91 gfx::PointF view_offset_snapped(gfx::ToRoundedInt(view_offset.x()), | 91 gfx::PointF view_offset_snapped(gfx::ToRoundedInt(view_offset.x()), |
92 gfx::ToRoundedInt(view_offset.y())); | 92 gfx::ToRoundedInt(view_offset.y())); |
93 | 93 |
94 gfx::Vector2dF fudge = view_offset_snapped - view_offset; | 94 gfx::Vector2dF fudge = view_offset_snapped - view_offset; |
95 fudge.Scale(1.0 / scale_factor); | 95 fudge.Scale(1.0 / scale_factor); |
96 layer_to_snap->SetSubpixelPositionOffset(fudge); | 96 layer_to_snap->SetSubpixelPositionOffset(fudge); |
97 #if DCHECK_IS_ON | 97 #if DCHECK_IS_ON() |
98 gfx::Point layer_offset; | 98 gfx::Point layer_offset; |
99 gfx::PointF origin; | 99 gfx::PointF origin; |
100 Layer::ConvertPointToLayer( | 100 Layer::ConvertPointToLayer( |
101 layer_to_snap->parent(), snapped_layer, &layer_offset); | 101 layer_to_snap->parent(), snapped_layer, &layer_offset); |
102 if (layer_to_snap->GetAnimator()->is_animating()) { | 102 if (layer_to_snap->GetAnimator()->is_animating()) { |
103 origin = layer_to_snap->GetTargetBounds().origin() + | 103 origin = layer_to_snap->GetTargetBounds().origin() + |
104 layer_to_snap->subpixel_position_offset(); | 104 layer_to_snap->subpixel_position_offset(); |
105 } else { | 105 } else { |
106 cc::Layer* cc_layer = layer_to_snap->cc_layer(); | 106 cc::Layer* cc_layer = layer_to_snap->cc_layer(); |
107 origin = cc_layer->position(); | 107 origin = cc_layer->position(); |
108 } | 108 } |
109 CheckSnapped((layer_offset.x() + origin.x()) * scale_factor); | 109 CheckSnapped((layer_offset.x() + origin.x()) * scale_factor); |
110 CheckSnapped((layer_offset.y() + origin.y()) * scale_factor); | 110 CheckSnapped((layer_offset.y() + origin.y()) * scale_factor); |
111 #endif | 111 #endif |
112 } | 112 } |
113 | 113 |
114 } // namespace ui | 114 } // namespace ui |
OLD | NEW |