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

Unified Diff: ui/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: disable tests that doesn't run on bots 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/dip_util.cc
diff --git a/ui/compositor/dip_util.cc b/ui/compositor/dip_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e13c7508cb22490cb4cc34f48ede2ec460dd2f62
--- /dev/null
+++ b/ui/compositor/dip_util.cc
@@ -0,0 +1,101 @@
+// 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/compositor/dip_util.h"
+
+#include "base/command_line.h"
+#include "ui/compositor/compositor.h"
+#include "ui/compositor/compositor_switches.h"
+#include "ui/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 {
+namespace {
+bool dip_enabled_for_test = false;
+} // namespace
+
+namespace test {
+
+ScopedDIPEnablerForTest::ScopedDIPEnablerForTest() {
+ CHECK(!dip_enabled_for_test);
+ dip_enabled_for_test = true;
+}
+
+ScopedDIPEnablerForTest::~ScopedDIPEnablerForTest() {
+ dip_enabled_for_test = false;
+}
+
+} // namespace test
+
+bool IsDIPEnabled() {
+ static const bool dip_enabled =
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kUIEnableDIP);
+ return dip_enabled || dip_enabled_for_test;
+}
+
+float GetDeviceScaleFactor(const Layer* layer) {
+ if (!IsDIPEnabled())
+ return 1.0f;
+ return layer->device_scale_factor();
+}
+
+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 ui
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698