summaryrefslogtreecommitdiffstats
path: root/ui/base
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 19:56:20 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 19:56:20 +0000
commita3957de5c0179812822e6ec0a93b05b3d27c9735 (patch)
tree35a23d613aaee3f52b6487dcaf31b55ef2e75f73 /ui/base
parentdee6c492fa9cfd2f8281be7459df291524447d52 (diff)
downloadchromium_src-a3957de5c0179812822e6ec0a93b05b3d27c9735.zip
chromium_src-a3957de5c0179812822e6ec0a93b05b3d27c9735.tar.gz
chromium_src-a3957de5c0179812822e6ec0a93b05b3d27c9735.tar.bz2
Metro/HiDPI: Add DPI util functions
BUG=114311 TEST= Review URL: http://codereview.chromium.org/10051013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r--ui/base/win/dpi.cc55
-rw-r--r--ui/base/win/dpi.h26
2 files changed, 81 insertions, 0 deletions
diff --git a/ui/base/win/dpi.cc b/ui/base/win/dpi.cc
new file mode 100644
index 0000000..c998292
--- /dev/null
+++ b/ui/base/win/dpi.cc
@@ -0,0 +1,55 @@
+// 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/base/win/dpi.h"
+
+#include <windows.h>
+
+#include "base/win/scoped_hdc.h"
+
+namespace {
+
+int kDefaultDPIX = 96;
+int kDefaultDPIY = 96;
+
+} // namespace
+
+namespace ui {
+
+gfx::Size GetDPI() {
+ static int dpi_x = 0;
+ static int dpi_y = 0;
+ static bool should_initialize = true;
+
+ if (should_initialize) {
+ should_initialize = false;
+ base::win::ScopedGetDC screen_dc(NULL);
+ // This value is safe to cache for the life time of the app since the
+ // user must logout to change the DPI setting. This value also applies
+ // to all screens.
+ dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX);
+ dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY);
+ }
+ return gfx::Size(dpi_x, dpi_y);
+}
+
+float GetDPIScale() {
+ return static_cast<float>(GetDPI().width()) /
+ static_cast<float>(kDefaultDPIX);
+}
+
+bool IsInHighDPIMode() {
+ gfx::Size dpi(GetDPI());
+ return dpi.width() > kDefaultDPIX || dpi.height() > kDefaultDPIY;
+}
+
+void EnableHighDPISupport() {
+ typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID);
+ SetProcessDPIAwarePtr set_process_dpi_aware_func =
+ GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware");
+ if (set_process_dpi_aware_func)
+ set_process_dpi_aware_func();
+}
+
+} // namespace ui
diff --git a/ui/base/win/dpi.h b/ui/base/win/dpi.h
new file mode 100644
index 0000000..2bb698e
--- /dev/null
+++ b/ui/base/win/dpi.h
@@ -0,0 +1,26 @@
+// 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.
+
+#ifndef UI_BASE_WIN_DPI_H_
+#define UI_BASE_WIN_DPI_H_
+#pragma once
+
+#include "ui/gfx/size.h"
+#include "ui/base/ui_export.h"
+
+namespace ui {
+
+UI_EXPORT gfx::Size GetDPI();
+
+// Gets the scale factor of the display. For example, if the display DPI is
+// 96 then the scale factor is 1.0.
+UI_EXPORT float GetDPIScale();
+
+UI_EXPORT bool IsInHighDPIMode();
+
+UI_EXPORT void EnableHighDPISupport();
+
+} // namespace ui
+
+#endif // UI_BASE_WIN_DPI_H_