diff options
author | Sven Gothel <[email protected]> | 2023-01-14 20:23:46 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-01-14 20:23:46 +0100 |
commit | 4b944d5ae8cd0040ee43fcdefa92bfe06c56518b (patch) | |
tree | ec5e1ac5546bf615564568a1831641ae971c17f2 /src/jogl/native | |
parent | b367231929a8e4d8eac53933a59a297b75ef5e58 (diff) |
MacOS: MacOSXCGLContext.drawableUpdatedNotify(): Issue updateContext() on main thread, deferred w/o wait (MacOS >= 13)
updateContextRegister() stays in current thread.
Diffstat (limited to 'src/jogl/native')
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface.m | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m index 16b85974e..78b0b1854 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m @@ -643,12 +643,17 @@ void setContextOpacity(NSOpenGLContext* ctx, int opacity) { [ctx setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity]; } -void updateContext(NSOpenGLContext* ctx) { +void updateContext(NSOpenGLContext* ctx, Bool onMainThread) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSView *nsView = [ctx view]; if(NULL != nsView) { - DBG_PRINT("updateContext.0: ctx %p, ctx.view %p\n", ctx, nsView); - [ctx update]; + Bool isMainThread = [NSThread isMainThread]; + DBG_PRINT("updateContext.0: ctx %p, ctx.view %p, onMain %d, isMain %d\n", ctx, nsView, onMainThread, isMainThread); + if(onMainThread && NO == isMainThread) { + [ctx performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:NO]; + } else { + [ctx update]; + } DBG_PRINT("updateContext.X\n"); } [pool release]; @@ -658,14 +663,25 @@ void copyContext(NSOpenGLContext* dest, NSOpenGLContext* src, int mask) { [dest copyAttributesFromContext: src withMask: mask]; } -void* updateContextRegister(NSOpenGLContext* ctx, NSView* view) { +void* updateContextRegister(NSOpenGLContext* ctx, NSView* view, Bool onMainThread) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - DBG_PRINT("updateContextRegister.0: ctx %p, view %p\n", ctx, view); - ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view]; - DBG_PRINT("updateContextRegister.X: ctxupd %p\n", contextUpdater); - [pool release]; - return contextUpdater; + Bool isMainThread = [NSThread isMainThread]; + DBG_PRINT("updateContextRegister.0: ctx %p, view %p, onMain %d, isMain %d\n", ctx, view, onMainThread, isMainThread); + if(onMainThread && NO == isMainThread) { + __block ContextUpdater *contextUpdater = NULL; + dispatch_sync(dispatch_get_main_queue(), ^{ + contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view]; + }); + DBG_PRINT("updateContextRegister.XM: ctxupd %p\n", contextUpdater); + [pool release]; + return contextUpdater; + } else { + ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view]; + DBG_PRINT("updateContextRegister.X_: ctxupd %p\n", contextUpdater); + [pool release]; + return contextUpdater; + } } Bool updateContextNeedsUpdate(void* updater) { |