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/. */
8 #include "DisplayConfigWindows.h"
15 optional
<DisplayConfig
> GetDisplayConfig() {
20 vector
<DISPLAYCONFIG_PATH_INFO
> paths
;
21 vector
<DISPLAYCONFIG_MODE_INFO
> modes
;
23 result
= GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS
, &numPaths
,
25 if (result
!= ERROR_SUCCESS
) {
28 // allocate the recommended amount of space
29 paths
.resize(numPaths
);
30 modes
.resize(numModes
);
32 result
= QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS
, &numPaths
, paths
.data(),
33 &numModes
, modes
.data(), NULL
);
34 // try again if there wasn't enough space
35 } while (result
== ERROR_INSUFFICIENT_BUFFER
);
37 if (result
!= ERROR_SUCCESS
) return {};
39 // shrink to fit the actual number of modes and paths returned
40 modes
.resize(numModes
);
41 paths
.resize(numPaths
);
43 return DisplayConfig
{paths
, modes
};
46 bool HasScaledResolution() {
47 auto config
= GetDisplayConfig();
49 for (auto& path
: config
->mPaths
) {
50 auto& modes
= config
->mModes
;
51 int targetModeIndex
= path
.targetInfo
.modeInfoIdx
;
52 int sourceModeIndex
= path
.sourceInfo
.modeInfoIdx
;
54 // Check if the source and target resolutions are different
55 if ((modes
[targetModeIndex
]
56 .targetMode
.targetVideoSignalInfo
.activeSize
.cx
!=
57 modes
[sourceModeIndex
].sourceMode
.width
) ||
58 (modes
[targetModeIndex
]
59 .targetMode
.targetVideoSignalInfo
.activeSize
.cy
!=
60 modes
[sourceModeIndex
].sourceMode
.height
)) {
68 void GetScaledResolutions(ScaledResolutionSet
& aRv
) {
69 auto config
= GetDisplayConfig();
71 for (auto& path
: config
->mPaths
) {
72 auto& modes
= config
->mModes
;
73 int targetModeIndex
= path
.targetInfo
.modeInfoIdx
;
74 int sourceModeIndex
= path
.sourceInfo
.modeInfoIdx
;
76 // Check if the source and target resolutions are different
77 IntSize
src(modes
[sourceModeIndex
].sourceMode
.width
,
78 modes
[sourceModeIndex
].sourceMode
.height
);
80 modes
[targetModeIndex
].targetMode
.targetVideoSignalInfo
.activeSize
.cx
,
81 modes
[targetModeIndex
]
82 .targetMode
.targetVideoSignalInfo
.activeSize
.cy
);
84 aRv
.AppendElement(std::pair
<IntSize
, IntSize
>{src
, dst
});
91 } // namespace mozilla