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

Unified Diff: ui/base/win/dpi.cc

Issue 11953054: Fix high-DPI on Windows to make use of DIP scaling in WebKit. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove redundant comments. Created 7 years, 11 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/base/win/dpi.h ('k') | ui/gfx/display.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/win/dpi.cc
diff --git a/ui/base/win/dpi.cc b/ui/base/win/dpi.cc
index 9c56af05b9febd994de39b88bd2a7b589fdb824b..ecfb3e7a31e477ff93b3e4a19394bd2d6ced2d09 100644
--- a/ui/base/win/dpi.cc
+++ b/ui/base/win/dpi.cc
@@ -7,12 +7,26 @@
#include <windows.h>
#include "base/win/scoped_hdc.h"
+#include "ui/gfx/display.h"
+#include "ui/gfx/point_conversions.h"
+#include "ui/gfx/rect_conversions.h"
+#include "ui/gfx/size_conversions.h"
namespace {
int kDefaultDPIX = 96;
int kDefaultDPIY = 96;
+
+float GetDeviceScaleFactorImpl() {
+#if defined(ENABLE_HIDPI)
+ return gfx::Display::HasForceDeviceScaleFactor() ?
+ gfx::Display::GetForcedDeviceScaleFactor() : ui::GetDPIScale();
+#else
+ return 1.0f;
+#endif
+}
+
} // namespace
namespace ui {
@@ -53,4 +67,39 @@ void EnableHighDPISupport() {
set_process_dpi_aware_func();
}
+namespace win {
+
+float GetDeviceScaleFactor() {
+ static const float device_scale_factor = GetDeviceScaleFactorImpl();
+ return device_scale_factor;
+}
+
+gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) {
+ return gfx::ToFlooredPoint(
+ gfx::ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor()));
+}
+
+gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds) {
+ // TODO(kevers): Switch to non-deprecated method for float to int conversions.
+ return gfx::ToFlooredRectDeprecated(
+ gfx::ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactor()));
+}
+
+gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds) {
+ // TODO(kevers): Switch to non-deprecated method for float to int conversions.
+ return gfx::ToFlooredRectDeprecated(
+ gfx::ScaleRect(dip_bounds, GetDeviceScaleFactor()));
+}
+
+gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) {
+ return gfx::ToFlooredSize(
+ gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor()));
+}
+
+gfx::Size DIPToScreenSize(const gfx::Size& dip_size) {
+ return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor()));
+}
+
+} // namespace win
+
} // namespace ui
« no previous file with comments | « ui/base/win/dpi.h ('k') | ui/gfx/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698