Index: ui/base/win/dpi.cc |
diff --git a/ui/base/win/dpi.cc b/ui/base/win/dpi.cc |
index 9c56af05b9febd994de39b88bd2a7b589fdb824b..b968f43112d4bef597f90930b4c1cce0f0b07ed2 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) |
sky
2013/01/28 20:56:35
Why the ifdef?
kevers
2013/01/28 22:53:40
Removing the ifdef would expose the forced device
sky
2013/01/29 15:34:56
Why wouldn't we do this? I assume we're going to n
kevers
2013/01/29 17:08:29
Yes, ENABLE_HIDPI ifdefs are going away once the f
|
+ return gfx::Display::HasForceDeviceScaleFactor() ? |
+ gfx::Display::GetForcedDeviceScaleFactor() : ui::GetDPIScale(); |
+#else |
+ return 1.0f; |
+#endif |
+} |
+ |
} // namespace |
namespace ui { |
@@ -53,4 +67,40 @@ void EnableHighDPISupport() { |
set_process_dpi_aware_func(); |
} |
+namespace win { |
+ |
+float GetDeviceScaleFactor() { |
+ static const float device_scale_factor = GetDeviceScaleFactorImpl(); |
sky
2013/01/28 20:56:35
Why do we need to cache this?
kevers
2013/01/28 22:53:40
See this caching pattern used in several places wh
|
+ return device_scale_factor; |
+} |
+ |
sky
2013/01/28 20:56:35
nit: remove one newline.
kevers
2013/01/29 17:08:29
Done.
|
+ |
+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 |