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) | |
|
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
| |
| 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() { | |
| 73 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
| |
| 74 return device_scale_factor; | |
| 75 } | |
| 76 | |
|
sky
2013/01/28 20:56:35
nit: remove one newline.
kevers
2013/01/29 17:08:29
Done.
| |
| 77 | |
| 78 gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) { | |
| 79 return gfx::ToFlooredPoint( | |
| 80 gfx::ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); | |
| 81 } | |
| 82 | |
| 83 gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds) { | |
| 84 // TODO(kevers): Switch to non-deprecated method for float to int conversions. | |
| 85 return gfx::ToFlooredRectDeprecated( | |
| 86 gfx::ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactor())); | |
| 87 } | |
| 88 | |
| 89 gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds) { | |
| 90 // TODO(kevers): Switch to non-deprecated method for float to int conversions. | |
| 91 return gfx::ToFlooredRectDeprecated( | |
| 92 gfx::ScaleRect(dip_bounds, GetDeviceScaleFactor())); | |
| 93 } | |
| 94 | |
| 95 gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { | |
| 96 return gfx::ToFlooredSize( | |
| 97 gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); | |
| 98 } | |
| 99 | |
| 100 gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { | |
| 101 return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); | |
| 102 } | |
| 103 | |
| 104 } // namespace win | |
| 105 | |
| 56 } // namespace ui | 106 } // namespace ui |
| OLD | NEW |