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

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

Issue 750173002: Move dip utils to gfx/geometry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missed android change Created 6 years 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
« no previous file with comments | « content/browser/renderer_host/software_frame_manager.cc ('k') | ui/gfx/geometry/BUILD.gn » ('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/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/safe_integer_conversions.h" 13 #include "ui/gfx/geometry/dip_util.h"
14 #include "ui/gfx/point.h" 14 #include "ui/gfx/point.h"
15 #include "ui/gfx/point_conversions.h" 15 #include "ui/gfx/point_conversions.h"
16 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/rect_conversions.h" 17 #include "ui/gfx/rect_conversions.h"
18 #include "ui/gfx/size.h" 18 #include "ui/gfx/size.h"
19 #include "ui/gfx/size_conversions.h" 19 #include "ui/gfx/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,
32 const gfx::Point& point_in_pixel) { 32 const gfx::Point& point_in_pixel) {
33 return gfx::ToFlooredPoint( 33 return gfx::ConvertPointToDIP(GetDeviceScaleFactor(layer), point_in_pixel);
34 gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
35 } 34 }
36 35
37 gfx::PointF ConvertPointToDIP(const Layer* layer, 36 gfx::PointF ConvertPointToDIP(const Layer* layer,
38 const gfx::PointF& point_in_pixel) { 37 const gfx::PointF& point_in_pixel) {
39 return gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer)); 38 return gfx::ConvertPointToDIP(GetDeviceScaleFactor(layer), point_in_pixel);
40 } 39 }
41 40
42 gfx::Size ConvertSizeToDIP(const Layer* layer, 41 gfx::Size ConvertSizeToDIP(const Layer* layer,
43 const gfx::Size& size_in_pixel) { 42 const gfx::Size& size_in_pixel) {
44 return gfx::ToFlooredSize( 43 return gfx::ConvertSizeToDIP(GetDeviceScaleFactor(layer), size_in_pixel);
45 gfx::ScaleSize(size_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
46 } 44 }
47 45
48 gfx::Rect ConvertRectToDIP(const Layer* layer, 46 gfx::Rect ConvertRectToDIP(const Layer* layer,
49 const gfx::Rect& rect_in_pixel) { 47 const gfx::Rect& rect_in_pixel) {
50 float scale = 1.0f / GetDeviceScaleFactor(layer); 48 return gfx::ConvertRectToDIP(GetDeviceScaleFactor(layer), rect_in_pixel);
51 return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale));
52 } 49 }
53 50
54 gfx::Point ConvertPointToPixel(const Layer* layer, 51 gfx::Point ConvertPointToPixel(const Layer* layer,
55 const gfx::Point& point_in_dip) { 52 const gfx::Point& point_in_dip) {
56 return gfx::ToFlooredPoint( 53 return gfx::ConvertPointToPixel(GetDeviceScaleFactor(layer), point_in_dip);
57 gfx::ScalePoint(point_in_dip, GetDeviceScaleFactor(layer)));
58 } 54 }
59 55
60 gfx::Size ConvertSizeToPixel(const Layer* layer, 56 gfx::Size ConvertSizeToPixel(const Layer* layer,
61 const gfx::Size& size_in_dip) { 57 const gfx::Size& size_in_dip) {
62 return gfx::ToFlooredSize( 58 return gfx::ConvertSizeToPixel(GetDeviceScaleFactor(layer), size_in_dip);
63 gfx::ScaleSize(size_in_dip, GetDeviceScaleFactor(layer)));
64 } 59 }
65 60
66 gfx::Rect ConvertRectToPixel(const Layer* layer, 61 gfx::Rect ConvertRectToPixel(const Layer* layer,
67 const gfx::Rect& rect_in_dip) { 62 const gfx::Rect& rect_in_dip) {
68 float scale = GetDeviceScaleFactor(layer); 63 return gfx::ConvertRectToPixel(GetDeviceScaleFactor(layer), rect_in_dip);
69 // Use ToEnclosingRect() to ensure we paint all the possible pixels
70 // touched. ToEnclosingRect() floors the origin, and ceils the max
71 // coordinate. To do otherwise (such as flooring the size) potentially
72 // results in rounding down and not drawing all the pixels that are
73 // touched.
74 return gfx::ToEnclosingRect(
75 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale),
76 gfx::ScaleSize(rect_in_dip.size(), scale)));
77 } 64 }
78 65
79 #if DCHECK_IS_ON 66 #if DCHECK_IS_ON
80 namespace { 67 namespace {
81 68
82 void CheckSnapped(float snapped_position) { 69 void CheckSnapped(float snapped_position) {
83 const float kEplison = 0.0001f; 70 const float kEplison = 0.0001f;
84 float diff = std::abs(snapped_position - gfx::ToRoundedInt(snapped_position)); 71 float diff = std::abs(snapped_position - gfx::ToRoundedInt(snapped_position));
85 DCHECK_LT(diff, kEplison); 72 DCHECK_LT(diff, kEplison);
86 } 73 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } else { 105 } else {
119 cc::Layer* cc_layer = layer_to_snap->cc_layer(); 106 cc::Layer* cc_layer = layer_to_snap->cc_layer();
120 origin = cc_layer->position(); 107 origin = cc_layer->position();
121 } 108 }
122 CheckSnapped((layer_offset.x() + origin.x()) * scale_factor); 109 CheckSnapped((layer_offset.x() + origin.x()) * scale_factor);
123 CheckSnapped((layer_offset.y() + origin.y()) * scale_factor); 110 CheckSnapped((layer_offset.y() + origin.y()) * scale_factor);
124 #endif 111 #endif
125 } 112 }
126 113
127 } // namespace ui 114 } // namespace ui
OLDNEW
« no previous file with comments | « content/browser/renderer_host/software_frame_manager.cc ('k') | ui/gfx/geometry/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698