dip_util.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.
4
5#include "ui/compositor/dip_util.h"
6
7#include "base/command_line.h"
8#include "ui/base/ui_base_switches.h"
9#include "ui/compositor/compositor.h"
10#include "ui/compositor/compositor_switches.h"
11#include "ui/compositor/layer.h"
12#include "ui/gfx/display.h"
13#include "ui/gfx/point.h"
14#include "ui/gfx/point_conversions.h"
15#include "ui/gfx/rect.h"
16#include "ui/gfx/rect_conversions.h"
17#include "ui/gfx/size.h"
18#include "ui/gfx/size_conversions.h"
19
20namespace ui {
21
22float GetDeviceScaleFactor(const Layer* layer) {
23  return layer->device_scale_factor();
24}
25
26gfx::Point ConvertPointToDIP(const Layer* layer,
27                             const gfx::Point& point_in_pixel) {
28  return gfx::ToFlooredPoint(
29      gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
30}
31
32gfx::PointF ConvertPointToDIP(const Layer* layer,
33                              const gfx::PointF& point_in_pixel) {
34  return gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer));
35}
36
37gfx::Size ConvertSizeToDIP(const Layer* layer,
38                           const gfx::Size& size_in_pixel) {
39  return gfx::ToFlooredSize(
40      gfx::ScaleSize(size_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
41}
42
43gfx::Rect ConvertRectToDIP(const Layer* layer,
44                           const gfx::Rect& rect_in_pixel) {
45  float scale = 1.0f / GetDeviceScaleFactor(layer);
46  return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale));
47}
48
49gfx::Point ConvertPointToPixel(const Layer* layer,
50                               const gfx::Point& point_in_dip) {
51  return gfx::ToFlooredPoint(
52      gfx::ScalePoint(point_in_dip, GetDeviceScaleFactor(layer)));
53}
54
55gfx::Size ConvertSizeToPixel(const Layer* layer,
56                             const gfx::Size& size_in_dip) {
57  return gfx::ToFlooredSize(
58      gfx::ScaleSize(size_in_dip, GetDeviceScaleFactor(layer)));
59}
60
61gfx::Rect ConvertRectToPixel(const Layer* layer,
62                             const gfx::Rect& rect_in_dip) {
63  float scale = GetDeviceScaleFactor(layer);
64  return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_dip, scale));
65}
66}  // namespace ui
67