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/gfx/win/dpi.h" | 5 #include "ui/gfx/win/dpi.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/win/scoped_hdc.h" | 9 #include "base/win/scoped_hdc.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 reinterpret_cast<IsProcessDPIAwarePtr>( | 31 reinterpret_cast<IsProcessDPIAwarePtr>( |
32 GetProcAddress(GetModuleHandleA("user32.dll"), "IsProcessDPIAware")); | 32 GetProcAddress(GetModuleHandleA("user32.dll"), "IsProcessDPIAware")); |
33 if (is_process_dpi_aware_func) | 33 if (is_process_dpi_aware_func) |
34 return is_process_dpi_aware_func(); | 34 return is_process_dpi_aware_func(); |
35 return FALSE; | 35 return FALSE; |
36 } | 36 } |
37 | 37 |
38 float g_device_scale_factor = 0.0f; | 38 float g_device_scale_factor = 0.0f; |
39 | 39 |
40 float GetUnforcedDeviceScaleFactor() { | 40 float GetUnforcedDeviceScaleFactor() { |
| 41 // If the global device scale factor is initialized use it. This is to ensure |
| 42 // we use the same scale factor across all callsites. We don't use the |
| 43 // GetDeviceScaleFactor function here because it fires a DCHECK if the |
| 44 // g_device_scale_factor global is 0. |
| 45 if (g_device_scale_factor) |
| 46 return g_device_scale_factor; |
41 return static_cast<float>(gfx::GetDPI().width()) / | 47 return static_cast<float>(gfx::GetDPI().width()) / |
42 static_cast<float>(kDefaultDPIX); | 48 static_cast<float>(kDefaultDPIX); |
43 } | 49 } |
44 | 50 |
45 float GetModernUIScaleWrapper() { | |
46 float result = 1.0f; | |
47 // TODO(cpu) : Fix scale for Win7. | |
48 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
49 return result; | |
50 | |
51 typedef float(WINAPI *GetModernUIScalePtr)(VOID); | |
52 HMODULE lib = LoadLibraryA("metro_driver.dll"); | |
53 if (lib) { | |
54 GetModernUIScalePtr func = | |
55 reinterpret_cast<GetModernUIScalePtr>( | |
56 GetProcAddress(lib, "GetModernUIScale")); | |
57 if (func) | |
58 result = func(); | |
59 FreeLibrary(lib); | |
60 } | |
61 return result; | |
62 } | |
63 | |
64 // Duplicated from Win8.1 SDK ShellScalingApi.h | 51 // Duplicated from Win8.1 SDK ShellScalingApi.h |
65 typedef enum PROCESS_DPI_AWARENESS { | 52 typedef enum PROCESS_DPI_AWARENESS { |
66 PROCESS_DPI_UNAWARE = 0, | 53 PROCESS_DPI_UNAWARE = 0, |
67 PROCESS_SYSTEM_DPI_AWARE = 1, | 54 PROCESS_SYSTEM_DPI_AWARE = 1, |
68 PROCESS_PER_MONITOR_DPI_AWARE = 2 | 55 PROCESS_PER_MONITOR_DPI_AWARE = 2 |
69 } PROCESS_DPI_AWARENESS; | 56 } PROCESS_DPI_AWARENESS; |
70 | 57 |
71 typedef enum MONITOR_DPI_TYPE { | 58 typedef enum MONITOR_DPI_TYPE { |
72 MDT_EFFECTIVE_DPI = 0, | 59 MDT_EFFECTIVE_DPI = 0, |
73 MDT_ANGULAR_DPI = 1, | 60 MDT_ANGULAR_DPI = 1, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 reg_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) { | 106 reg_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) { |
120 return value; | 107 return value; |
121 } | 108 } |
122 return default_value; | 109 return default_value; |
123 } | 110 } |
124 | 111 |
125 } // namespace | 112 } // namespace |
126 | 113 |
127 namespace gfx { | 114 namespace gfx { |
128 | 115 |
129 float GetModernUIScale() { | |
130 return GetModernUIScaleWrapper(); | |
131 } | |
132 | |
133 void InitDeviceScaleFactor(float scale) { | 116 void InitDeviceScaleFactor(float scale) { |
134 DCHECK_NE(0.0f, scale); | 117 DCHECK_NE(0.0f, scale); |
135 g_device_scale_factor = scale; | 118 g_device_scale_factor = scale; |
136 } | 119 } |
137 | 120 |
138 Size GetDPI() { | 121 Size GetDPI() { |
139 static int dpi_x = 0; | 122 static int dpi_x = 0; |
140 static int dpi_y = 0; | 123 static int dpi_y = 0; |
141 static bool should_initialize = true; | 124 static bool should_initialize = true; |
142 | 125 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 242 |
260 double GetUndocumentedDPITouchScale() { | 243 double GetUndocumentedDPITouchScale() { |
261 static double scale = | 244 static double scale = |
262 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? | 245 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? |
263 GetUndocumentedDPIScale() : 1.0; | 246 GetUndocumentedDPIScale() : 1.0; |
264 return scale; | 247 return scale; |
265 } | 248 } |
266 | 249 |
267 } // namespace win | 250 } // namespace win |
268 } // namespace gfx | 251 } // namespace gfx |
OLD | NEW |