Fix compilation error triggered with -Werror=sign-compare
[chromium-blink-merge.git] / ui / compositor / dip_util.cc
blobfcecf249555ea0ae77a1893f6091d3e2050918fc
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
3 // found in the LICENSE file.
5 #include "ui/compositor/dip_util.h"
7 #include "base/command_line.h"
8 #include "ui/compositor/compositor.h"
9 #include "ui/compositor/compositor_switches.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/gfx/display.h"
12 #include "ui/gfx/point.h"
13 #include "ui/gfx/point_conversions.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/rect_conversions.h"
16 #include "ui/gfx/size.h"
17 #include "ui/gfx/size_conversions.h"
19 namespace ui {
21 float GetDeviceScaleFactor(const Layer* layer) {
22 return layer->device_scale_factor();
25 gfx::Point ConvertPointToDIP(const Layer* layer,
26 const gfx::Point& point_in_pixel) {
27 return gfx::ToFlooredPoint(
28 gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
31 gfx::PointF ConvertPointToDIP(const Layer* layer,
32 const gfx::PointF& point_in_pixel) {
33 return gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer));
36 gfx::Size ConvertSizeToDIP(const Layer* layer,
37 const gfx::Size& size_in_pixel) {
38 return gfx::ToFlooredSize(
39 gfx::ScaleSize(size_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
42 gfx::Rect ConvertRectToDIP(const Layer* layer,
43 const gfx::Rect& rect_in_pixel) {
44 float scale = 1.0f / GetDeviceScaleFactor(layer);
45 return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale));
48 gfx::Point ConvertPointToPixel(const Layer* layer,
49 const gfx::Point& point_in_dip) {
50 return gfx::ToFlooredPoint(
51 gfx::ScalePoint(point_in_dip, GetDeviceScaleFactor(layer)));
54 gfx::Size ConvertSizeToPixel(const Layer* layer,
55 const gfx::Size& size_in_dip) {
56 return gfx::ToFlooredSize(
57 gfx::ScaleSize(size_in_dip, GetDeviceScaleFactor(layer)));
60 gfx::Rect ConvertRectToPixel(const Layer* layer,
61 const gfx::Rect& rect_in_dip) {
62 float scale = GetDeviceScaleFactor(layer);
63 // Use ToEnclosingRect() to ensure we paint all the possible pixels
64 // touched. ToEnclosingRect() floors the origin, and ceils the max
65 // coordinate. To do otherwise (such as flooring the size) potentially
66 // results in rounding down and not drawing all the pixels that are
67 // touched.
68 return gfx::ToEnclosingRect(
69 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale),
70 gfx::ScaleSize(rect_in_dip.size(), scale)));
73 } // namespace ui