From dec7875a6e23212021e4d9080330a42832dfe02a Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Tue, 15 Jun 2021 01:40:19 +0000
Subject: [PATCH] update SDL soruce to 2.0.14

---
 source/src/video/cocoa/SDL_cocoaopengl.m |   47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/source/src/video/cocoa/SDL_cocoaopengl.m b/source/src/video/cocoa/SDL_cocoaopengl.m
index 75a63df..6fb4711 100644
--- a/source/src/video/cocoa/SDL_cocoaopengl.m
+++ b/source/src/video/cocoa/SDL_cocoaopengl.m
@@ -63,10 +63,10 @@
 /* This should only be called on the thread on which a user is using the context. */
 - (void)updateIfNeeded
 {
-    int value = SDL_AtomicSet(&self->dirty, 0);
+    const int value = SDL_AtomicSet(&self->dirty, 0);
     if (value > 0) {
         /* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
-        [super update];
+        [self explicitUpdate];
     }
 }
 
@@ -97,17 +97,6 @@
         SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata;
         NSView *contentview = windowdata->sdlContentView;
 
-        /* This should never be nil since sdlContentView is only nil if the
-           window was created via SDL_CreateWindowFrom, and SDL doesn't allow
-           OpenGL contexts to be created in that case. However, it doesn't hurt
-           to check. */
-        if (contentview == nil) {
-            /* Prefer to access the cached content view above instead of this,
-               since as of Xcode 11 + SDK 10.15, [window contentView] causes
-               Apple's Main Thread Checker to output a warning. */
-            contentview = [windowdata->nswindow contentView];
-        }
-
         /* Now sign up for scheduled updates for the new window. */
         NSMutableArray *contexts = windowdata->nscontexts;
         @synchronized (contexts) {
@@ -115,9 +104,13 @@
         }
 
         if ([self view] != contentview) {
-            [self setView:contentview];
+            if ([NSThread isMainThread]) {
+                [self setView:contentview];
+            } else {
+                dispatch_sync(dispatch_get_main_queue(), ^{ [self setView:contentview]; });
+            }
             if (self == [NSOpenGLContext currentContext]) {
-                [self update];
+                [self explicitUpdate];
             } else {
                 [self scheduleUpdate];
             }
@@ -125,10 +118,24 @@
     } else {
         [self clearDrawable];
         if (self == [NSOpenGLContext currentContext]) {
-            [self update];
+            [self explicitUpdate];
         } else {
             [self scheduleUpdate];
         }
+    }
+}
+
+- (SDL_Window*)window
+{
+    return self->window;
+}
+
+- (void)explicitUpdate
+{
+    if ([NSThread isMainThread]) {
+        [super update];
+    } else {
+        dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
     }
 }
 
@@ -348,8 +355,10 @@
 {
     if (context) {
         SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
-        [nscontext setWindow:window];
-        [nscontext updateIfNeeded];
+        if ([nscontext window] != window) {
+            [nscontext setWindow:window];
+            [nscontext updateIfNeeded];
+        }
         [nscontext makeCurrentContext];
     } else {
         [NSOpenGLContext clearCurrentContext];
@@ -362,7 +371,7 @@
 Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
 {
     SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
-    NSView *contentView = [windata->nswindow contentView];
+    NSView *contentView = windata->sdlContentView;
     NSRect viewport = [contentView bounds];
 
     if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {

--
Gitblit v1.9.3