Skip to content

Commit

Permalink
[WIN] Fix High DPI support on text
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Apr 8, 2015
1 parent da7a71d commit 8e1bade
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/shell_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "sandbox/win/src/sandbox_types.h"

#if defined(OS_WIN)
#include <windows.h>
#include <shellscalingapi.h>

#include "base/win/win_util.h"
#include "base/win/windows_version.h"
#include "content/public/app/startup_helper_win.h"
Expand All @@ -39,13 +42,49 @@ using base::CommandLine;

#if defined(OS_WIN)

// Win8.1 supports monitor-specific DPI scaling.
bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) {
typedef HRESULT(WINAPI *SetProcessDpiAwarenessPtr)(PROCESS_DPI_AWARENESS);
SetProcessDpiAwarenessPtr set_process_dpi_awareness_func =
reinterpret_cast<SetProcessDpiAwarenessPtr>(
GetProcAddress(GetModuleHandleA("user32.dll"),
"SetProcessDpiAwarenessInternal"));
if (set_process_dpi_awareness_func) {
HRESULT hr = set_process_dpi_awareness_func(value);
if (SUCCEEDED(hr)) {
VLOG(1) << "SetProcessDpiAwareness succeeded.";
return true;
} else if (hr == E_ACCESSDENIED) {
LOG(ERROR) << "Access denied error from SetProcessDpiAwareness. "
"Function called twice, or manifest was used.";
}
}
return false;
}

// This function works for Windows Vista through Win8. Win8.1 must use
// SetProcessDpiAwareness[Wrapper].
BOOL SetProcessDPIAwareWrapper() {
typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID);
SetProcessDPIAwarePtr set_process_dpi_aware_func =
reinterpret_cast<SetProcessDPIAwarePtr>(
GetProcAddress(GetModuleHandleA("user32.dll"),
"SetProcessDPIAware"));
return set_process_dpi_aware_func &&
set_process_dpi_aware_func();
}

void EnableHighDPISupport() {
if (!SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) {
SetProcessDPIAwareWrapper();
}
}

int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
CommandLine::Init(0, NULL);
#if 0 //FIXME
if (base::win::GetVersion() > base::win::VERSION_VISTA)
gfx::EnableHighDPISupport();
#endif

if (base::win::GetVersion() >= base::win::VERSION_WIN7)
EnableHighDPISupport();

sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);
Expand Down

0 comments on commit 8e1bade

Please sign in to comment.