Skip to content

Commit d5e5d4a

Browse files
committed
move vista+ display config function ptr calls to device->driverdata
backport from PR/9923 (commit e4518af)
1 parent 51ba036 commit d5e5d4a

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

src/video/windows/SDL_windowsmodes.c

+7-29
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,8 @@ static SDL_bool WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_D
193193
return SDL_TRUE;
194194
}
195195

196-
/* The win32 API calls in this function require Windows Vista or later. */
197-
/* *INDENT-OFF* */ /* clang-format off */
198-
typedef LONG (WINAPI *SDL_WIN32PROC_GetDisplayConfigBufferSizes)(UINT32 flags, UINT32* numPathArrayElements, UINT32* numModeInfoArrayElements);
199-
typedef LONG (WINAPI *SDL_WIN32PROC_QueryDisplayConfig)(UINT32 flags, UINT32* numPathArrayElements, DISPLAYCONFIG_PATH_INFO* pathArray, UINT32* numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO* modeInfoArray, DISPLAYCONFIG_TOPOLOGY_ID* currentTopologyId);
200-
typedef LONG (WINAPI *SDL_WIN32PROC_DisplayConfigGetDeviceInfo)(DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket);
201-
/* *INDENT-ON* */ /* clang-format on */
202-
203-
static char *WIN_GetDisplayNameVista(const WCHAR *deviceName)
196+
static char *WIN_GetDisplayNameVista(SDL_VideoData *videodata, const WCHAR *deviceName)
204197
{
205-
void *dll;
206-
SDL_WIN32PROC_GetDisplayConfigBufferSizes pGetDisplayConfigBufferSizes;
207-
SDL_WIN32PROC_QueryDisplayConfig pQueryDisplayConfig;
208-
SDL_WIN32PROC_DisplayConfigGetDeviceInfo pDisplayConfigGetDeviceInfo;
209198
DISPLAYCONFIG_PATH_INFO *paths = NULL;
210199
DISPLAYCONFIG_MODE_INFO *modes = NULL;
211200
char *retval = NULL;
@@ -214,21 +203,12 @@ static char *WIN_GetDisplayNameVista(const WCHAR *deviceName)
214203
UINT32 i;
215204
LONG rc;
216205

217-
dll = SDL_LoadObject("USER32.DLL");
218-
if (!dll) {
206+
if (!videodata->GetDisplayConfigBufferSizes || !videodata->QueryDisplayConfig || !videodata->DisplayConfigGetDeviceInfo) {
219207
return NULL;
220208
}
221209

222-
pGetDisplayConfigBufferSizes = (SDL_WIN32PROC_GetDisplayConfigBufferSizes)SDL_LoadFunction(dll, "GetDisplayConfigBufferSizes");
223-
pQueryDisplayConfig = (SDL_WIN32PROC_QueryDisplayConfig)SDL_LoadFunction(dll, "QueryDisplayConfig");
224-
pDisplayConfigGetDeviceInfo = (SDL_WIN32PROC_DisplayConfigGetDeviceInfo)SDL_LoadFunction(dll, "DisplayConfigGetDeviceInfo");
225-
226-
if (!pGetDisplayConfigBufferSizes || !pQueryDisplayConfig || !pDisplayConfigGetDeviceInfo) {
227-
goto WIN_GetDisplayNameVista_failed;
228-
}
229-
230210
do {
231-
rc = pGetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount);
211+
rc = videodata->GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount);
232212
if (rc != ERROR_SUCCESS) {
233213
goto WIN_GetDisplayNameVista_failed;
234214
}
@@ -242,7 +222,7 @@ static char *WIN_GetDisplayNameVista(const WCHAR *deviceName)
242222
goto WIN_GetDisplayNameVista_failed;
243223
}
244224

245-
rc = pQueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, paths, &modeCount, modes, 0);
225+
rc = videodata->QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, paths, &modeCount, modes, 0);
246226
} while (rc == ERROR_INSUFFICIENT_BUFFER);
247227

248228
if (rc == ERROR_SUCCESS) {
@@ -255,7 +235,7 @@ static char *WIN_GetDisplayNameVista(const WCHAR *deviceName)
255235
sourceName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME;
256236
sourceName.header.size = sizeof(sourceName);
257237
sourceName.header.id = paths[i].sourceInfo.id;
258-
rc = pDisplayConfigGetDeviceInfo(&sourceName.header);
238+
rc = videodata->DisplayConfigGetDeviceInfo(&sourceName.header);
259239
if (rc != ERROR_SUCCESS) {
260240
break;
261241
} else if (SDL_wcscmp(deviceName, sourceName.viewGdiDeviceName) != 0) {
@@ -267,7 +247,7 @@ static char *WIN_GetDisplayNameVista(const WCHAR *deviceName)
267247
targetName.header.id = paths[i].targetInfo.id;
268248
targetName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME;
269249
targetName.header.size = sizeof(targetName);
270-
rc = pDisplayConfigGetDeviceInfo(&targetName.header);
250+
rc = videodata->DisplayConfigGetDeviceInfo(&targetName.header);
271251
if (rc == ERROR_SUCCESS) {
272252
retval = WIN_StringToUTF8W(targetName.monitorFriendlyDeviceName);
273253
/* if we got an empty string, treat it as failure so we'll fallback
@@ -283,14 +263,12 @@ static char *WIN_GetDisplayNameVista(const WCHAR *deviceName)
283263

284264
SDL_free(paths);
285265
SDL_free(modes);
286-
SDL_UnloadObject(dll);
287266
return retval;
288267

289268
WIN_GetDisplayNameVista_failed:
290269
SDL_free(retval);
291270
SDL_free(paths);
292271
SDL_free(modes);
293-
SDL_UnloadObject(dll);
294272
return NULL;
295273
}
296274

@@ -360,7 +338,7 @@ static void WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info,
360338
displaydata->IsValid = SDL_TRUE;
361339

362340
SDL_zero(display);
363-
display.name = WIN_GetDisplayNameVista(info->szDevice);
341+
display.name = WIN_GetDisplayNameVista(_this->driverdata, info->szDevice);
364342
if (!display.name) {
365343
DISPLAY_DEVICEW device;
366344
SDL_zero(device);

src/video/windows/SDL_windowsvideo.c

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ static SDL_VideoDevice *WIN_CreateDevice(void)
139139
data->GetDpiForWindow = (UINT (WINAPI *)(HWND))SDL_LoadFunction(data->userDLL, "GetDpiForWindow");
140140
data->AreDpiAwarenessContextsEqual = (BOOL (WINAPI *)(DPI_AWARENESS_CONTEXT, DPI_AWARENESS_CONTEXT))SDL_LoadFunction(data->userDLL, "AreDpiAwarenessContextsEqual");
141141
data->IsValidDpiAwarenessContext = (BOOL (WINAPI *)(DPI_AWARENESS_CONTEXT))SDL_LoadFunction(data->userDLL, "IsValidDpiAwarenessContext");
142+
data->GetDisplayConfigBufferSizes = (LONG (WINAPI *)(UINT32,UINT32*,UINT32* ))SDL_LoadFunction(data->userDLL, "GetDisplayConfigBufferSizes");
143+
data->QueryDisplayConfig = (LONG (WINAPI *)(UINT32,UINT32*,DISPLAYCONFIG_PATH_INFO*,UINT32*,DISPLAYCONFIG_MODE_INFO*,DISPLAYCONFIG_TOPOLOGY_ID*))SDL_LoadFunction(data->userDLL, "QueryDisplayConfig");
144+
data->DisplayConfigGetDeviceInfo = (LONG (WINAPI *)(DISPLAYCONFIG_DEVICE_INFO_HEADER*))SDL_LoadFunction(data->userDLL, "DisplayConfigGetDeviceInfo");
142145
/* *INDENT-ON* */ /* clang-format on */
143146
} else {
144147
SDL_ClearError();

src/video/windows/SDL_windowsvideo.h

+4
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ typedef struct SDL_VideoData
389389
UINT (WINAPI *GetDpiForWindow)( HWND );
390390
BOOL (WINAPI *AreDpiAwarenessContextsEqual)(DPI_AWARENESS_CONTEXT, DPI_AWARENESS_CONTEXT);
391391
BOOL (WINAPI *IsValidDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
392+
/* DisplayConfig functions */
393+
LONG (WINAPI *GetDisplayConfigBufferSizes)( UINT32, UINT32*, UINT32* );
394+
LONG (WINAPI *QueryDisplayConfig)( UINT32, UINT32*, DISPLAYCONFIG_PATH_INFO*, UINT32*, DISPLAYCONFIG_MODE_INFO*, DISPLAYCONFIG_TOPOLOGY_ID*);
395+
LONG (WINAPI *DisplayConfigGetDeviceInfo)( DISPLAYCONFIG_DEVICE_INFO_HEADER*);
392396
/* *INDENT-ON* */ /* clang-format on */
393397

394398
void *shcoreDLL;

0 commit comments

Comments
 (0)