From 8c78f80f205345fe43ec2639e648421ef0134e57 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Mon, 5 Nov 2012 05:02:38 +0100
Subject: GLAutoDrawable: Refine API change of commit
c002e04f848116922a1ed7bd96ead54961649bbd
As suggested by Julien Gouesse, align 'enqueue(..)' method w/ 'invoke(..)':
- public void enqueue(GLRunnable glRunnable);
+ public boolean invoke(boolean wait, List glRunnables);
---
make/scripts/tests.sh | 4 +-
.../classes/com/jogamp/opengl/swt/GLCanvas.java | 12 +++---
.../com/jogamp/opengl/util/GLDrawableUtil.java | 35 ++++++++--------
.../classes/javax/media/opengl/GLAutoDrawable.java | 32 +++++----------
.../classes/javax/media/opengl/awt/GLCanvas.java | 5 ++-
.../classes/javax/media/opengl/awt/GLJPanel.java | 5 ++-
.../classes/jogamp/opengl/GLAutoDrawableBase.java | 5 ++-
.../classes/jogamp/opengl/GLDrawableHelper.java | 47 +++++++++++++++++++++-
.../acore/TestGLContextDrawableSwitchNEWT.java | 8 ++--
9 files changed, 96 insertions(+), 57 deletions(-)
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index cc9a330a5..3221deaab 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -267,7 +267,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES1NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableDelegateOnOffscrnCapsNEWT $*
-#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLContextDrawableSwitchNEWT $*
+testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLContextDrawableSwitchNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestPointsNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT $*
@@ -352,7 +352,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestAWTCardLayoutAnimatorStartStopBug532 $*
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasAWTActionDeadlock00AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasAWTActionDeadlock01AWT $*
-testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasAWTActionDeadlock02AWT $*
+#testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasAWTActionDeadlock02AWT $*
#
# swt (testswt)
diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
index ea794cc78..755a7c392 100644
--- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
+++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
@@ -27,6 +27,8 @@
*/
package com.jogamp.opengl.swt;
+import java.util.List;
+
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.ProxySurface;
@@ -545,15 +547,15 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
}
@Override
- public boolean invoke(final boolean wait, final GLRunnable run) {
- return helper.invoke(this, wait, run);
+ public boolean invoke(final boolean wait, final GLRunnable runnable) {
+ return helper.invoke(this, wait, runnable);
}
@Override
- public void enqueue(GLRunnable glRunnable) {
- helper.enqueue(glRunnable);
+ public boolean invoke(final boolean wait, final List runnables) {
+ return helper.invoke(this, wait, runnables);
}
-
+
@Override
public void setAnimator(final GLAnimatorControl arg0) throws GLException {
helper.setAnimator(arg0);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java b/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java
index 08eaf0494..cc81e4820 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java
@@ -27,6 +27,9 @@
*/
package com.jogamp.opengl.util;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLContext;
@@ -80,7 +83,7 @@ public class GLDrawableUtil {
dest.addGLEventListener(listener);
if(preserveInitState && initialized) {
dest.setGLEventListenerInitState(listener, true);
- dest.enqueue(new ReshapeGLEventListener(listener));
+ dest.invoke(false, new ReshapeGLEventListener(listener));
} // else .. !init state is default
}
@@ -118,6 +121,8 @@ public class GLDrawableUtil {
* @param b
*/
public static final void swapGLContextAndAllGLEventListener(GLAutoDrawable a, GLAutoDrawable b) {
+ final List aGLCmds = new ArrayList();
+ final List bGLCmds = new ArrayList();
final GLAnimatorControl aAnim = a.getAnimator();
final GLAnimatorControl bAnim = b.getAnimator();
final boolean aIsPaused = isAnimatorAnimatingOnOtherThread(aAnim) && aAnim.pause();
@@ -146,32 +151,30 @@ public class GLDrawableUtil {
//
// trigger glFinish to sync GL ctx
//
- a.enqueue(glFinish);
- b.enqueue(glFinish);
- a.display();
- b.display();
+ a.invoke(true, glFinish);
+ b.invoke(true, glFinish);
//
// switch context and
// trigger GL-Viewport reset and reshape of all initialized GLEventListeners
//
b.setContext( a.setContext( b.getContext() ) );
- a.enqueue(setViewport);
- b.enqueue(setViewport);
+ aGLCmds.add(setViewport);
+ bGLCmds.add(setViewport);
for(int i=0; i
- * Unlike the {@link #invoke(boolean, GLRunnable)}, this method only enqueues the {@link GLRunnable}
- * w/o taking care of it's execution. Hence either a performing {@link GLAnimatorControl animator}
- * or explicit user call shall trigger {@link #display()} to ensure it's execution.
- *
- *
- * Method return immediately w/o waiting or blocking
- *
- *
- * @param glRunnable the {@link GLRunnable} to execute within the next {@link #display()} call
- *
- * @see #invoke(boolean, GLRunnable)
- * @see #display()
- * @see GLRunnable
+ * Extends {@link #invoke(boolean, GLRunnable)} functionality
+ * allowing to inject a list of {@link GLRunnable}s.
+ * @param wait if true
block until execution of the last glRunnable
is finished, otherwise return immediately w/o waiting
+ * @param glRunnables the {@link GLRunnable}s to execute within {@link #display()}
+ * @return true
if the {@link GLRunnable}s has been processed or queued, otherwise false
.
*/
- public void enqueue(GLRunnable glRunnable);
-
+ public boolean invoke(boolean wait, List glRunnables);
+
/** Destroys all resources associated with this GLAutoDrawable,
inclusive the GLContext.
If a window is attached to it's implementation, it shall be closed.
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index 5b5f800a4..1d8666e6a 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -57,6 +57,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.EventQueue;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.List;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.OffscreenLayerOption;
@@ -746,8 +747,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
@Override
- public void enqueue(GLRunnable glRunnable) {
- helper.enqueue(glRunnable);
+ public boolean invoke(final boolean wait, final List glRunnables) {
+ return helper.invoke(this, wait, glRunnables);
}
@Override
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index 08d70211b..58b1baa65 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -54,6 +54,7 @@ import java.awt.image.DataBufferInt;
import java.beans.Beans;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
+import java.util.List;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
@@ -483,8 +484,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
@Override
- public void enqueue(GLRunnable glRunnable) {
- helper.enqueue(glRunnable);
+ public boolean invoke(final boolean wait, final List glRunnables) {
+ return helper.invoke(this, wait, glRunnables);
}
@Override
diff --git a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
index 09a754279..7bcd37ecd 100644
--- a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
+++ b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
@@ -29,6 +29,7 @@
package jogamp.opengl;
import java.io.PrintStream;
+import java.util.List;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
@@ -412,8 +413,8 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter {
}
@Override
- public final void enqueue(GLRunnable glRunnable) {
- helper.enqueue(glRunnable);
+ public boolean invoke(final boolean wait, final List glRunnables) {
+ return helper.invoke(this, wait, glRunnables);
}
@Override
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
index d891ae810..be63c9278 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
@@ -41,6 +41,7 @@
package jogamp.opengl;
import java.util.ArrayList;
+import java.util.List;
import java.util.HashSet;
import javax.media.nativewindow.NativeSurface;
@@ -691,9 +692,9 @@ public class GLDrawableHelper {
return false;
}
- Throwable throwable = null;
GLRunnableTask rTask = null;
Object rTaskLock = new Object();
+ Throwable throwable = null;
synchronized(rTaskLock) {
final boolean deferred;
synchronized(glRunnablesLock) {
@@ -724,6 +725,50 @@ public class GLDrawableHelper {
}
return true;
}
+
+ public final boolean invoke(GLAutoDrawable drawable, boolean wait, List newGLRunnables) {
+ if( null == newGLRunnables || newGLRunnables.size() == 0 || null == drawable ||
+ wait && ( !drawable.isRealized() || null==drawable.getContext() ) ) {
+ return false;
+ }
+
+ final int count = newGLRunnables.size();
+ GLRunnableTask rTask = null;
+ Object rTaskLock = new Object();
+ Throwable throwable = null;
+ synchronized(rTaskLock) {
+ final boolean deferred;
+ synchronized(glRunnablesLock) {
+ deferred = isAnimatorAnimatingOnOtherThread();
+ if(!deferred) {
+ wait = false; // don't wait if exec immediatly
+ }
+ for(int i=0; i