From 36887db6c983244917802f3ec761a0d28171887a Mon Sep 17 00:00:00 2001
From: Kenneth Russel <kbrussel@alum.mit.edu>
Date: Tue, 21 Feb 2006 09:43:43 +0000
Subject: Added optimized path to GLDrawableHelper for situation where
 GLWorkerThread is being used; last context made current on that thread is
 left current on that thread. In the case where only a single OpenGL context
 is in use this eliminates the repeated calls to makeCurrent. Ran into same
 NVidia driver bug causing crashes upon exit with Java2D/OpenGL pipeline.
 Added workaround to GLDrawableHelper which can be enabled with
 -Djogl.nvidia.crash.workaround, which just disables this optimization. Fixed
 GLCanvas and GLPbufferImpl's destruction paths to behave correctly in the
 face of the context being left current on the GLWorkerThread. Updated code in
 Threading related to GLWorkerThread to interoperate better with Java2D/OpenGL
 pipeline.

git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@629 232f8b59-042b-4e1e-8c03-345bb8c30851
---
 src/classes/javax/media/opengl/GLCanvas.java  | 29 ++++++++++++++++++++++-----
 src/classes/javax/media/opengl/Threading.java | 12 ++++++++++-
 2 files changed, 35 insertions(+), 6 deletions(-)

(limited to 'src/classes/javax/media')

diff --git a/src/classes/javax/media/opengl/GLCanvas.java b/src/classes/javax/media/opengl/GLCanvas.java
index 0329e4017..d555a1df0 100644
--- a/src/classes/javax/media/opengl/GLCanvas.java
+++ b/src/classes/javax/media/opengl/GLCanvas.java
@@ -166,11 +166,19 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
       <B>Overrides:</B>
       <DL><DD><CODE>removeNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */
   public void removeNotify() {
-    context.destroy();
-    drawable.setRealized(false);
-    super.removeNotify();
-    if (DEBUG) {
-      System.err.println("GLCanvas.removeNotify()");
+    try {
+      if (Threading.isSingleThreaded() &&
+          !Threading.isOpenGLThread()) {
+        Threading.invokeOnOpenGLThread(destroyAction);
+      } else {
+        context.destroy();
+      }
+    } finally {
+      drawable.setRealized(false);
+      super.removeNotify();
+      if (DEBUG) {
+        System.err.println("GLCanvas.removeNotify()");
+      }
     }
   }
 
@@ -289,6 +297,17 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
   private SwapBuffersOnEventDispatchThreadAction swapBuffersOnEventDispatchThreadAction =
     new SwapBuffersOnEventDispatchThreadAction();
 
+  class DestroyAction implements Runnable {
+    public void run() {
+      GLContext current = GLContext.getCurrent();
+      if (current == context) {
+        context.release();
+      }
+      context.destroy();
+    }
+  }
+  private DestroyAction destroyAction = new DestroyAction();
+
   // Disables the AWT's erasing of this Canvas's background on Windows
   // in Java SE 6. This internal API is not available in previous
   // releases, but the system property
diff --git a/src/classes/javax/media/opengl/Threading.java b/src/classes/javax/media/opengl/Threading.java
index 7aa57def5..f8d54d95d 100755
--- a/src/classes/javax/media/opengl/Threading.java
+++ b/src/classes/javax/media/opengl/Threading.java
@@ -197,7 +197,17 @@ public class Threading {
           return EventQueue.isDispatchThread();
         }
       case WORKER:
-        return GLWorkerThread.isWorkerThread();
+        if (Java2D.isOGLPipelineActive()) {
+          // FIXME: ideally only the QFT would be considered to be the
+          // "OpenGL thread", but we can not currently run all of JOGL's
+          // OpenGL work on that thread. For now, run the GLJPanel's
+          // Java2D/JOGL bridge on the QFT but everything else on the
+          // worker thread, except when we're already on the QFT.
+          return (Java2D.isQueueFlusherThread() ||
+                  GLWorkerThread.isWorkerThread());
+        } else {
+          return GLWorkerThread.isWorkerThread();
+        }
       default:
         throw new InternalError("Illegal single-threading mode " + mode);
     }
-- 
cgit v1.2.3