13
13
#include < fcntl.h>
14
14
15
15
#include < windows.h>
16
+ #include < shellscalingapi.h>
17
+ #include < tchar.h>
16
18
#include < shellapi.h>
17
19
18
20
#include " atom/app/atom_main_delegate.h"
19
21
#include " atom/common/crash_reporter/win/crash_service_main.h"
20
22
#include " base/environment.h"
23
+ #include " base/win/windows_version.h"
21
24
#include " content/public/app/startup_helper_win.h"
22
25
#include " sandbox/win/src/sandbox_types.h"
23
26
#include " ui/gfx/win/dpi.h"
@@ -37,6 +40,48 @@ int Start(int argc, char *argv[]);
37
40
38
41
#if defined(OS_WIN)
39
42
43
+ namespace {
44
+
45
+ // Win8.1 supports monitor-specific DPI scaling.
46
+ bool SetProcessDpiAwarenessWrapper (PROCESS_DPI_AWARENESS value) {
47
+ typedef HRESULT (WINAPI *SetProcessDpiAwarenessPtr)(PROCESS_DPI_AWARENESS);
48
+ SetProcessDpiAwarenessPtr set_process_dpi_awareness_func =
49
+ reinterpret_cast <SetProcessDpiAwarenessPtr>(
50
+ GetProcAddress (GetModuleHandleA (" user32.dll" ),
51
+ " SetProcessDpiAwarenessInternal" ));
52
+ if (set_process_dpi_awareness_func) {
53
+ HRESULT hr = set_process_dpi_awareness_func (value);
54
+ if (SUCCEEDED (hr)) {
55
+ VLOG (1 ) << " SetProcessDpiAwareness succeeded." ;
56
+ return true ;
57
+ } else if (hr == E_ACCESSDENIED) {
58
+ LOG (ERROR) << " Access denied error from SetProcessDpiAwareness. "
59
+ " Function called twice, or manifest was used." ;
60
+ }
61
+ }
62
+ return false ;
63
+ }
64
+
65
+ // This function works for Windows Vista through Win8. Win8.1 must use
66
+ // SetProcessDpiAwareness[Wrapper].
67
+ BOOL SetProcessDPIAwareWrapper () {
68
+ typedef BOOL (WINAPI *SetProcessDPIAwarePtr)(VOID);
69
+ SetProcessDPIAwarePtr set_process_dpi_aware_func =
70
+ reinterpret_cast <SetProcessDPIAwarePtr>(
71
+ GetProcAddress (GetModuleHandleA (" user32.dll" ),
72
+ " SetProcessDPIAware" ));
73
+ return set_process_dpi_aware_func &&
74
+ set_process_dpi_aware_func ();
75
+ }
76
+
77
+ void EnableHighDPISupport () {
78
+ if (!SetProcessDpiAwarenessWrapper (PROCESS_SYSTEM_DPI_AWARE)) {
79
+ SetProcessDPIAwareWrapper ();
80
+ }
81
+ }
82
+
83
+ } // namespace
84
+
40
85
int APIENTRY wWinMain (HINSTANCE instance, HINSTANCE, wchar_t * cmd, int ) {
41
86
int argc = 0 ;
42
87
wchar_t ** wargv = ::CommandLineToArgvW (::GetCommandLineW (), &argc);
@@ -103,8 +148,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
103
148
content::InitializeSandboxInfo (&sandbox_info);
104
149
atom::AtomMainDelegate delegate;
105
150
106
- // Now chrome relies on a regkey to enable high dpi support.
107
- gfx::EnableHighDPISupport ();
151
+ // We don't want to set DPI awareness on pre-Win7 because we don't support
152
+ // DirectWrite there. GDI fonts are kerned very badly, so better to leave
153
+ // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite().
154
+ if (base::win::GetVersion () >= base::win::VERSION_WIN7)
155
+ EnableHighDPISupport ();
108
156
109
157
content::ContentMainParams params (&delegate);
110
158
params.instance = instance;
0 commit comments