From ae099e6623cf973193647495a27bcd4b25230c4a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 17 Dec 2011 21:56:59 +0100 Subject: MaxOSXWindowSystemInterface: deleteContext / releaseNSOpenGLLayer: - release on main-thread doesn't wait anymore - use recursive lock --- .../macosx/MacOSXWindowSystemInterface-pbuffer.m | 33 ++++++++++++++++------ .../native/macosx/MacOSXWindowSystemInterface.m | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/jogl/native/macosx') diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m index 34bf213ab..fe896cc53 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m @@ -55,6 +55,8 @@ - (void)deallocTex; - (void)disableAnimation; +- (void)releaseLayer; +- (void)dealloc; - (int)getSwapInterval; - (void)setSwapInterval:(int)interval; - (void)tick; @@ -94,7 +96,10 @@ static CVReturn renderMyNSOpenGLLayer(CVDisplayLinkRef displayLink, texWidth: (int) _texWidth texHeight: (int) _texHeight; { - pthread_mutex_init(&renderLock, NULL); // fast non-recursive + pthread_mutexattr_t renderLockAttr; + pthread_mutexattr_init(&renderLockAttr); + pthread_mutexattr_settype(&renderLockAttr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&renderLock, &renderLockAttr); // recursive pthread_cond_init(&renderSignal, NULL); // no attribute // no animations for add/remove/swap sublayers etc @@ -203,6 +208,17 @@ static CVReturn renderMyNSOpenGLLayer(CVDisplayLinkRef displayLink, pthread_mutex_unlock(&renderLock); } +- (void)releaseLayer +{ + DBG_PRINT("MyNSOpenGLLayer::releaseLayer.0: %p (refcnt %d)\n", self, (int)[self retainCount]); + pthread_mutex_lock(&renderLock); + [self disableAnimation]; + [self deallocTex]; + [self release]; + DBG_PRINT("MyNSOpenGLLayer::releaseLayer.X: %p (refcnt %d)\n", self, (int)[self retainCount]); + pthread_mutex_unlock(&renderLock); +} + - (void)dealloc { DBG_PRINT("MyNSOpenGLLayer::dealloc.0 %p (refcnt %d)\n", self, (int)[self retainCount]); @@ -450,16 +466,15 @@ void setNSOpenGLLayerNeedsDisplay(NSOpenGLLayer* layer) { void releaseNSOpenGLLayer(NSOpenGLLayer* layer) { MyNSOpenGLLayer* l = (MyNSOpenGLLayer*) layer; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - DBG_PRINT("MyNSOpenGLLayer::releaseNSOpenGLLayer.0: %p (refcnt %d)\n", l, (int)[l retainCount]); + DBG_PRINT("MyNSOpenGLLayer::releaseNSOpenGLLayer.0: %p\n", l); - [l performSelectorOnMainThread:@selector(disableAnimation) withObject:nil waitUntilDone:YES]; - // [l disableAnimation]; - - [l performSelectorOnMainThread:@selector(deallocTex) withObject:nil waitUntilDone:YES]; - // [l deallocTex]; + if ( [NSThread isMainThread] == YES ) { + [l releaseLayer]; + } else { + [l performSelectorOnMainThread:@selector(releaseLayer) withObject:nil waitUntilDone:NO]; + } - [l release]; - DBG_PRINT("MyNSOpenGLLayer::releaseNSOpenGLLayer.X: %p (refcnt %d)\n", l, (int)[l retainCount]); + DBG_PRINT("MyNSOpenGLLayer::releaseNSOpenGLLayer.X: %p\n", l); [pool release]; } diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m index 8c04f1774..b5979d53e 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m @@ -603,7 +603,7 @@ Bool deleteContext(NSOpenGLContext* ctx, Bool releaseOnMainThread) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; [ctx clearDrawable]; if(releaseOnMainThread && NO == [NSThread isMainThread]) { - [ctx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES]; + [ctx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO]; } else { // would hangs for ~10s for 1 of a shared context set or offscreen context, set releaseOnMainThread=true ! [ctx release]; -- cgit v1.2.3