From 3119d58ff536424c361892a0aa76f95731ea0fbc Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 10 Aug 2022 10:48:23 -0400
Subject: [PATCH] cocoa: Change the new sync_dispatch hint to async_dispatch.
This is so the default is safer.
---
include/SDL_hints.h | 14 ++++++++++----
src/video/cocoa/SDL_cocoaopengl.m | 16 ++++++++--------
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index f50b5e06e8c..02d5fc5f845 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -981,13 +981,19 @@ extern "C" {
* \brief A variable controlling whether dispatching OpenGL context updates should block the dispatching thread until the main thread finishes processing
*
* This variable can be set to the following values:
- * "0" - Dispatching OpenGL context updates will allow the dispatching thread to continue execution.
- * "1" - Dispatching OpenGL context updates will block the dispatching thread until the main thread finishes processing.
+ * "0" - Dispatching OpenGL context updates will block the dispatching thread until the main thread finishes processing (default).
+ * "1" - Dispatching OpenGL context updates will allow the dispatching thread to continue execution.
*
- * This hint only applies to Mac OS X
+ * Generally you want the default, but if you have OpenGL code in a background thread on a Mac, and the main thread
+ * hangs because it's waiting for that background thread, but that background thread is also hanging because it's
+ * waiting for the main thread to do an update, this might fix your issue.
+ *
+ * This hint only applies to macOS.
+ *
+ * This hint is available since SDL 2.24.0.
*
*/
-#define SDL_HINT_MAC_OPENGL_SYNC_DISPATCH "SDL_MAC_OPENGL_SYNC_DISPATCH"
+#define SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH "SDL_MAC_OPENGL_ASYNC_DISPATCH"
/**
* \brief A variable setting the double click radius, in pixels.
diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m
index 31fe948a8de..91319d5a7bd 100644
--- a/src/video/cocoa/SDL_cocoaopengl.m
+++ b/src/video/cocoa/SDL_cocoaopengl.m
@@ -44,12 +44,12 @@
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
-static SDL_bool SDL_opengl_sync_dispatch = SDL_FALSE;
+static SDL_bool SDL_opengl_async_dispatch = SDL_FALSE;
static void SDLCALL
-SDL_OpenGLSyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+SDL_OpenGLAsyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
- SDL_opengl_sync_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
+ SDL_opengl_async_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
}
@implementation SDLOpenGLContext : NSOpenGLContext
@@ -63,7 +63,7 @@ - (id)initWithFormat:(NSOpenGLPixelFormat *)format
self->window = NULL;
}
- SDL_AddHintCallback(SDL_HINT_MAC_OPENGL_SYNC_DISPATCH, SDL_OpenGLSyncDispatchChanged, NULL);
+ SDL_AddHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
return self;
}
@@ -147,17 +147,17 @@ - (void)explicitUpdate
if ([NSThread isMainThread]) {
[super update];
} else {
- if (SDL_opengl_sync_dispatch) {
- dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
- } else {
+ if (SDL_opengl_async_dispatch) {
dispatch_async(dispatch_get_main_queue(), ^{ [super update]; });
+ } else {
+ dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
}
}
}
- (void)dealloc
{
- SDL_DelHintCallback(SDL_HINT_MAC_OPENGL_SYNC_DISPATCH, SDL_OpenGLSyncDispatchChanged, NULL);
+ SDL_DelHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
}
@end