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

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

Issue 10221028: Move DIP translation from ui/aura to ui/compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert change i made by accident Created 8 years, 7 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
OLDNEW
(Empty)
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/gfx/compositor/dip_util.h"
6
7 #include "base/command_line.h"
8 #include "ui/gfx/compositor/compositor.h"
9 #include "ui/gfx/compositor/compositor_switches.h"
10 #include "ui/gfx/compositor/layer.h"
11 #include "ui/gfx/monitor.h"
12 #include "ui/gfx/point.h"
13 #include "ui/gfx/size.h"
14 #include "ui/gfx/rect.h"
15
16 namespace ui {
17 namespace {
18 bool dip_enabled_for_test = false;
19 } // namespace
20
21 namespace test {
22
23 ScopedDIPEnablerForTest::ScopedDIPEnablerForTest() {
24 CHECK(!dip_enabled_for_test);
25 dip_enabled_for_test = true;
26 }
27
28 ScopedDIPEnablerForTest::~ScopedDIPEnablerForTest() {
29 dip_enabled_for_test = false;
30 }
31
32 } // namespace test
33
34 bool IsDIPEnabled() {
35 static const bool dip_enabled =
36 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUIEnableDIP);
37 return dip_enabled || dip_enabled_for_test;
38 }
39
40 float GetDeviceScaleFactor(const Layer* layer) {
41 if (!IsDIPEnabled())
42 return 1.0f;
43 return layer->device_scale_factor();
44 }
45
46 gfx::Point ConvertPointToDIP(const Layer* layer,
47 const gfx::Point& point_in_pixel) {
48 if (IsDIPEnabled())
49 return point_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer));
50 else
51 return point_in_pixel;
52 }
53
54 gfx::Size ConvertSizeToDIP(const Layer* layer,
55 const gfx::Size& size_in_pixel) {
56 if (IsDIPEnabled())
57 return size_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer));
58 else
59 return size_in_pixel;
60 }
61
62 gfx::Rect ConvertRectToDIP(const Layer* layer,
63 const gfx::Rect& rect_in_pixel) {
64 if (IsDIPEnabled()) {
65 float scale = 1.0f / GetDeviceScaleFactor(layer);
66 return gfx::Rect(rect_in_pixel.origin().Scale(scale),
67 rect_in_pixel.size().Scale(scale));
68 } else {
69 return rect_in_pixel;
70 }
71 }
72
73 gfx::Point ConvertPointToPixel(const Layer* layer,
74 const gfx::Point& point_in_dip) {
75 if (IsDIPEnabled()) {
76 return point_in_dip.Scale(GetDeviceScaleFactor(layer));
77 } else {
78 return point_in_dip;
79 }
80 }
81
82 gfx::Size ConvertSizeToPixel(const Layer* layer,
83 const gfx::Size& size_in_dip) {
84 if (IsDIPEnabled()) {
85 return size_in_dip.Scale(GetDeviceScaleFactor(layer));
86 } else {
87 return size_in_dip;
88 }
89 }
90
91 gfx::Rect ConvertRectToPixel(const Layer* layer,
92 const gfx::Rect& rect_in_dip) {
93 if (IsDIPEnabled()) {
94 float scale = GetDeviceScaleFactor(layer);
95 return gfx::Rect(rect_in_dip.origin().Scale(scale),
96 rect_in_dip.size().Scale(scale));
97 } else {
98 return rect_in_dip;
99 }
100 }
101 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698