From 5d33b0a3ef993ff2d257c90abc3d84bc93269cd0 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Thu, 13 Oct 2011 13:02:32 +0200
Subject: MacOSX: Fix shared ctx release [onMainThread]; Make GLContextShareSet
 lifecycle deterministic; Remove warnings

Fix shared ctx release [onMainThread]
  - Releasing the shared contexts caused a freeze of about 10s from one of the shared release operations.
    [NSOpenGLContext release]
  - Thorough triage concluded the workaround to release the shared ctx on the main thread.
  - Using enhanced GLContextShareSet, see below

Make GLContextShareSet lifecycle deterministic
  - Programmatically control the lifecycle of tracked shared ctx allows us using 'hard' references.
  - Features queries for isShared() and ofc unregister a share set if all are destroyed.

Remove warnings
  - MacOSXWindowSystemInterface.m used 'long', where 'GLint' was requested.
---
 .../native/macosx/MacOSXWindowSystemInterface.m    | 90 +++++++++++-----------
 1 file changed, 47 insertions(+), 43 deletions(-)

(limited to 'src/jogl/native/macosx/MacOSXWindowSystemInterface.m')

diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
index aab70791c..1eb3da96c 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
@@ -44,50 +44,50 @@
 
 struct _RendererInfo
 {
-    long id;                // kCGLRPRendererID
-    long displayMask;        // kCGLRPDisplayMask
+    GLint id;                // kCGLRPRendererID
+    GLint displayMask;        // kCGLRPDisplayMask
     
-    long accelerated;        // kCGLRPAccelerated
+    GLint accelerated;        // kCGLRPAccelerated
     
-    long window;            // kCGLRPWindow
-    long fullscreen;        // kCGLRPFullScreen
-    long multiscreen;        // kCGLRPMultiScreen
-    long offscreen;            // kCGLRPOffScreen
-    long floatPixels;        // see kCGLRPColorModes
-    long stereo;            // kCGLRPBufferModes
+    GLint window;            // kCGLRPWindow
+    GLint fullscreen;        // kCGLRPFullScreen
+    GLint multiscreen;        // kCGLRPMultiScreen
+    GLint offscreen;            // kCGLRPOffScreen
+    GLint floatPixels;        // see kCGLRPColorModes
+    GLint stereo;            // kCGLRPBufferModes
     
-    long auxBuffers;        // kCGLRPMaxAuxBuffers
-    long sampleBuffers;        // kCGLRPMaxSampleBuffers
-    long samples;            // kCGLRPMaxSamples
-    long samplesModes;        // kCGLRPSampleModes
-    long multiSample;        // see kCGLRPSampleModes
-    long superSample;        // see kCGLRPSampleModes
-    long alphaSample;        // kCGLRPSampleAlpha
+    GLint auxBuffers;        // kCGLRPMaxAuxBuffers
+    GLint sampleBuffers;        // kCGLRPMaxSampleBuffers
+    GLint samples;            // kCGLRPMaxSamples
+    GLint samplesModes;        // kCGLRPSampleModes
+    GLint multiSample;        // see kCGLRPSampleModes
+    GLint superSample;        // see kCGLRPSampleModes
+    GLint alphaSample;        // kCGLRPSampleAlpha
     
-    long colorModes;        // kCGLRPColorModes
-    long colorRGBSizeMAX;
-    long colorASizeMAX;
-    long colorFloatRGBSizeMAX;
-    long colorFloatASizeMAX;
-    long colorFloatRGBSizeMIN;
-    long colorFloatASizeMIN;
-    long colorModesCount;
-    long colorFloatModesCount;
-    long depthModes;        // kCGLRPDepthModes
-    long depthSizeMAX;
-    long depthModesCount;
-    long stencilModes;        // kCGLRPStencilModes
-    long stencilSizeMAX;
-    long stencilModesCount;
-    long accumModes;        // kCGLRPAccumModes
-    long accumRGBSizeMAX;
-    long accumASizeMAX;
-    long accumModesCount;
+    GLint colorModes;        // kCGLRPColorModes
+    GLint colorRGBSizeMAX;
+    GLint colorASizeMAX;
+    GLint colorFloatRGBSizeMAX;
+    GLint colorFloatASizeMAX;
+    GLint colorFloatRGBSizeMIN;
+    GLint colorFloatASizeMIN;
+    GLint colorModesCount;
+    GLint colorFloatModesCount;
+    GLint depthModes;        // kCGLRPDepthModes
+    GLint depthSizeMAX;
+    GLint depthModesCount;
+    GLint stencilModes;        // kCGLRPStencilModes
+    GLint stencilSizeMAX;
+    GLint stencilModesCount;
+    GLint accumModes;        // kCGLRPAccumModes
+    GLint accumRGBSizeMAX;
+    GLint accumASizeMAX;
+    GLint accumModesCount;
 }
 typedef RendererInfo;
 
 RendererInfo *gRenderers = NULL;
-long gRenderersCount = 0;
+GLint gRenderersCount = 0;
 
 long depthModes[] = {
                     kCGL0Bit,
@@ -446,9 +446,9 @@ void* createPixelFormat(int* iattrs, int niattrs, int* ivalues) {
 void queryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues) {
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
   NSOpenGLPixelFormat* fmt = (NSOpenGLPixelFormat*) pixelFormat;
-  long tmp;
+  GLint tmp;
   // FIXME: think about how specifying this might affect the API
-  int virtualScreen = 0;
+  GLint virtualScreen = 0;
 
   int i;
   for (i = 0; i < niattrs && iattrs[i]>0; i++) {
@@ -522,7 +522,7 @@ void* createContext(void* shareContext,
         if (nsContext != nil) {
           if (nsView != nil) {
             if(!opaque) {
-                long zeroOpacity = 0;
+                GLint zeroOpacity = 0;
                 [nsContext setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity];
             }
             [nsContext setView:nsView];
@@ -585,13 +585,17 @@ Bool clearCurrentContext(void* nsJContext) {
   return true;
 }
 
-Bool deleteContext(void* nsJContext) {
+Bool deleteContext(void* nsJContext, Bool releaseOnMainThread) {
   NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
     
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
   [nsContext clearDrawable];
-  // [nsContext release]; // FIXME: JAU: freezes for a few seconds if ctx is shared
-  // [nsContext dealloc];
+  if(releaseOnMainThread) {
+      [nsContext performSelectorOnMainThread:@selector(release:) withObject:nil waitUntilDone:YES];
+  } else {
+      // would hangs for ~10s for 1 of the shared context, set releaseOnMainThread=true !
+      [nsContext release]; 
+  }
   [pool release];
   return true;
 }
@@ -736,7 +740,7 @@ void* getProcAddress(const char *procname) {
 
 void setSwapInterval(void* nsJContext, int interval) {
   NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-  long swapInterval = interval;
+  GLint swapInterval = interval;
   [nsContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
 }
 
-- 
cgit v1.2.3