Chromium Code Reviews| Index: ui/gfx/compositor/dip_util.cc |
| diff --git a/ui/gfx/compositor/dip_util.cc b/ui/gfx/compositor/dip_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7c831f8544748e90f3852b853ad9b60f1379eed8 |
| --- /dev/null |
| +++ b/ui/gfx/compositor/dip_util.cc |
| @@ -0,0 +1,88 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/compositor/dip_util.h" |
| + |
| +#include "base/command_line.h" |
| +#include "ui/gfx/compositor/compositor.h" |
| +#include "ui/gfx/compositor/compositor_switches.h" |
| +#include "ui/gfx/compositor/layer.h" |
| +#include "ui/gfx/monitor.h" |
| +#include "ui/gfx/point.h" |
| +#include "ui/gfx/size.h" |
| +#include "ui/gfx/rect.h" |
| + |
| +namespace ui { |
| + |
| +bool IsDIPEnabled() { |
| + static const bool dip_enabled = |
| + CommandLine::ForCurrentProcess()->HasSwitch(switches::kUIEnableDIP); |
| + return dip_enabled; |
| +} |
| + |
| +float GetDeviceScaleFactor(const Layer* layer) { |
| + if (!IsDIPEnabled()) |
| + return 1.0f; |
| + Layer* nonconst = const_cast<Layer*>(layer); |
|
piman
2012/05/04 18:46:06
We should add a const version of GetCompositor() i
|
| + Compositor* c = nonconst->GetCompositor(); |
| + return c ? |
| + c->device_scale_factor() : gfx::Monitor::GetDefaultDeviceScaleFactor(); |
| +} // namespace |
| + |
| +gfx::Point ConvertPointToDIP(const Layer* layer, |
| + const gfx::Point& point_in_pixel) { |
| + if (IsDIPEnabled()) |
| + return point_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer)); |
| + else |
| + return point_in_pixel; |
| +} |
| + |
| +gfx::Size ConvertSizeToDIP(const Layer* layer, |
| + const gfx::Size& size_in_pixel) { |
| + if (IsDIPEnabled()) |
| + return size_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer)); |
| + else |
| + return size_in_pixel; |
| +} |
| + |
| +gfx::Rect ConvertRectToDIP(const Layer* layer, |
| + const gfx::Rect& rect_in_pixel) { |
| + if (IsDIPEnabled()) { |
| + float scale = 1.0f / GetDeviceScaleFactor(layer); |
| + return gfx::Rect(rect_in_pixel.origin().Scale(scale), |
| + rect_in_pixel.size().Scale(scale)); |
| + } else { |
| + return rect_in_pixel; |
| + } |
| +} |
| + |
| +gfx::Point ConvertPointToPixel(const Layer* layer, |
| + const gfx::Point& point_in_dip) { |
| + if (IsDIPEnabled()) { |
| + return point_in_dip.Scale(GetDeviceScaleFactor(layer)); |
| + } else { |
| + return point_in_dip; |
| + } |
| +} |
| + |
| +gfx::Size ConvertSizeToPixel(const Layer* layer, |
| + const gfx::Size& size_in_dip) { |
| + if (IsDIPEnabled()) { |
| + return size_in_dip.Scale(GetDeviceScaleFactor(layer)); |
| + } else { |
| + return size_in_dip; |
| + } |
| +} |
| + |
| +gfx::Rect ConvertRectToPixel(const Layer* layer, |
| + const gfx::Rect& rect_in_dip) { |
| + if (IsDIPEnabled()) { |
| + float scale = GetDeviceScaleFactor(layer); |
| + return gfx::Rect(rect_in_dip.origin().Scale(scale), |
| + rect_in_dip.size().Scale(scale)); |
| + } else { |
| + return rect_in_dip; |
| + } |
| +} |
| +} // namespace aura |