aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-03-20 09:02:53 +0100
committerSven Gothel <[email protected]>2012-03-20 09:02:53 +0100
commitb7c5a58f3fd44f87ff3a79410f72260efce7a552 (patch)
treed071492fbdca8be12e74aab571687152a207712c /src/jogl
parentb823e8a0e18ec0b357d62af468a14162a9fb4948 (diff)
Cleanup: Use getThreadName() and validateCurrent() to remove redundancy and to add thread-name info; GLWorkerThread: Use ArrayList and generics.
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java28
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java50
-rw-r--r--src/jogl/classes/jogamp/opengl/GLWorkerThread.java22
3 files changed, 49 insertions, 51 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index f928bc126..41dce0d3b 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -122,6 +122,10 @@ public abstract class GLContext {
private int currentSwapInterval;
protected void resetStates() {
+ if (DEBUG) {
+ System.err.println(getThreadName() + ": GLContext.resetStates()");
+ // Thread.dumpStack();
+ }
ctxMajorVersion=-1;
ctxMinorVersion=-1;
ctxOptions=0;
@@ -260,7 +264,7 @@ public abstract class GLContext {
public static GL getCurrentGL() throws GLException {
GLContext glc = getCurrent();
if(null==glc) {
- throw new GLException("No OpenGL context current on this thread");
+ throw new GLException(getThreadName()+": No OpenGL context current on this thread");
}
return glc.getGL();
}
@@ -288,7 +292,7 @@ public abstract class GLContext {
*/
public final void validateCurrent() throws GLException {
if(getCurrent() != this) {
- throw new GLException("Given GL context not current");
+ throw new GLException(getThreadName()+": This context is not current. Current context: "+getCurrent()+", this context "+this);
}
}
@@ -299,7 +303,7 @@ public abstract class GLContext {
*/
protected static void setCurrent(GLContext cur) {
if(TRACE_SWITCH) {
- System.err.println("GLContext.ContextSwitch: - setCurrent() - "+Thread.currentThread().getName()+": "+cur);
+ System.err.println(getThreadName()+": GLContext.ContextSwitch: - setCurrent() - "+cur);
}
currentContext.set(cur);
}
@@ -624,9 +628,7 @@ public abstract class GLContext {
* @throws GLException if the context is not current.
*/
public final boolean setSwapInterval(int interval) throws GLException {
- if (!isCurrent()) {
- throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
- }
+ validateCurrent();
if(0<=interval) {
if( setSwapIntervalImpl(interval) ) {
currentSwapInterval = interval;
@@ -665,18 +667,13 @@ public abstract class GLContext {
public final boolean queryMaxSwapGroups(int[] maxGroups, int maxGroups_offset,
int[] maxBarriers, int maxBarriers_offset) {
-
- if (!isCurrent()) {
- throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
- }
+ validateCurrent();
return queryMaxSwapGroupsImpl(maxGroups, maxGroups_offset, maxBarriers, maxBarriers_offset);
}
protected boolean queryMaxSwapGroupsImpl(int[] maxGroups, int maxGroups_offset,
int[] maxBarriers, int maxBarriers_offset) { return false; }
public final boolean joinSwapGroup(int group) {
- if (!isCurrent()) {
- throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
- }
+ validateCurrent();
return joinSwapGroupImpl(group);
}
protected boolean joinSwapGroupImpl(int group) { /** nop per default .. **/ return false; }
@@ -685,9 +682,7 @@ public abstract class GLContext {
return currentSwapGroup;
}
public final boolean bindSwapBarrier(int group, int barrier) {
- if (!isCurrent()) {
- throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
- }
+ validateCurrent();
return bindSwapBarrierImpl(group, barrier);
}
protected boolean bindSwapBarrierImpl(int group, int barrier) { /** nop per default .. **/ return false; }
@@ -875,7 +870,6 @@ public abstract class GLContext {
deviceVersionsAvailableSet.add(devKey);
if (DEBUG) {
System.err.println(getThreadName() + ": createContextARB: SET mappedVersionsAvailableSet "+devKey);
- // Thread.dumpStack();
}
}
}
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index d8d9ddf6b..10d478b85 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -140,11 +140,7 @@ import jogamp.opengl.ThreadingImpl;
@SuppressWarnings("serial")
public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosingProtocol, OffscreenLayerOption {
- private static final boolean DEBUG;
-
- static {
- DEBUG = Debug.debug("GLCanvas");
- }
+ private static final boolean DEBUG = Debug.debug("GLCanvas");
private GLDrawableHelper drawableHelper = new GLDrawableHelper();
private AWTGraphicsConfiguration awtConfig;
@@ -330,14 +326,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
final GraphicsConfiguration compatible = (null!=config)?config.getAWTGraphicsConfiguration():null;
boolean equalCaps = config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities());
if(DEBUG) {
- Exception e = new Exception("Info: Call Stack: "+Thread.currentThread().getName());
- e.printStackTrace();
+ System.err.println(getThreadName()+": Info:");
System.err.println("Created Config (n): HAVE GC "+chosen);
System.err.println("Created Config (n): THIS GC "+gc);
System.err.println("Created Config (n): Choosen GC "+compatible);
System.err.println("Created Config (n): HAVE CF "+awtConfig);
System.err.println("Created Config (n): Choosen CF "+config);
System.err.println("Created Config (n): EQUALS CAPS "+equalCaps);
+ Thread.dumpStack();
}
if (compatible != null) {
@@ -412,7 +408,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
public void display() {
if( !validateGLDrawable() ) {
if(DEBUG) {
- System.err.println("Info: GLCanvas display - skipped GL render, drawable not valid yet");
+ System.err.println(getThreadName()+": Info: GLCanvas display - skipped GL render, drawable not valid yet");
}
return; // not yet available ..
}
@@ -427,9 +423,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
try {
final GLAnimatorControl animator = getAnimator();
if(DEBUG) {
- Exception ex1 = new Exception("Info: dispose("+regenerate+") - START, hasContext " +
+ System.err.println(getThreadName()+": Info: dispose("+regenerate+") - START, hasContext " +
(null!=context) + ", hasDrawable " + (null!=drawable)+", "+animator);
- ex1.printStackTrace();
+ Thread.dumpStack();
}
if(null!=context) {
@@ -472,7 +468,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
if(DEBUG) {
- System.err.println("dispose("+regenerate+") - END, "+animator);
+ System.err.println(getThreadName()+": dispose("+regenerate+") - END, "+animator);
}
} finally {
drawableSync.unlock();
@@ -533,8 +529,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
@Override
public void addNotify() {
if(DEBUG) {
- Exception ex1 = new Exception(Thread.currentThread().getName()+" - Info: addNotify - start, bounds: "+this.getBounds());
- ex1.printStackTrace();
+ System.err.println(getThreadName()+": Info: addNotify - start, bounds: "+this.getBounds());
+ Thread.dumpStack();
}
drawableSync.lock();
@@ -570,7 +566,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
// validateGLDrawable();
if(DEBUG) {
- System.err.println(Thread.currentThread().getName()+" - Info: addNotify - end: peer: "+getPeer());
+ System.err.println(getThreadName()+": Info: addNotify - end: peer: "+getPeer());
}
} finally {
drawableSync.unlock();
@@ -604,10 +600,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
realized = true;
sendReshape=true; // ensure a reshape is being send ..
if(DEBUG) {
- String msg = Thread.currentThread().getName()+" - Realized Drawable: "+drawable.toString();
- // System.err.println(msg);
- Throwable t = new Throwable(msg);
- t.printStackTrace();
+ System.err.println(getThreadName()+": Realized Drawable: "+drawable.toString());
+ Thread.dumpStack();
}
}
}
@@ -630,8 +624,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
@Override
public void removeNotify() {
if(DEBUG) {
- Exception ex1 = new Exception(Thread.currentThread().getName()+" - Info: removeNotify - start");
- ex1.printStackTrace();
+ System.err.println(getThreadName()+": Info: removeNotify - start");
+ Thread.dumpStack();
}
awtWindowClosingProtocol.removeClosingListener();
@@ -651,7 +645,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
}
if(DEBUG) {
- System.err.println(Thread.currentThread().getName()+" - Info: removeNotify - end, peer: "+getPeer());
+ System.err.println(getThreadName()+": Info: removeNotify - end, peer: "+getPeer());
}
}
@@ -853,7 +847,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
createDrawableAndContext();
if(DEBUG) {
- System.err.println("GLCanvas.dispose(true): new drawable: "+drawable);
+ System.err.println(getThreadName()+": GLCanvas.dispose(true): new drawable: "+drawable);
}
validateGLDrawable(); // immediate attempt to recreate the drawable
}
@@ -884,7 +878,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
boolean closed = adevice.close();
if(DEBUG) {
- System.err.println(Thread.currentThread().getName() + " - GLCanvas.dispose(false): closed GraphicsDevice: "+adeviceMsg+", result: "+closed);
+ System.err.println(getThreadName()+": GLCanvas.dispose(false): closed GraphicsDevice: "+adeviceMsg+", result: "+closed);
}
awtConfig=null;
}
@@ -923,7 +917,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
public void run() {
if (sendReshape) {
if(DEBUG) {
- System.err.println(Thread.currentThread().getName()+" - reshape: "+getWidth()+"x"+getHeight());
+ System.err.println(getThreadName()+": Reshape: "+getWidth()+"x"+getHeight());
}
// Note: we ignore the given x and y within the parent component
// since we are drawing directly into this heavyweight component.
@@ -994,7 +988,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
disableBackgroundEraseInitialized = true;
if(DEBUG) {
- System.err.println("GLCanvas: TK disableBackgroundErase method found: "+
+ System.err.println(getThreadName()+": GLCanvas: TK disableBackgroundErase method found: "+
(null!=disableBackgroundEraseMethod));
}
}
@@ -1006,7 +1000,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
t = e;
}
if(DEBUG) {
- System.err.println("GLCanvas: TK disableBackgroundErase error: "+t);
+ System.err.println(getThreadName()+": GLCanvas: TK disableBackgroundErase error: "+t);
}
}
}
@@ -1069,6 +1063,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
return config;
}
+ protected static String getThreadName() {
+ return Thread.currentThread().getName();
+ }
+
/**
* A most simple JOGL AWT test entry
*/
diff --git a/src/jogl/classes/jogamp/opengl/GLWorkerThread.java b/src/jogl/classes/jogamp/opengl/GLWorkerThread.java
index ac9655fbb..e717ec64c 100644
--- a/src/jogl/classes/jogamp/opengl/GLWorkerThread.java
+++ b/src/jogl/classes/jogamp/opengl/GLWorkerThread.java
@@ -40,8 +40,10 @@
package jogamp.opengl;
import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-import javax.media.opengl.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.media.opengl.GLContext;
/** Singleton thread upon which all OpenGL work is performed by
default. Unfortunately many vendors' OpenGL drivers are not really
@@ -64,7 +66,7 @@ public class GLWorkerThread {
// The Runnable to execute immediately on the worker thread
private static volatile Runnable work;
// Queue of Runnables to be asynchronously invoked
- private static List queue = new LinkedList();
+ private static List<Runnable> queue = new ArrayList<Runnable>();
/** Should only be called by Threading class if creation of the
GLWorkerThread was requested via the opengl.1thread system
@@ -141,7 +143,7 @@ public class GLWorkerThread {
*/
} else {
- throw new RuntimeException("Should not start GLWorkerThread twice");
+ throw new RuntimeException(getThreadName()+": Should not start GLWorkerThread twice");
}
}
}
@@ -150,7 +152,7 @@ public class GLWorkerThread {
public static void invokeAndWait(Runnable runnable)
throws InvocationTargetException, InterruptedException {
if (!started) {
- throw new RuntimeException("May not invokeAndWait on worker thread without starting it first");
+ throw new RuntimeException(getThreadName()+": May not invokeAndWait on worker thread without starting it first");
}
Object lockTemp = lock;
@@ -177,7 +179,7 @@ public class GLWorkerThread {
public static void invokeLater(Runnable runnable) {
if (!started) {
- throw new RuntimeException("May not invokeLater on worker thread without starting it first");
+ throw new RuntimeException(getThreadName()+": May not invokeLater on worker thread without starting it first");
}
Object lockTemp = lock;
@@ -208,6 +210,10 @@ public class GLWorkerThread {
return (Thread.currentThread() == thread);
}
+ protected static String getThreadName() {
+ return Thread.currentThread().getName();
+ }
+
static class WorkerRunnable implements Runnable {
public void run() {
// Notify starting thread that we're ready
@@ -252,10 +258,10 @@ public class GLWorkerThread {
while (!queue.isEmpty()) {
try {
- Runnable curAsync = (Runnable) queue.remove(0);
+ Runnable curAsync = queue.remove(0);
curAsync.run();
} catch (Throwable t) {
- System.err.println("Exception occurred on JOGL OpenGL worker thread:");
+ System.err.println(getThreadName()+": Exception occurred on JOGL OpenGL worker thread:");
t.printStackTrace();
}
}