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/. */
12 #include "DisplayConfigWindows.h"
19 struct DisplayConfig
{
20 vector
<DISPLAYCONFIG_PATH_INFO
> mPaths
;
21 vector
<DISPLAYCONFIG_MODE_INFO
> mModes
;
24 optional
<DisplayConfig
> GetDisplayConfig() {
29 vector
<DISPLAYCONFIG_PATH_INFO
> paths
;
30 vector
<DISPLAYCONFIG_MODE_INFO
> modes
;
32 result
= GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS
, &numPaths
,
34 if (result
!= ERROR_SUCCESS
) {
37 // allocate the recommended amount of space
38 paths
.resize(numPaths
);
39 modes
.resize(numModes
);
41 result
= QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS
, &numPaths
, paths
.data(),
42 &numModes
, modes
.data(), NULL
);
43 // try again if there wasn't enough space
44 } while (result
== ERROR_INSUFFICIENT_BUFFER
);
46 if (result
!= ERROR_SUCCESS
) return {};
48 // shrink to fit the actual number of modes and paths returned
49 modes
.resize(numModes
);
50 paths
.resize(numPaths
);
52 return DisplayConfig
{paths
, modes
};
55 bool HasScaledResolution() {
56 auto config
= GetDisplayConfig();
58 for (auto& path
: config
->mPaths
) {
59 auto& modes
= config
->mModes
;
60 int targetModeIndex
= path
.targetInfo
.modeInfoIdx
;
61 int sourceModeIndex
= path
.sourceInfo
.modeInfoIdx
;
63 // Check if the source and target resolutions are different
64 if ((modes
[targetModeIndex
]
65 .targetMode
.targetVideoSignalInfo
.activeSize
.cx
!=
66 modes
[sourceModeIndex
].sourceMode
.width
) ||
67 (modes
[targetModeIndex
]
68 .targetMode
.targetVideoSignalInfo
.activeSize
.cy
!=
69 modes
[sourceModeIndex
].sourceMode
.height
)) {
77 void GetScaledResolutions(ScaledResolutionSet
& aRv
) {
78 auto config
= GetDisplayConfig();
80 for (auto& path
: config
->mPaths
) {
81 auto& modes
= config
->mModes
;
82 int targetModeIndex
= path
.targetInfo
.modeInfoIdx
;
83 int sourceModeIndex
= path
.sourceInfo
.modeInfoIdx
;
85 // Check if the source and target resolutions are different
86 IntSize
src(modes
[sourceModeIndex
].sourceMode
.width
,
87 modes
[sourceModeIndex
].sourceMode
.height
);
89 modes
[targetModeIndex
].targetMode
.targetVideoSignalInfo
.activeSize
.cx
,
90 modes
[targetModeIndex
]
91 .targetMode
.targetVideoSignalInfo
.activeSize
.cy
);
93 aRv
.AppendElement(std::pair
<IntSize
, IntSize
>{src
, dst
});
100 } // namespace mozilla