Bug 1848468 - Mark k-rate-dynamics-compressor-connections.html subtest as failing...
[gecko.git] / gfx / thebes / DisplayConfigWindows.cpp
blobf9696a4070fd3f01ad3ef57c65025c345cb47e7b
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>
9 #include "DisplayConfigWindows.h"
11 namespace mozilla {
12 namespace gfx {
14 using namespace std;
16 optional<DisplayConfig> GetDisplayConfig() {
17 LONG result;
19 UINT32 numPaths;
20 UINT32 numModes;
21 vector<DISPLAYCONFIG_PATH_INFO> paths;
22 vector<DISPLAYCONFIG_MODE_INFO> modes;
23 do {
24 result = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &numPaths,
25 &numModes);
26 if (result != ERROR_SUCCESS) {
27 return {};
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();
49 if (config) {
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)) {
62 return true;
66 return false;
69 void GetScaledResolutions(ScaledResolutionSet& aRv) {
70 auto config = GetDisplayConfig();
71 if (config) {
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);
80 IntSize dst(
81 modes[targetModeIndex].targetMode.targetVideoSignalInfo.activeSize.cx,
82 modes[targetModeIndex]
83 .targetMode.targetVideoSignalInfo.activeSize.cy);
84 if (src != dst) {
85 aRv.AppendElement(std::pair<IntSize, IntSize>{src, dst});
91 } // namespace gfx
92 } // namespace mozilla