diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index 8c7837ed327..28771d4a8bc 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -13,11 +13,14 @@ #include #include +#include +#include #include #include "atom/app/atom_main_delegate.h" #include "atom/common/crash_reporter/win/crash_service_main.h" #include "base/environment.h" +#include "base/win/windows_version.h" #include "content/public/app/startup_helper_win.h" #include "sandbox/win/src/sandbox_types.h" #include "ui/gfx/win/dpi.h" @@ -37,6 +40,48 @@ int Start(int argc, char *argv[]); #if defined(OS_WIN) +namespace { + +// 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( + 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( + 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(); + } +} + +} // namespace + int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { int argc = 0; wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); @@ -103,8 +148,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { content::InitializeSandboxInfo(&sandbox_info); atom::AtomMainDelegate delegate; - // Now chrome relies on a regkey to enable high dpi support. - gfx::EnableHighDPISupport(); + // We don't want to set DPI awareness on pre-Win7 because we don't support + // DirectWrite there. GDI fonts are kerned very badly, so better to leave + // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). + if (base::win::GetVersion() >= base::win::VERSION_WIN7) + EnableHighDPISupport(); content::ContentMainParams params(&delegate); params.instance = instance;