[Commits] SDL: macOS: Make sure the desktop's display mode is always in SD...

libsdl.org revision control commits-owner at libsdl.org
Fri Dec 29 18:14:01 PST 2017


details:   https://hg.libsdl.org/SDL/rev/677c76668fe1
changeset: 11786:677c76668fe1
user:      Alex Szpakowski <slime73 at gmail.com>
date:      Fri Dec 29 22:13:40 2017 -0400
description:
macOS: Make sure the desktop's display mode is always in SDL's list of display modes.

diffstat:

 src/video/cocoa/SDL_cocoamodes.m |  40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diffs (65 lines):

diff -r 6d85907059ff -r 677c76668fe1 src/video/cocoa/SDL_cocoamodes.m
--- a/src/video/cocoa/SDL_cocoamodes.m	Tue Dec 19 11:19:10 2017 -0800
+++ b/src/video/cocoa/SDL_cocoamodes.m	Fri Dec 29 22:13:40 2017 -0400
@@ -340,29 +340,53 @@
 Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
 {
     SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
-    CFArrayRef modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
+    CVDisplayLinkRef link = NULL;
+    CGDisplayModeRef desktopmoderef;
+    SDL_DisplayMode desktopmode;
+    CFArrayRef modes;
+
+    CVDisplayLinkCreateWithCGDisplay(data->display, &link);
+
+    desktopmoderef = CGDisplayCopyDisplayMode(data->display);
+
+    /* CopyAllDisplayModes won't always contain the desktop display mode (if
+     * NULL is passed in) - for example on a retina 15" MBP, System Preferences
+     * allows choosing 1920x1200 but it's not in the list. AddDisplayMode makes
+     * sure there are no duplicates so it's safe to always add the desktop mode
+     * even in cases where it is in the CopyAllDisplayModes list.
+     */
+    if (desktopmoderef && GetDisplayMode(_this, desktopmoderef, link, &desktopmode)) {
+        if (!SDL_AddDisplayMode(display, &desktopmode)) {
+            CGDisplayModeRelease(desktopmoderef);
+            SDL_free(desktopmode.driverdata);
+        }
+    } else {
+        CGDisplayModeRelease(desktopmoderef);
+    }
+
+    modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
 
     if (modes) {
-        CVDisplayLinkRef link = NULL;
+        CFIndex i;
         const CFIndex count = CFArrayGetCount(modes);
-        CFIndex i;
-
-        CVDisplayLinkCreateWithCGDisplay(data->display, &link);
 
         for (i = 0; i < count; i++) {
             CGDisplayModeRef moderef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
             SDL_DisplayMode mode;
+
             if (GetDisplayMode(_this, moderef, link, &mode)) {
-                CGDisplayModeRetain(moderef);
-                if (!SDL_AddDisplayMode(display, &mode)) {
+                if (SDL_AddDisplayMode(display, &mode)) {
+                    CGDisplayModeRetain(moderef);
+                } else {
                     SDL_free(mode.driverdata);
                 }
             }
         }
 
-        CVDisplayLinkRelease(link);
         CFRelease(modes);
     }
+
+    CVDisplayLinkRelease(link);
 }
 
 int


More information about the commits mailing list