Bug 1758688 [wpt PR 33067] - [FedCM] Make revoke a non-static method, a=testonly
[gecko.git] / gfx / thebes / DisplayConfigWindows.cpp
blob49fc13c580b77734f0c6bfd5496fa09a097f236d
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/. */
6 #include <iostream>
7 #include <windows.h>
8 #include <wingdi.h>
9 #include <optional>
10 #include <vector>
12 #include "DisplayConfigWindows.h"
14 namespace mozilla {
15 namespace gfx {
17 using namespace std;
19 struct DisplayConfig {
20 vector<DISPLAYCONFIG_PATH_INFO> mPaths;
21 vector<DISPLAYCONFIG_MODE_INFO> mModes;
24 optional<DisplayConfig> GetDisplayConfig() {
25 LONG result;
27 UINT32 numPaths;
28 UINT32 numModes;
29 vector<DISPLAYCONFIG_PATH_INFO> paths;
30 vector<DISPLAYCONFIG_MODE_INFO> modes;
31 do {
32 result = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &numPaths,
33 &numModes);
34 if (result != ERROR_SUCCESS) {
35 return {};
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();
57 if (config) {
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)) {
70 return true;
74 return false;
77 void GetScaledResolutions(ScaledResolutionSet& aRv) {
78 auto config = GetDisplayConfig();
79 if (config) {
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);
88 IntSize dst(
89 modes[targetModeIndex].targetMode.targetVideoSignalInfo.activeSize.cx,
90 modes[targetModeIndex]
91 .targetMode.targetVideoSignalInfo.activeSize.cy);
92 if (src != dst) {
93 aRv.AppendElement(std::pair<IntSize, IntSize>{src, dst});
99 } // namespace gfx
100 } // namespace mozilla