1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "DisplayConfigWindows.h"
16 optional
<DisplayConfig
> GetDisplayConfig() {
21 vector
<DISPLAYCONFIG_PATH_INFO
> paths
;
22 vector
<DISPLAYCONFIG_MODE_INFO
> modes
;
24 result
= GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS
, &numPaths
,
26 if (result
!= ERROR_SUCCESS
) {
29 // allocate the recommended amount of space
30 paths
.resize(numPaths
);
31 modes
.resize(numModes
);
33 result
= QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS
, &numPaths
, paths
.data(),
34 &numModes
, modes
.data(), NULL
);
35 // try again if there wasn't enough space
36 } while (result
== ERROR_INSUFFICIENT_BUFFER
);
38 if (result
!= ERROR_SUCCESS
) return {};
40 // shrink to fit the actual number of modes and paths returned
41 modes
.resize(numModes
);
42 paths
.resize(numPaths
);
44 return DisplayConfig
{paths
, modes
};
47 bool HasScaledResolution() {
48 auto config
= GetDisplayConfig();
50 for (auto& path
: config
->mPaths
) {
51 auto& modes
= config
->mModes
;
52 int targetModeIndex
= path
.targetInfo
.modeInfoIdx
;
53 int sourceModeIndex
= path
.sourceInfo
.modeInfoIdx
;
55 // Check if the source and target resolutions are different
56 if ((modes
[targetModeIndex
]
57 .targetMode
.targetVideoSignalInfo
.activeSize
.cx
!=
58 modes
[sourceModeIndex
].sourceMode
.width
) ||
59 (modes
[targetModeIndex
]
60 .targetMode
.targetVideoSignalInfo
.activeSize
.cy
!=
61 modes
[sourceModeIndex
].sourceMode
.height
)) {
69 void GetScaledResolutions(ScaledResolutionSet
& aRv
) {
70 auto config
= GetDisplayConfig();
72 for (auto& path
: config
->mPaths
) {
73 auto& modes
= config
->mModes
;
74 int targetModeIndex
= path
.targetInfo
.modeInfoIdx
;
75 int sourceModeIndex
= path
.sourceInfo
.modeInfoIdx
;
77 // Check if the source and target resolutions are different
78 IntSize
src(modes
[sourceModeIndex
].sourceMode
.width
,
79 modes
[sourceModeIndex
].sourceMode
.height
);
81 modes
[targetModeIndex
].targetMode
.targetVideoSignalInfo
.activeSize
.cx
,
82 modes
[targetModeIndex
]
83 .targetMode
.targetVideoSignalInfo
.activeSize
.cy
);
85 aRv
.AppendElement(std::pair
<IntSize
, IntSize
>{src
, dst
});
92 } // namespace mozilla