no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / mozglue / misc / WindowsDpiInitialization.cpp
blob972d577651c34ee2a15c6421fe2092a523263a4d
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/WindowsDpiInitialization.h"
7 #include "mozilla/DynamicallyLinkedFunctionPtr.h"
8 #include "mozilla/WindowsProcessMitigations.h"
9 #include "mozilla/WindowsVersion.h"
11 #include <shellscalingapi.h>
12 #include <windows.h>
14 namespace mozilla {
16 typedef HRESULT(WINAPI* SetProcessDpiAwarenessType)(PROCESS_DPI_AWARENESS);
17 typedef BOOL(WINAPI* SetProcessDpiAwarenessContextType)(DPI_AWARENESS_CONTEXT);
19 WindowsDpiInitializationResult WindowsDpiInitialization() {
20 // DPI Awareness can't be used in a Win32k Lockdown process, so there's
21 // nothing to do
22 if (IsWin32kLockedDown()) {
23 return WindowsDpiInitializationResult::Success;
26 // From MSDN:
27 // SetProcessDpiAwarenessContext() was added in the Win10 Anniversary Update
28 // SetProcessDpiAwareness() was added in Windows 8.1
29 // SetProcessDpiAware() was added in Windows Vista
31 // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 wasn't added later until
32 // the Creators Update, so if it fails we just fall back to
33 // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
34 if (IsWin10AnniversaryUpdateOrLater()) {
35 DynamicallyLinkedFunctionPtr<SetProcessDpiAwarenessContextType>
36 setProcessDpiAwarenessContext(L"user32.dll",
37 "SetProcessDpiAwarenessContext");
38 if (!setProcessDpiAwarenessContext) {
39 return WindowsDpiInitializationResult::
40 FindSetProcessDpiAwarenessContextFailed;
43 if (!setProcessDpiAwarenessContext(
44 DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) &&
45 !setProcessDpiAwarenessContext(
46 DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE)) {
47 return WindowsDpiInitializationResult::
48 SetProcessDpiAwarenessContextFailed;
51 return WindowsDpiInitializationResult::Success;
52 } else {
53 DynamicallyLinkedFunctionPtr<SetProcessDpiAwarenessType>
54 setProcessDpiAwareness(L"Shcore.dll", "SetProcessDpiAwareness");
55 if (!setProcessDpiAwareness) {
56 return WindowsDpiInitializationResult::FindSetProcessDpiAwarenessFailed;
59 if (FAILED(setProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE))) {
60 return WindowsDpiInitializationResult::SetProcessDpiAwarenessFailed;
63 return WindowsDpiInitializationResult::Success;
67 } // namespace mozilla