Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/win/dpi.h" | 5 #include "ui/base/win/dpi.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/win/scoped_hdc.h" | 9 #include "base/win/scoped_hdc.h" |
| 10 #include "ui/gfx/display.h" | |
| 11 #include "ui/gfx/point_conversions.h" | |
| 12 #include "ui/gfx/rect_conversions.h" | |
| 13 #include "ui/gfx/size_conversions.h" | |
| 10 | 14 |
| 11 namespace { | 15 namespace { |
| 12 | 16 |
| 13 int kDefaultDPIX = 96; | 17 int kDefaultDPIX = 96; |
| 14 int kDefaultDPIY = 96; | 18 int kDefaultDPIY = 96; |
| 15 | 19 |
| 20 | |
| 21 float GetDeviceScaleFactorImpl() { | |
| 22 #if defined(ENABLE_HIDPI) | |
| 23 return gfx::Display::HasForceDeviceScaleFactor() ? | |
| 24 gfx::Display::GetForcedDeviceScaleFactor() : ui::GetDPIScale(); | |
| 25 #else | |
| 26 return 1.0f; | |
| 27 #endif | |
| 28 } | |
| 29 | |
| 16 } // namespace | 30 } // namespace |
| 17 | 31 |
| 18 namespace ui { | 32 namespace ui { |
| 19 | 33 |
| 20 gfx::Size GetDPI() { | 34 gfx::Size GetDPI() { |
| 21 static int dpi_x = 0; | 35 static int dpi_x = 0; |
| 22 static int dpi_y = 0; | 36 static int dpi_y = 0; |
| 23 static bool should_initialize = true; | 37 static bool should_initialize = true; |
| 24 | 38 |
| 25 if (should_initialize) { | 39 if (should_initialize) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 46 | 60 |
| 47 void EnableHighDPISupport() { | 61 void EnableHighDPISupport() { |
| 48 typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); | 62 typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); |
| 49 SetProcessDPIAwarePtr set_process_dpi_aware_func = | 63 SetProcessDPIAwarePtr set_process_dpi_aware_func = |
| 50 reinterpret_cast<SetProcessDPIAwarePtr>( | 64 reinterpret_cast<SetProcessDPIAwarePtr>( |
| 51 GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware")); | 65 GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware")); |
| 52 if (set_process_dpi_aware_func) | 66 if (set_process_dpi_aware_func) |
| 53 set_process_dpi_aware_func(); | 67 set_process_dpi_aware_func(); |
| 54 } | 68 } |
| 55 | 69 |
| 70 namespace win { | |
| 71 | |
| 72 float GetDeviceScaleFactor() { | |
|
darin (slow to review)
2013/01/30 21:39:12
What happens in the case of multiple monitors, eac
kevers
2013/01/30 22:27:01
Under Windows, all monitors use the same scale fac
| |
| 73 static const float device_scale_factor = GetDeviceScaleFactorImpl(); | |
| 74 return device_scale_factor; | |
| 75 } | |
| 76 | |
| 77 gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) { | |
| 78 return gfx::ToFlooredPoint( | |
| 79 gfx::ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); | |
| 80 } | |
| 81 | |
| 82 gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds) { | |
| 83 // TODO(kevers): Switch to non-deprecated method for float to int conversions. | |
| 84 return gfx::ToFlooredRectDeprecated( | |
| 85 gfx::ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactor())); | |
| 86 } | |
| 87 | |
| 88 gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds) { | |
| 89 // TODO(kevers): Switch to non-deprecated method for float to int conversions. | |
| 90 return gfx::ToFlooredRectDeprecated( | |
| 91 gfx::ScaleRect(dip_bounds, GetDeviceScaleFactor())); | |
| 92 } | |
| 93 | |
| 94 gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { | |
| 95 return gfx::ToFlooredSize( | |
| 96 gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); | |
| 97 } | |
| 98 | |
| 99 gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { | |
| 100 return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); | |
| 101 } | |
| 102 | |
| 103 } // namespace win | |
| 104 | |
| 56 } // namespace ui | 105 } // namespace ui |
| OLD | NEW |