Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: ui/gfx/win/dpi.cc

Issue 153403003: Move supports-high-dpi flag into registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reformat, remove strings Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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";
sky 2014/02/20 15:48:43 nit: move constants to top of namespace (right her
girard 2014/02/20 20:20:16 Done.
102 const wchar_t kHighDPISupportW[] = L"high-dpi-support";
103
104 DWORD ReadRegistryValue(HKEY root,
105 const wchar_t* base_key,
106 const wchar_t* value_name,
107 DWORD default_value) {
108 base::win::RegKey reg_key(HKEY_CURRENT_USER,
109 base_key,
110 KEY_QUERY_VALUE);
111 DWORD value;
112 if (reg_key.Valid() &&
113 reg_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) {
114 return value;
115 }
116 return default_value;
117 }
118
101 } // namespace 119 } // namespace
102 120
103 namespace gfx { 121 namespace gfx {
104 122
105 float GetModernUIScale() { 123 float GetModernUIScale() {
106 return GetModernUIScaleWrapper(); 124 return GetModernUIScaleWrapper();
107 } 125 }
108 126
109 void InitDeviceScaleFactor(float scale) { 127 void InitDeviceScaleFactor(float scale) {
110 DCHECK_NE(0.0f, scale); 128 DCHECK_NE(0.0f, scale);
(...skipping 20 matching lines...) Expand all
131 float GetDPIScale() { 149 float GetDPIScale() {
132 if (IsHighDPIEnabled()) { 150 if (IsHighDPIEnabled()) {
133 return gfx::Display::HasForceDeviceScaleFactor() ? 151 return gfx::Display::HasForceDeviceScaleFactor() ?
134 gfx::Display::GetForcedDeviceScaleFactor() : 152 gfx::Display::GetForcedDeviceScaleFactor() :
135 GetUnforcedDeviceScaleFactor(); 153 GetUnforcedDeviceScaleFactor();
136 } 154 }
137 return 1.0; 155 return 1.0;
138 } 156 }
139 157
140 bool IsHighDPIEnabled() { 158 bool IsHighDPIEnabled() {
159 // Flag stored in HKEY_CURRENT_USER\SOFTWARE\\Google\\Chrome\\Profile,
160 // under the DWORD value high-dpi-support.
141 // Default is disabled. 161 // Default is disabled.
142 if (CommandLine::ForCurrentProcess()->HasSwitch( 162 static DWORD value = ReadRegistryValue(
143 switches::kHighDPISupport)) { 163 HKEY_CURRENT_USER, kRegistryProfilePath,
144 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 164 kHighDPISupportW, FALSE);
145 switches::kHighDPISupport).compare("1") == 0; 165 return value == 1;
146 }
147 return false;
148 } 166 }
149 167
150 bool IsInHighDPIMode() { 168 bool IsInHighDPIMode() {
151 return GetDPIScale() > 1.0; 169 return GetDPIScale() > 1.0;
152 } 170 }
153 171
154 void EnableHighDPISupport() { 172 void EnableHighDPISupport() {
155 if (IsHighDPIEnabled() && 173 if (IsHighDPIEnabled() &&
156 (base::win::GetVersion() < base::win::VERSION_WIN8_1)) { 174 !SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) {
157 if (!SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) { 175 SetProcessDPIAwareWrapper();
158 SetProcessDPIAwareWrapper();
159 }
160 } 176 }
161 } 177 }
162 178
163 namespace win { 179 namespace win {
164 180
165 float GetDeviceScaleFactor() { 181 float GetDeviceScaleFactor() {
166 DCHECK_NE(0.0f, g_device_scale_factor); 182 DCHECK_NE(0.0f, g_device_scale_factor);
167 return g_device_scale_factor; 183 return g_device_scale_factor;
168 } 184 }
169 185
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 244
229 double GetUndocumentedDPITouchScale() { 245 double GetUndocumentedDPITouchScale() {
230 static double scale = 246 static double scale =
231 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? 247 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ?
232 GetUndocumentedDPIScale() : 1.0; 248 GetUndocumentedDPIScale() : 1.0;
233 return scale; 249 return scale;
234 } 250 }
235 251
236 } // namespace win 252 } // namespace win
237 } // namespace gfx 253 } // namespace gfx
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698