From 842aeb8c470eb93459cd152354522cd7269033c1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 20 Sep 2015 16:25:00 +0200 Subject: [PATCH] Make Win32 video mode enumeration faster --- src/win32_monitor.c | 25 ++++++++++++++++--------- src/win32_platform.h | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/win32_monitor.c b/src/win32_monitor.c index be5686f8..5b235db6 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -152,6 +152,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) DeleteDC(dc); free(name); + if (adapter.StateFlags & DISPLAY_DEVICE_MODESPRUNED) + monitor->win32.modesPruned = GL_TRUE; + wcscpy(monitor->win32.adapterName, adapter.DeviceName); wcscpy(monitor->win32.displayName, display.DeviceName); @@ -226,15 +229,6 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) modeIndex++; - if (ChangeDisplaySettingsExW(monitor->win32.adapterName, - &dm, - NULL, - CDS_TEST, - NULL) != DISP_CHANGE_SUCCESSFUL) - { - continue; - } - // Skip modes with less than 15 BPP if (dm.dmBitsPerPel < 15) continue; @@ -257,6 +251,19 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) if (i < *count) continue; + if (monitor->win32.modesPruned) + { + // Skip modes not supported by the connected displays + if (ChangeDisplaySettingsExW(monitor->win32.adapterName, + &dm, + NULL, + CDS_TEST, + NULL) != DISP_CHANGE_SUCCESSFUL) + { + continue; + } + } + if (*count == size) { if (*count) diff --git a/src/win32_platform.h b/src/win32_platform.h index e8e32dfc..d3e190e9 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -203,6 +203,7 @@ typedef struct _GLFWmonitorWin32 WCHAR displayName[32]; char publicAdapterName[64]; char publicDisplayName[64]; + GLboolean modesPruned; GLboolean modeChanged; } _GLFWmonitorWin32;