diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util')
3 files changed, 67 insertions, 40 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java index e3aff61c6..9dd58bb57 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java @@ -55,29 +55,36 @@ class AWTAnimatorImpl extends AnimatorImpl { public void display(AnimatorBase animator, boolean ignoreExceptions, boolean printExceptions) { - Iterator iter = animator.drawableIterator(); - while (animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && iter.hasNext()) { - GLAutoDrawable drawable = (GLAutoDrawable) iter.next(); - if (drawable instanceof JComponent) { - // Lightweight components need a more efficient drawing - // scheme than simply forcing repainting of each one in - // turn since drawing one can force another one to be - // drawn in turn - lightweights.add(drawable); - } else { - try { - drawable.display(); - } catch (RuntimeException e) { - if (ignoreExceptions) { - if (printExceptions) { - e.printStackTrace(); + List drawables = animator.acquireDrawables(); + try { + for (int i=0; + animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && i<drawables.size(); + i++) { + GLAutoDrawable drawable = (GLAutoDrawable) drawables.get(i); + if (drawable instanceof JComponent) { + // Lightweight components need a more efficient drawing + // scheme than simply forcing repainting of each one in + // turn since drawing one can force another one to be + // drawn in turn + lightweights.add(drawable); + } else { + try { + drawable.display(); + } catch (RuntimeException e) { + if (ignoreExceptions) { + if (printExceptions) { + e.printStackTrace(); + } + } else { + throw(e); } - } else { - throw(e); } } } + } finally { + animator.releaseDrawables(); } + if (lightweights.size() > 0) { try { SwingUtilities.invokeAndWait(drawWithRepaintManagerRunnable); diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java index a54f6be57..24eee1875 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java @@ -28,9 +28,11 @@ package com.jogamp.opengl.util; +import com.jogamp.common.util.locks.RecursiveLock; import com.jogamp.opengl.impl.Debug; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLProfile; @@ -43,7 +45,8 @@ public abstract class AnimatorBase implements GLAnimatorControl { private static int animatorCount = 0; - protected volatile ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList(); + protected ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList(); + protected RecursiveLock drawablesLock = new RecursiveLock(); protected AnimatorImpl impl; protected String baseName; protected Thread thread; @@ -75,18 +78,24 @@ public abstract class AnimatorBase implements GLAnimatorControl { protected abstract String getBaseName(String prefix); public synchronized void add(GLAutoDrawable drawable) { - ArrayList newList = (ArrayList) drawables.clone(); - newList.add(drawable); - drawables = newList; - drawable.setAnimator(this); + drawablesLock.lock(); + try { + drawables.add(drawable); + drawable.setAnimator(this); + } finally { + drawablesLock.unlock(); + } notifyAll(); } public synchronized void remove(GLAutoDrawable drawable) { - ArrayList newList = (ArrayList) drawables.clone(); - newList.remove(drawable); - drawables = newList; - drawable.setAnimator(null); + drawablesLock.lock(); + try { + drawables.remove(drawable); + drawable.setAnimator(null); + } finally { + drawablesLock.unlock(); + } notifyAll(); } @@ -101,8 +110,13 @@ public abstract class AnimatorBase implements GLAnimatorControl { totalFrames++; } - public Iterator drawableIterator() { - return drawables.iterator(); + public List acquireDrawables() { + drawablesLock.lock(); + return drawables; + } + + public void releaseDrawables() { + drawablesLock.unlock(); } public long getCurrentTime() { diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java index e4bf8d711..8f2715e0a 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java @@ -44,20 +44,26 @@ class AnimatorImpl { public void display(AnimatorBase animator, boolean ignoreExceptions, boolean printExceptions) { - Iterator iter = animator.drawableIterator(); - while (animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && iter.hasNext()) { - GLAutoDrawable drawable = (GLAutoDrawable) iter.next(); - try { - drawable.display(); - } catch (RuntimeException e) { - if (ignoreExceptions) { - if (printExceptions) { - e.printStackTrace(); + List drawables = animator.acquireDrawables(); + try { + for (int i=0; + animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && i<drawables.size(); + i++) { + GLAutoDrawable drawable = (GLAutoDrawable) drawables.get(i); + try { + drawable.display(); + } catch (RuntimeException e) { + if (ignoreExceptions) { + if (printExceptions) { + e.printStackTrace(); + } + } else { + throw(e); } - } else { - throw(e); } } + } finally { + animator.releaseDrawables(); } } |