summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-11-23 06:02:36 +0100
committerSven Gothel <[email protected]>2010-11-23 06:02:36 +0100
commitfc7dd718b88877435a1a30d59e996651fa57a80a (patch)
treec602b1b15da85b64e8b6e3fa26efbdc7f4703532 /src/jogl/classes/com/jogamp
parentdec9bd072b8de0669e6fac48b2ca144bbaaad5fc (diff)
AnimatorBase: add()/remove() - decorate change of drawables with pause()/resume() so it becomes a non critical to multithreading, hence display() or state change needs to be synced
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
index 65d6745ed..96cfe6562 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
@@ -92,18 +92,13 @@ public abstract class AnimatorBase implements GLAnimatorControl {
if(DEBUG) {
System.err.println("Animator add: "+drawable.hashCode()+" - "+Thread.currentThread());
}
- // drawables list may be in use by display
- stateSync.lock();
- try {
- ArrayList newDrawables = (ArrayList) drawables.clone();
- newDrawables.add(drawable);
- drawables = newDrawables;
- drawablesEmpty = drawables.size() == 0;
- drawable.setAnimator(this);
- } finally {
- stateSync.unlock();
+ boolean paused = pause();
+ drawables.add(drawable);
+ drawablesEmpty = drawables.size() == 0;
+ drawable.setAnimator(this);
+ if(paused) {
+ resume();
}
- notifyAll();
if(!impl.skipWaitForCompletion(animThread)) {
while(isStarted() && !isPaused() && !isAnimating()) {
try {
@@ -111,6 +106,7 @@ public abstract class AnimatorBase implements GLAnimatorControl {
} catch (InterruptedException ie) { }
}
}
+ notifyAll();
}
public synchronized void remove(GLAutoDrawable drawable) {
@@ -118,18 +114,13 @@ public abstract class AnimatorBase implements GLAnimatorControl {
System.err.println("Animator remove: "+drawable.hashCode()+" - "+Thread.currentThread());
}
- // drawables list may be in use by display
- stateSync.lock();
- try {
- ArrayList newDrawables = (ArrayList) drawables.clone();
- newDrawables.remove(drawable);
- drawables = newDrawables;
- drawablesEmpty = drawables.size() == 0;
- drawable.setAnimator(null);
- } finally {
- stateSync.unlock();
+ boolean paused = pause();
+ drawables.remove(drawable);
+ drawablesEmpty = drawables.size() == 0;
+ drawable.setAnimator(null);
+ if(paused) {
+ resume();
}
- notifyAll();
if(!impl.skipWaitForCompletion(animThread)) {
while(isStarted() && drawablesEmpty && isAnimating()) {
try {
@@ -137,6 +128,7 @@ public abstract class AnimatorBase implements GLAnimatorControl {
} catch (InterruptedException ie) { }
}
}
+ notifyAll();
}
/** Called every frame to cause redrawing of all of the
@@ -145,14 +137,7 @@ public abstract class AnimatorBase implements GLAnimatorControl {
components this Animator manages, in particular when multiple
lightweight widgets are continually being redrawn. */
protected void display() {
- ArrayList dl;
- stateSync.lock();
- try {
- dl = drawables;
- } finally {
- stateSync.unlock();
- }
- impl.display(dl, ignoreExceptions, printExceptions);
+ impl.display(drawables, ignoreExceptions, printExceptions);
curTime = System.currentTimeMillis();
totalFrames++;
}