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

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: . 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
18 bool IsDIPEnabled() {
19 static const bool dip_enabled =
20 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUIEnableDIP);
21 return dip_enabled;
22 }
23
24 float GetDeviceScaleFactor(const Layer* layer) {
25 if (!IsDIPEnabled())
26 return 1.0f;
27 Layer* nonconst = const_cast<Layer*>(layer);
28 Compositor* c = nonconst->GetCompositor();
29 return c ?
30 c->device_scale_factor() : gfx::Monitor::GetDefaultDeviceScaleFactor();
31 } // namespace
32
33 gfx::Point ConvertPointToDIP(const Layer* layer,
34 const gfx::Point& point_in_pixel) {
35 if (IsDIPEnabled())
36 return point_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer));
37 else
38 return point_in_pixel;
39 }
40
41 gfx::Size ConvertSizeToDIP(const Layer* layer,
42 const gfx::Size& size_in_pixel) {
43 if (IsDIPEnabled())
44 return size_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer));
45 else
46 return size_in_pixel;
47 }
48
49 gfx::Rect ConvertRectToDIP(const Layer* layer,
50 const gfx::Rect& rect_in_pixel) {
51 if (IsDIPEnabled()) {
52 float scale = 1.0f / GetDeviceScaleFactor(layer);
53 return gfx::Rect(rect_in_pixel.origin().Scale(scale),
54 rect_in_pixel.size().Scale(scale));
55 } else {
56 return rect_in_pixel;
57 }
58 }
59
60 gfx::Point ConvertPointToPixel(const Layer* layer,
61 const gfx::Point& point_in_dip) {
62 if (IsDIPEnabled()) {
63 return point_in_dip.Scale(GetDeviceScaleFactor(layer));
64 } else {
65 return point_in_dip;
66 }
67 }
68
69 gfx::Size ConvertSizeToPixel(const Layer* layer,
70 const gfx::Size& size_in_dip) {
71 if (IsDIPEnabled()) {
72 return size_in_dip.Scale(GetDeviceScaleFactor(layer));
73 } else {
74 return size_in_dip;
75 }
76 }
77
78 gfx::Rect ConvertRectToPixel(const Layer* layer,
79 const gfx::Rect& rect_in_dip) {
80 if (IsDIPEnabled()) {
81 float scale = GetDeviceScaleFactor(layer);
82 return gfx::Rect(rect_in_dip.origin().Scale(scale),
83 rect_in_dip.size().Scale(scale));
84 } else {
85 return rect_in_dip;
86 }
87 }
88 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698