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

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: Code cleanup - remove useless comment. 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";
102 const wchar_t kHighDPISupportW[] = L"high-dpi-support";
103
104 DWORD ReadRegistryValue(HKEY root, const wchar_t* base_key,
sky 2014/02/19 21:20:32 nit: when you wrap to multiple lines, one paramete
girard 2014/02/20 02:22:18 Done.
105 const wchar_t* value_name, DWORD default_value) {
106 base::win::RegKey regKey(HKEY_CURRENT_USER,
sky 2014/02/19 21:20:32 reg_key
girard 2014/02/20 02:22:18 Done.
107 base_key,
sky 2014/02/19 21:20:32 nit: spacing
girard 2014/02/20 02:22:18 Done.
108 KEY_QUERY_VALUE);
109 DWORD value;
110 if (regKey.Valid() &&
111 regKey.ReadValueDW(value_name,&value) == ERROR_SUCCESS) {
sky 2014/02/19 21:20:32 'name,&'-> 'name, &'
girard 2014/02/20 02:22:18 Done.
112 return value;
113 }
114 return default_value;
115 }
116
101 } // namespace 117 } // namespace
102 118
103 namespace gfx { 119 namespace gfx {
104 120
105 float GetModernUIScale() { 121 float GetModernUIScale() {
106 return GetModernUIScaleWrapper(); 122 return GetModernUIScaleWrapper();
107 } 123 }
108 124
109 void InitDeviceScaleFactor(float scale) { 125 void InitDeviceScaleFactor(float scale) {
110 DCHECK_NE(0.0f, scale); 126 DCHECK_NE(0.0f, scale);
(...skipping 20 matching lines...) Expand all
131 float GetDPIScale() { 147 float GetDPIScale() {
132 if (IsHighDPIEnabled()) { 148 if (IsHighDPIEnabled()) {
133 return gfx::Display::HasForceDeviceScaleFactor() ? 149 return gfx::Display::HasForceDeviceScaleFactor() ?
134 gfx::Display::GetForcedDeviceScaleFactor() : 150 gfx::Display::GetForcedDeviceScaleFactor() :
135 GetUnforcedDeviceScaleFactor(); 151 GetUnforcedDeviceScaleFactor();
136 } 152 }
137 return 1.0; 153 return 1.0;
138 } 154 }
139 155
140 bool IsHighDPIEnabled() { 156 bool IsHighDPIEnabled() {
157 // Flag stored in HKEY_CURRENT_USER\SOFTWARE\\Google\\Chrome\\Profile,
158 // under the DWORD value high-dpi-support.
141 // Default is disabled. 159 // Default is disabled.
142 if (CommandLine::ForCurrentProcess()->HasSwitch( 160 static DWORD value = ReadRegistryValue(
143 switches::kHighDPISupport)) { 161 HKEY_CURRENT_USER,kRegistryProfilePath,
sky 2014/02/19 21:20:32 nit: spaces after ','
girard 2014/02/20 02:22:18 Done.
144 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 162 kHighDPISupportW,FALSE);
145 switches::kHighDPISupport).compare("1") == 0; 163 return value == 1;
146 }
147 return false;
148 } 164 }
149 165
150 bool IsInHighDPIMode() { 166 bool IsInHighDPIMode() {
151 return GetDPIScale() > 1.0; 167 return GetDPIScale() > 1.0;
152 } 168 }
153 169
154 void EnableHighDPISupport() { 170 void EnableHighDPISupport() {
155 if (IsHighDPIEnabled() && 171 if (IsHighDPIEnabled()) {
156 (base::win::GetVersion() < base::win::VERSION_WIN8_1)) {
157 if (!SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) { 172 if (!SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) {
sky 2014/02/19 21:20:32 nit: combine ifs.
girard 2014/02/20 02:22:18 Done.
158 SetProcessDPIAwareWrapper(); 173 SetProcessDPIAwareWrapper();
159 } 174 }
160 } 175 }
161 } 176 }
162 177
163 namespace win { 178 namespace win {
164 179
165 float GetDeviceScaleFactor() { 180 float GetDeviceScaleFactor() {
166 DCHECK_NE(0.0f, g_device_scale_factor); 181 DCHECK_NE(0.0f, g_device_scale_factor);
167 return g_device_scale_factor; 182 return g_device_scale_factor;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 243
229 double GetUndocumentedDPITouchScale() { 244 double GetUndocumentedDPITouchScale() {
230 static double scale = 245 static double scale =
231 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? 246 (base::win::GetVersion() < base::win::VERSION_WIN8_1) ?
232 GetUndocumentedDPIScale() : 1.0; 247 GetUndocumentedDPIScale() : 1.0;
233 return scale; 248 return scale;
234 } 249 }
235 250
236 } // namespace win 251 } // namespace win
237 } // namespace gfx 252 } // 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