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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 BOOL SetProcessDPIAwareWrapper() { | 91 BOOL SetProcessDPIAwareWrapper() { |
92 typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); | 92 typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); |
93 SetProcessDPIAwarePtr set_process_dpi_aware_func = | 93 SetProcessDPIAwarePtr set_process_dpi_aware_func = |
94 reinterpret_cast<SetProcessDPIAwarePtr>( | 94 reinterpret_cast<SetProcessDPIAwarePtr>( |
95 GetProcAddress(GetModuleHandleA("user32.dll"), | 95 GetProcAddress(GetModuleHandleA("user32.dll"), |
96 "SetProcessDPIAware")); | 96 "SetProcessDPIAware")); |
97 return set_process_dpi_aware_func && | 97 return set_process_dpi_aware_func && |
98 set_process_dpi_aware_func(); | 98 set_process_dpi_aware_func(); |
99 } | 99 } |
100 | 100 |
| 101 const wchar_t kRegistryProfilePath[] = L"SOFTWARE\\Google\\Chrome\\Profile"; |
| 102 const wchar_t kHighDPISupport[] = L"high-dpi-support"; |
| 103 |
| 104 DWORD ReadRegistryValue(HKEY root, const wchar_t* base_key, |
| 105 const wchar_t* value_name, DWORD default_value) { |
| 106 base::win::RegKey regKey(HKEY_CURRENT_USER, |
| 107 base_key, |
| 108 KEY_QUERY_VALUE); |
| 109 DWORD value; |
| 110 if (regKey.Valid() && |
| 111 regKey.ReadValueDW(value_name,&value) == ERROR_SUCCESS) { |
| 112 return value; |
| 113 } |
| 114 return default_value; |
| 115 } |
101 } // namespace | 116 } // namespace |
102 | 117 |
103 namespace gfx { | 118 namespace gfx { |
104 | 119 |
105 float GetModernUIScale() { | 120 float GetModernUIScale() { |
106 return GetModernUIScaleWrapper(); | 121 return GetModernUIScaleWrapper(); |
107 } | 122 } |
108 | 123 |
109 void InitDeviceScaleFactor(float scale) { | 124 void InitDeviceScaleFactor(float scale) { |
110 DCHECK_NE(0.0f, scale); | 125 DCHECK_NE(0.0f, scale); |
(...skipping 19 matching lines...) Expand all Loading... |
130 | 145 |
131 float GetDPIScale() { | 146 float GetDPIScale() { |
132 if (IsHighDPIEnabled()) { | 147 if (IsHighDPIEnabled()) { |
133 return gfx::Display::HasForceDeviceScaleFactor() ? | 148 return gfx::Display::HasForceDeviceScaleFactor() ? |
134 gfx::Display::GetForcedDeviceScaleFactor() : | 149 gfx::Display::GetForcedDeviceScaleFactor() : |
135 GetUnforcedDeviceScaleFactor(); | 150 GetUnforcedDeviceScaleFactor(); |
136 } | 151 } |
137 return 1.0; | 152 return 1.0; |
138 } | 153 } |
139 | 154 |
| 155 std::wstring ConvertToWString(const std::string& s) { |
| 156 std::wstring result; |
| 157 result.assign(s.begin(),s.end()); |
| 158 return result; |
| 159 } |
| 160 |
140 bool IsHighDPIEnabled() { | 161 bool IsHighDPIEnabled() { |
141 // Default is disabled. | 162 // Default is disabled. |
142 if (CommandLine::ForCurrentProcess()->HasSwitch( | 163 static DWORD value = ReadRegistryValue( |
143 switches::kHighDPISupport)) { | 164 HKEY_CURRENT_USER,kRegistryProfilePath, |
144 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 165 ConvertToWString(switches::kHighDPISupport).c_str(),FALSE); |
145 switches::kHighDPISupport).compare("1") == 0; | 166 return value == 1; |
146 } | |
147 return false; | |
148 } | 167 } |
149 | 168 |
150 bool IsInHighDPIMode() { | 169 bool IsInHighDPIMode() { |
151 return GetDPIScale() > 1.0; | 170 return GetDPIScale() > 1.0; |
152 } | 171 } |
153 | 172 |
154 void EnableHighDPISupport() { | 173 void EnableHighDPISupport() { |
155 if (IsHighDPIEnabled() && | 174 // TODO: Test to see if this changes in Win8.1 - If not, then change |
156 (base::win::GetVersion() < base::win::VERSION_WIN8_1)) { | 175 // GetUndocumentedDPIScale... |
| 176 if (IsHighDPIEnabled()) { |
157 if (!SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) { | 177 if (!SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) { |
158 SetProcessDPIAwareWrapper(); | 178 SetProcessDPIAwareWrapper(); |
159 } | 179 } |
160 } | 180 } |
161 } | 181 } |
162 | 182 |
163 namespace win { | 183 namespace win { |
164 | 184 |
165 float GetDeviceScaleFactor() { | 185 float GetDeviceScaleFactor() { |
166 DCHECK_NE(0.0f, g_device_scale_factor); | 186 DCHECK_NE(0.0f, g_device_scale_factor); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 248 |
229 double GetUndocumentedDPITouchScale() { | 249 double GetUndocumentedDPITouchScale() { |
230 static double scale = | 250 static double scale = |
231 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? | 251 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? |
232 GetUndocumentedDPIScale() : 1.0; | 252 GetUndocumentedDPIScale() : 1.0; |
233 return scale; | 253 return scale; |
234 } | 254 } |
235 | 255 |
236 } // namespace win | 256 } // namespace win |
237 } // namespace gfx | 257 } // namespace gfx |
OLD | NEW |