From 3ed491213f8f7f05d7b9866b50d764370d8ff5f6 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sun, 25 Mar 2012 03:29:53 +0200
Subject: Enhance and generalize AWT Threading* implementation; Minor changes
 ..

Threading*:
  - add invoke(..) generalizing the Therading decision

GLCanvas:
  - remove 'manual' Threading decision, simply call Threading.invoke(..)
  - use anonymous Runnable instances
  - remove drawable lock, drawable is volatile instead

GLJPanel:
  - remove 'manual' Threading decision, simply call Threading.invoke(..)
  - use anonymous Runnable instances
  - DEBUG: Use getThreadName() prefix

GLContextImpl:
  - Remove GLWorkerThread idle command on makeCurrent(),
    no holding of context in worker thread while idle.
  - DEBUG: Use getThreadName() prefix

X11GLXContext:
  - DEBUG: Use getThreadName() prefix

TODO: Validate whether it's OK for GLCanvas and GLJPanel to set Threading.Mode.MT as the default mode!
---
 .../jogamp/opengl/awt/AWTThreadingPlugin.java      | 41 +++++++++++++---------
 1 file changed, 24 insertions(+), 17 deletions(-)

(limited to 'src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java')

diff --git a/src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java b/src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java
index 901146fc4..73b7d197d 100644
--- a/src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java
+++ b/src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java
@@ -40,18 +40,24 @@
 
 package jogamp.opengl.awt;
 
-import javax.media.opengl.*;
-
 import java.awt.EventQueue;
 import java.lang.reflect.InvocationTargetException;
 
-import jogamp.opengl.*;
+import javax.media.opengl.GLException;
+
+import jogamp.opengl.GLWorkerThread;
+import jogamp.opengl.ThreadingImpl;
+import jogamp.opengl.ToolkitThreadingPlugin;
 
-public class AWTThreadingPlugin implements ThreadingPlugin {
+public class AWTThreadingPlugin implements ToolkitThreadingPlugin {
 
   public AWTThreadingPlugin() {}
 
-  public boolean isOpenGLThread() throws GLException {
+  public final boolean isToolkitThread() throws GLException {
+      return EventQueue.isDispatchThread();
+  }
+  
+  public final boolean isOpenGLThread() throws GLException {
     switch (ThreadingImpl.getMode()) {
       case ST_AWT:
         // FIXME: See the FIXME below in 'invokeOnOpenGLThread'
@@ -76,7 +82,7 @@ public class AWTThreadingPlugin implements ThreadingPlugin {
     }
   }
 
-  public void invokeOnOpenGLThread(Runnable r) throws GLException {
+  public final void invokeOnOpenGLThread(boolean wait, Runnable r) throws GLException {
     switch (ThreadingImpl.getMode()) {
       case ST_AWT:
         // FIXME: ideally should run all OpenGL work on the Java2D QFT
@@ -87,11 +93,19 @@ public class AWTThreadingPlugin implements ThreadingPlugin {
         // implementation, which attempts to grab the AWT lock on the
         // QFT which is not allowed. For now, on X11 platforms,
         // continue to perform this work on the EDT.
-        if (Java2D.isOGLPipelineActive() && !ThreadingImpl.isX11()) {
-          Java2D.invokeWithOGLContextCurrent(null, r);
+        if (wait && Java2D.isOGLPipelineActive() && !ThreadingImpl.isX11()) {
+          if(wait) {
+              Java2D.invokeWithOGLContextCurrent(null, r);
+          } else {
+              
+          }
         } else {
           try {
-            EventQueue.invokeAndWait(r);
+            if(wait) {
+                EventQueue.invokeAndWait(r);
+            } else {
+                EventQueue.invokeLater(r);
+            }
           } catch (InvocationTargetException e) {
             throw new GLException(e.getTargetException());
           } catch (InterruptedException e) {
@@ -101,14 +115,7 @@ public class AWTThreadingPlugin implements ThreadingPlugin {
         break;
 
       case ST_WORKER:
-        GLWorkerThread.start(); // singleton start via volatile-dbl-checked-locking
-        try {
-          GLWorkerThread.invokeAndWait(r);
-        } catch (InvocationTargetException e) {
-          throw new GLException(e.getTargetException());
-        } catch (InterruptedException e) {
-          throw new GLException(e);
-        }
+        ThreadingImpl.invokeOnWorkerThread(wait, r);
         break;
 
       default:
-- 
cgit v1.2.3