Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / thebes / DisplayConfigWindows.cpp
blobba5db0aa20c9ce5b9d98ac87948725de75474367
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 <windows.h>
8 #include "DisplayConfigWindows.h"
10 namespace mozilla {
11 namespace gfx {
13 using namespace std;
15 optional<DisplayConfig> GetDisplayConfig() {
16 LONG result;
18 UINT32 numPaths;
19 UINT32 numModes;
20 vector<DISPLAYCONFIG_PATH_INFO> paths;
21 vector<DISPLAYCONFIG_MODE_INFO> modes;
22 do {
23 result = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &numPaths,
24 &numModes);
25 if (result != ERROR_SUCCESS) {
26 return {};
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();
48 if (config) {
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)) {
61 return true;
65 return false;
68 void GetScaledResolutions(ScaledResolutionSet& aRv) {
69 auto config = GetDisplayConfig();
70 if (config) {
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);
79 IntSize dst(
80 modes[targetModeIndex].targetMode.targetVideoSignalInfo.activeSize.cx,
81 modes[targetModeIndex]
82 .targetMode.targetVideoSignalInfo.activeSize.cy);
83 if (src != dst) {
84 aRv.AppendElement(std::pair<IntSize, IntSize>{src, dst});
90 } // namespace gfx
91 } // namespace mozilla