MCPcopy Create free account
hub / github.com/Aleksoid1978/VideoRenderer / GetDisplayConfigs

Function GetDisplayConfigs

Source/DisplayConfig.cpp:201–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201bool GetDisplayConfigs(std::vector<DisplayConfig_t>& displayConfigs)
202{
203 UINT32 num_paths;
204 UINT32 num_modes;
205 std::vector<DISPLAYCONFIG_PATH_INFO> paths;
206 std::vector<DISPLAYCONFIG_MODE_INFO> modes;
207 LONG res;
208
209 // The display configuration could change between the call to
210 // GetDisplayConfigBufferSizes and the call to QueryDisplayConfig, so call
211 // them in a loop until the correct buffer size is chosen
212 do {
213 res = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &num_paths, &num_modes);
214 if (res == ERROR_SUCCESS) {
215 paths.resize(num_paths);
216 modes.resize(num_modes);
217 res = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &num_paths, paths.data(), &num_modes, modes.data(), nullptr);
218 }
219 } while (res == ERROR_INSUFFICIENT_BUFFER);
220
221 if (res != ERROR_SUCCESS) {
222 return false;
223 }
224
225 displayConfigs.clear();
226
227 // num_paths and num_modes could decrease in a loop
228 paths.resize(num_paths);
229 modes.resize(num_modes);
230
231 for (const auto& path : paths) {
232 // Send a GET_SOURCE_NAME request
233 DISPLAYCONFIG_SOURCE_DEVICE_NAME source = {
234 {DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, sizeof(source), path.sourceInfo.adapterId, path.sourceInfo.id}, {},
235 };
236 if (DisplayConfigGetDeviceInfo(&source.header) == ERROR_SUCCESS) {
237 DisplayConfig_t dc = {};
238 if (path.sourceInfo.modeInfoIdx != DISPLAYCONFIG_PATH_MODE_IDX_INVALID) {
239 const auto& mode = modes[path.sourceInfo.modeInfoIdx];
240 if (mode.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE) {
241 dc.width = mode.sourceMode.width;;
242 dc.height = mode.sourceMode.height;
243 }
244 }
245 if (path.targetInfo.modeInfoIdx != DISPLAYCONFIG_PATH_MODE_IDX_INVALID) {
246 const auto& mode = modes[path.targetInfo.modeInfoIdx];
247 if (mode.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) {
248 dc.refreshRate = mode.targetMode.targetVideoSignalInfo.vSyncFreq;
249 dc.scanLineOrdering = mode.targetMode.targetVideoSignalInfo.scanLineOrdering;
250 }
251 dc.modeTarget = mode;
252
253 if (IsWindows11_24H2OrGreater()) {
254 DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2 color_info = {
255 {static_cast<DISPLAYCONFIG_DEVICE_INFO_TYPE>(DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO_2),
256 sizeof(color_info), mode.adapterId, mode.id}, {}
257 };
258 res = DisplayConfigGetDeviceInfo(&color_info.header);

Callers 1

OnActivateMethod · 0.85

Calls 2

is_valid_refresh_rateFunction · 0.85

Tested by

no test coverage detected