DisplayConfigWindows.cpp (2863B)
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/. */ 5 6 #include <windows.h> 7 8 #include "DisplayConfigWindows.h" 9 10 namespace mozilla { 11 namespace gfx { 12 13 using namespace std; 14 15 optional<DisplayConfig> GetDisplayConfig() { 16 LONG result; 17 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 {}; 27 } 28 // allocate the recommended amount of space 29 paths.resize(numPaths); 30 modes.resize(numModes); 31 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); 36 37 if (result != ERROR_SUCCESS) return {}; 38 39 // shrink to fit the actual number of modes and paths returned 40 modes.resize(numModes); 41 paths.resize(numPaths); 42 43 return DisplayConfig{paths, modes}; 44 } 45 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; 53 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; 62 } 63 } 64 } 65 return false; 66 } 67 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; 75 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}); 85 } 86 } 87 } 88 } 89 90 } // namespace gfx 91 } // namespace mozilla