25
25
#include " sandbox/win/src/sandbox_types.h"
26
26
27
27
#if defined(OS_WIN)
28
+ #include < windows.h>
29
+ #include < shellscalingapi.h>
30
+
28
31
#include " base/win/win_util.h"
29
32
#include " base/win/windows_version.h"
30
33
#include " content/public/app/startup_helper_win.h"
@@ -39,13 +42,49 @@ using base::CommandLine;
39
42
40
43
#if defined(OS_WIN)
41
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
+
42
83
int APIENTRY wWinMain (HINSTANCE instance, HINSTANCE, wchar_t *, int ) {
43
84
CommandLine::Init (0 , NULL );
44
- #if 0 //FIXME
45
- if (base::win::GetVersion() > base::win::VERSION_VISTA)
46
- gfx::EnableHighDPISupport();
47
- #endif
48
85
86
+ if (base::win::GetVersion () >= base::win::VERSION_WIN7)
87
+ EnableHighDPISupport ();
49
88
50
89
sandbox::SandboxInterfaceInfo sandbox_info = {0 };
51
90
content::InitializeSandboxInfo (&sandbox_info);
0 commit comments