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

Function GetDisplayConfig

Source/DisplayConfig.cpp:96–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96bool GetDisplayConfig(const wchar_t* displayName, DisplayConfig_t& displayConfig)
97{
98 UINT32 num_paths;
99 UINT32 num_modes;
100 std::vector<DISPLAYCONFIG_PATH_INFO> paths;
101 std::vector<DISPLAYCONFIG_MODE_INFO> modes;
102 LONG res;
103
104 // The display configuration could change between the call to
105 // GetDisplayConfigBufferSizes and the call to QueryDisplayConfig, so call
106 // them in a loop until the correct buffer size is chosen
107 do {
108 res = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &num_paths, &num_modes);
109 if (ERROR_SUCCESS == res) {
110 paths.resize(num_paths);
111 modes.resize(num_modes);
112 res = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &num_paths, paths.data(), &num_modes, modes.data(), nullptr);
113 }
114 } while (ERROR_INSUFFICIENT_BUFFER == res);
115
116 if (res == ERROR_SUCCESS) {
117 // num_paths and num_modes could decrease in a loop
118 paths.resize(num_paths);
119 modes.resize(num_modes);
120
121 for (const auto& path : paths) {
122 // Send a GET_SOURCE_NAME request
123 DISPLAYCONFIG_SOURCE_DEVICE_NAME source = {
124 {DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, sizeof(source), path.sourceInfo.adapterId, path.sourceInfo.id}, {},
125 };
126 res = DisplayConfigGetDeviceInfo(&source.header);
127 if (ERROR_SUCCESS == res) {
128 if (wcscmp(displayName, source.viewGdiDeviceName) == 0) {
129 displayConfig = {};
130
131 if (path.sourceInfo.modeInfoIdx != DISPLAYCONFIG_PATH_MODE_IDX_INVALID) {
132 const auto& mode = modes[path.sourceInfo.modeInfoIdx];
133 if (mode.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE) {
134 displayConfig.width = mode.sourceMode.width;;
135 displayConfig.height = mode.sourceMode.height;
136 }
137 }
138 if (path.targetInfo.modeInfoIdx != DISPLAYCONFIG_PATH_MODE_IDX_INVALID) {
139 const auto& mode = modes[path.targetInfo.modeInfoIdx];
140 if (mode.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) {
141 displayConfig.refreshRate = mode.targetMode.targetVideoSignalInfo.vSyncFreq;
142 displayConfig.scanLineOrdering = mode.targetMode.targetVideoSignalInfo.scanLineOrdering;
143 }
144 displayConfig.modeTarget = mode;
145
146 if (IsWindows11_24H2OrGreater()) {
147 DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2 color_info = {
148 {static_cast<DISPLAYCONFIG_DEVICE_INFO_TYPE>(DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO_2),
149 sizeof(color_info), mode.adapterId, mode.id}, {}
150 };
151 res = DisplayConfigGetDeviceInfo(&color_info.header);
152 if (ERROR_SUCCESS == res) {
153 displayConfig.colorEncoding = color_info.colorEncoding;

Callers 6

CDX11VideoProcessorMethod · 0.85
~CDX11VideoProcessorMethod · 0.85
FillDisplayParamsMethod · 0.85
HandleHDRToggleMethod · 0.85
ResetMethod · 0.85
UpdateDisplayInfoMethod · 0.85

Calls 2

is_valid_refresh_rateFunction · 0.85

Tested by

no test coverage detected