From 468714cab94f90cc52218b6f72fcbf14e3f47e8b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 22 Sep 2014 19:25:05 +0200 Subject: [PATCH] Unified video mode enumeration. --- src/cocoa_monitor.m | 24 +++++++++++++++++++----- src/x11_monitor.c | 6 +----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 5ced387e..cfb76a79 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -326,7 +326,7 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) { CFArrayRef modes; - CFIndex count, i; + CFIndex count, i, j; GLFWvidmode* result; CVDisplayLinkRef link; @@ -340,12 +340,26 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) for (i = 0; i < count; i++) { - CGDisplayModeRef mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); - if (modeIsGood(mode)) + CGDisplayModeRef dm = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); + if (!modeIsGood(dm)) + continue; + + const GLFWvidmode mode = vidmodeFromCGDisplayMode(dm, link); + + for (j = 0; j < *found; j++) { - result[*found] = vidmodeFromCGDisplayMode(mode, link); - (*found)++; + if (_glfwCompareVideoModes(result + j, &mode) == 0) + break; } + + if (i < *found) + { + // This is a duplicate, so skip it + continue; + } + + result[*found] = mode; + (*found)++; } CFRelease(modes); diff --git a/src/x11_monitor.c b/src/x11_monitor.c index d0bbb434..36d914d6 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -352,12 +352,8 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) for (j = 0; j < *found; j++) { - if (result[j].width == mode.width && - result[j].height == mode.height && - result[j].refreshRate == mode.refreshRate) - { + if (_glfwCompareVideoModes(result + j, &mode) == 0) break; - } } if (j < *found)