Top Description Inners Fields Constructors Methods
com.jogamp.opengl.util

public abstract Class AnimatorBase

extends Object
implements GLAnimatorControl
Class Inheritance
All Implemented Interfaces
com.jogamp.opengl.GLAnimatorControl, com.jogamp.opengl.FPSCounter
Known Direct Subclasses
com.jogamp.opengl.util.FPSAnimator, com.jogamp.opengl.util.Animator
Imports
jogamp.opengl.Debug, .FPSCounterImpl, java.io.PrintStream, java.util.ArrayList, com.jogamp.opengl.GLAnimatorControl, .GLAutoDrawable, .GLException, .GLProfile, com.jogamp.common.ExceptionUtils, com.jogamp.common.util.InterruptedRuntimeException

Base implementation of GLAnimatorControl

The change synchronization is done via synchronized blocks on the AnimatorBase instance.
Status get / set activity is synced with a RecursiveLock, used as a memory barrier.
This is suitable, since all change requests are allowed to be expensive as they are not expected to be called at every frame.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
protected static interface
public static class

Field Summary

Modifier and TypeField and Description
protected Thread
private static final Class<?>
protected String
protected static final boolean
protected ArrayList<GLAutoDrawable>
protected boolean
protected boolean
protected FPSCounterImpl
protected boolean
protected AnimatorBase.AnimatorImpl
public static final int
MODE_EXPECT_AWT_RENDERING_THREAD

If present in modeBits field and AWT is available, implementation is aware of the AWT EDT, otherwise not.

protected int
protected static final long
protected boolean
private static int
protected static final long
TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION

A 1s timeout while waiting for a native action response, limiting finishLifecycleAction(Condition, long)

protected GLAnimatorControl.UncaughtExceptionHandler
protected Thread
private final AnimatorBase.Condition

Constructor Summary

AccessConstructor and Description
public
AnimatorBase()

Creates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available.

Method Summary

Modifier and TypeMethod and Description
public final synchronized void
add(final GLAutoDrawable
the drawable to be added
drawable
)

Implements com.jogamp.opengl.GLAnimatorControl.add.

Adds a drawable to this animator's list of rendering drawables.
protected final void
display()

Called every frame to cause redrawing of all of the GLAutoDrawables this Animator manages.

protected final synchronized boolean

Returns:

true if waitCondition.eval() returned false or if non-blocking. Otherwise returns false.
finishLifecycleAction
(final AnimatorBase.Condition
method will wait until TO is reached or waitCondition.eval() returns false.
waitCondition
,
long
if 0, method will wait until TO is reached or being notified. if > 0, method will wait for the given pollPeriod in milliseconds.
pollPeriod
)

protected final void
flushGLRunnables()

Should be called in case of an uncaught exception from within the animator thread to flush all animator.

protected abstract String
public final synchronized Thread
getExclusiveContextThread()

Returns the exclusive context thread if isExclusiveContextEnabled() and isStarted(), otherwise null.

public final long
getFPSStartTime()

Implements com.jogamp.opengl.FPSCounter.getFPSStartTime.

Returns the time of the first display call in milliseconds after enabling this feature via setUpdateFPSFrames(int, PrintStream).
public final float
public final long
public final long
getLastFPSUpdateTime()

Implements com.jogamp.opengl.FPSCounter.getLastFPSUpdateTime.

Returns the time of the last update interval in milliseconds, if this feature is enabled via setUpdateFPSFrames(int, PrintStream).
public synchronized int
public final synchronized Thread
protected static String
public final float
public final long
public final int
public final GLAnimatorControl.UncaughtExceptionHandler
getUncaughtExceptionHandler()

Implements com.jogamp.opengl.GLAnimatorControl.getUncaughtExceptionHandler.

Returns the UncaughtExceptionHandler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables.
public final int
protected final synchronized boolean

Returns:

true if handled, otherwise false. In case of false, caller needs to propagate the exception.
handleUncaughtException
(final AnimatorBase.UncaughtAnimatorException ue)

Should be called in case of an uncaught exception from within the animator thread, throws given exception if no handler has been installed.

protected final synchronized void
initImpl(final boolean force)

Initializes implementation details post setup, invoked at add(GLAutoDrawable), start(), ..

public final synchronized boolean
isExclusiveContextEnabled()

Returns true, if the exclusive context thread is enabled, otherwise false.

public synchronized boolean
isStarted()

Implements com.jogamp.opengl.GLAnimatorControl.isStarted.

Indicates whether this animator has been started.
public final synchronized void
remove(final GLAutoDrawable
the drawable to be removed
drawable
)

Implements com.jogamp.opengl.GLAnimatorControl.remove.

Removes a drawable from the animator's list of rendering drawables.
public final void
resetFPSCounter()

Implements com.jogamp.opengl.FPSCounter.resetFPSCounter.

Reset all performance counter (startTime, currentTime, frame number)
protected final synchronized void
setDrawablesExclCtxState(final boolean enable)

Should be called at start() and stop() from within the animator thread.

public final synchronized Thread

Returns:

previous value
setExclusiveContext
(final Thread t)

Dedicate all GLAutoDrawable's context to the given exclusive context thread.

public final boolean

Returns:

previous value
setExclusiveContext
(final boolean enable)

Dedicate all GLAutoDrawable's context to this animator thread.

public final void
setIgnoreExceptions(final boolean ignoreExceptions)

Sets a flag causing this Animator to ignore exceptions produced while redrawing the drawables.

public final synchronized void
setModeBits(final boolean enable, final int bitValues)

Enables or disables the given bitValues in this Animators modeBits.

public final void
setPrintExceptions(final boolean printExceptions)

Sets a flag indicating that when exceptions are being ignored by this Animator (see setIgnoreExceptions), to print the exceptions' stack traces for diagnostic information.

public final void
setUncaughtExceptionHandler(final GLAnimatorControl.UncaughtExceptionHandler
the UncaughtExceptionHandler to use as this animator's uncaught exception handler. Pass null to unset the handler.
handler
)

Implements com.jogamp.opengl.GLAnimatorControl.setUncaughtExceptionHandler.

Set the handler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables.
public final void
setUpdateFPSFrames(final int
Update interval in frames.
At every rendered frames interval the currentTime and fps values are updated. If the frames interval is <= 0, no update will be issued, ie the FPSCounter feature is turned off. You may choose DEFAULT_FRAMES_PER_INTERVAL.
frames
,
final PrintStream
optional print stream where the fps values gets printed if not null at every frames interval
out
)

Implements com.jogamp.opengl.FPSCounter.setUpdateFPSFrames.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private static final boolean
useAWTAnimatorImpl(final int modeBits)

protected final boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

animThreadback to summary
protected Thread animThread
awtAnimatorImplClazzback to summary
private static final Class<?> awtAnimatorImplClazz
baseNameback to summary
protected String baseName
DEBUGback to summary
protected static final boolean DEBUG
drawablesback to summary
protected ArrayList<GLAutoDrawable> drawables
drawablesEmptyback to summary
protected boolean drawablesEmpty
exclusiveContextback to summary
protected boolean exclusiveContext
fpsCounterback to summary
protected FPSCounterImpl fpsCounter
ignoreExceptionsback to summary
protected boolean ignoreExceptions
implback to summary
protected AnimatorBase.AnimatorImpl impl
MODE_EXPECT_AWT_RENDERING_THREADback to summary
public static final int MODE_EXPECT_AWT_RENDERING_THREAD

If present in modeBits field and AWT is available, implementation is aware of the AWT EDT, otherwise not.

This is the default.

See Also
setModeBits(boolean, int)
modeBitsback to summary
protected int modeBits
POLLP_WAIT_FOR_FINISH_LIFECYCLE_ACTIONback to summary
protected static final long POLLP_WAIT_FOR_FINISH_LIFECYCLE_ACTION
printExceptionsback to summary
protected boolean printExceptions
seqInstanceNumberback to summary
private static int seqInstanceNumber
TO_WAIT_FOR_FINISH_LIFECYCLE_ACTIONback to summary
protected static final long TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION

A 1s timeout while waiting for a native action response, limiting finishLifecycleAction(Condition, long)

uncaughtExceptionHandlerback to summary
protected GLAnimatorControl.UncaughtExceptionHandler uncaughtExceptionHandler
userExclusiveContextThreadback to summary
protected Thread userExclusiveContextThread
waitForNotAnimatingIfEmptyConditionback to summary
private final AnimatorBase.Condition waitForNotAnimatingIfEmptyCondition

Constructor Detail

AnimatorBaseback to summary
public AnimatorBase()

Creates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available.

See Also
GLProfile#isAWTAvailable()

Method Detail

addback to summary
public final synchronized void add(final GLAutoDrawable drawable)

Implements com.jogamp.opengl.GLAnimatorControl.add.

Doc from com.jogamp.opengl.GLAnimatorControl.add.

Adds a drawable to this animator's list of rendering drawables.

This allows the animator thread to become animating, in case the first drawable is added and the animator is started.

Parameters
drawable:GLAutoDrawable

the drawable to be added

Annotations
@Override
displayback to summary
protected final void display() throws UncaughtAnimatorException

Called every frame to cause redrawing of all of the GLAutoDrawables this Animator manages. Subclasses should call this to get the most optimized painting behavior for the set of components this Animator manages, in particular when multiple lightweight widgets are continually being redrawn.

finishLifecycleActionback to summary
protected final synchronized boolean finishLifecycleAction(final AnimatorBase.Condition waitCondition, long pollPeriod)
Parameters
waitCondition:AnimatorBase.Condition

method will wait until TO is reached or waitCondition.eval() returns false.

pollPeriod:long

if 0, method will wait until TO is reached or being notified. if > 0, method will wait for the given pollPeriod in milliseconds.

Returns:boolean

true if waitCondition.eval() returned false or if non-blocking. Otherwise returns false.

flushGLRunnablesback to summary
protected final void flushGLRunnables()

Should be called in case of an uncaught exception from within the animator thread to flush all animator.

The animator instance shall not be locked when calling this method!

getBaseNameback to summary
protected abstract String getBaseName(String prefix)
getExclusiveContextThreadback to summary
public final synchronized Thread getExclusiveContextThread()

Returns the exclusive context thread if isExclusiveContextEnabled() and isStarted(), otherwise null.

If exclusive context is enabled via setExclusiveContext(boolean) the animator thread is returned if above conditions are met.

If exclusive context is enabled via setExclusiveContext(Thread) the user passed thread is returned if above conditions are met.

See Also
setExclusiveContext(boolean), setExclusiveContext(Thread)
getFPSStartTimeback to summary
public final long getFPSStartTime()

Implements com.jogamp.opengl.FPSCounter.getFPSStartTime.

Doc from com.jogamp.opengl.FPSCounter.getFPSStartTime.

Returns the time of the first display call in milliseconds after enabling this feature via setUpdateFPSFrames(int, PrintStream).
This value is reset via resetFPSCounter().

Annotations
@Override
getLastFPSback to summary
public final float getLastFPS()

Implements com.jogamp.opengl.FPSCounter.getLastFPS.

Returns:float

Doc from com.jogamp.opengl.FPSCounter.getLastFPS.

Last update interval's frames per seconds, getUpdateFPSFrames() / getLastFPSPeriod()

Annotations
@Override
getLastFPSPeriodback to summary
public final long getLastFPSPeriod()

Implements com.jogamp.opengl.FPSCounter.getLastFPSPeriod.

Returns:long

Doc from com.jogamp.opengl.FPSCounter.getLastFPSPeriod.

Duration of the last update interval in milliseconds.

Annotations
@Override
getLastFPSUpdateTimeback to summary
public final long getLastFPSUpdateTime()

Implements com.jogamp.opengl.FPSCounter.getLastFPSUpdateTime.

Doc from com.jogamp.opengl.FPSCounter.getLastFPSUpdateTime.

Returns the time of the last update interval in milliseconds, if this feature is enabled via setUpdateFPSFrames(int, PrintStream).
This value is reset via resetFPSCounter().

Annotations
@Override
getModeBitsback to summary
public synchronized int getModeBits()
getThreadback to summary
public final synchronized Thread getThread()

Implements com.jogamp.opengl.GLAnimatorControl.getThread.

Returns:Thread

Doc from com.jogamp.opengl.GLAnimatorControl.getThread.

The animation thread if running, otherwise null.

Annotations
@Override
getThreadNameback to summary
protected static String getThreadName()
getTotalFPSback to summary
public final float getTotalFPS()

Implements com.jogamp.opengl.FPSCounter.getTotalFPS.

Returns:float

Doc from com.jogamp.opengl.FPSCounter.getTotalFPS.

Total frames per seconds, getTotalFPSFrames() / getTotalFPSDuration()

Annotations
@Override
getTotalFPSDurationback to summary
public final long getTotalFPSDuration()

Implements com.jogamp.opengl.FPSCounter.getTotalFPSDuration.

Returns:long

Doc from com.jogamp.opengl.FPSCounter.getTotalFPSDuration.

Total duration in milliseconds, getLastFPSUpdateTime() - getFPSStartTime()

Annotations
@Override
getTotalFPSFramesback to summary
public final int getTotalFPSFrames()

Implements com.jogamp.opengl.FPSCounter.getTotalFPSFrames.

Returns:int

Doc from com.jogamp.opengl.FPSCounter.getTotalFPSFrames.

Number of frame rendered since getFPSStartTime() up to getLastFPSUpdateTime()

Annotations
@Override
getUncaughtExceptionHandlerback to summary
public final GLAnimatorControl.UncaughtExceptionHandler getUncaughtExceptionHandler()

Implements com.jogamp.opengl.GLAnimatorControl.getUncaughtExceptionHandler.

Doc from com.jogamp.opengl.GLAnimatorControl.getUncaughtExceptionHandler.

Returns the UncaughtExceptionHandler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables.

Default is null.

Annotations
@Override
getUpdateFPSFramesback to summary
public final int getUpdateFPSFrames()

Implements com.jogamp.opengl.FPSCounter.getUpdateFPSFrames.

Returns:int

Doc from com.jogamp.opengl.FPSCounter.getUpdateFPSFrames.

update interval in frames

Annotations
@Override
handleUncaughtExceptionback to summary
protected final synchronized boolean handleUncaughtException(final AnimatorBase.UncaughtAnimatorException ue)

Should be called in case of an uncaught exception from within the animator thread, throws given exception if no handler has been installed.

Returns:boolean

true if handled, otherwise false. In case of false, caller needs to propagate the exception.

initImplback to summary
protected final synchronized void initImpl(final boolean force)

Initializes implementation details post setup, invoked at add(GLAutoDrawable), start(), ..

Operation is a NOP if force is false and this instance is already initialized.

Exceptions
GLException:
if Animator is isStarted()
isExclusiveContextEnabledback to summary
public final synchronized boolean isExclusiveContextEnabled()

Returns true, if the exclusive context thread is enabled, otherwise false.

See Also
setExclusiveContext(boolean), setExclusiveContext(Thread)
isStartedback to summary
public synchronized boolean isStarted()

Implements com.jogamp.opengl.GLAnimatorControl.isStarted.

Doc from com.jogamp.opengl.GLAnimatorControl.isStarted.

Indicates whether this animator has been started.

Annotations
@Override
removeback to summary
public final synchronized void remove(final GLAutoDrawable drawable)

Implements com.jogamp.opengl.GLAnimatorControl.remove.

Doc from com.jogamp.opengl.GLAnimatorControl.remove.

Removes a drawable from the animator's list of rendering drawables.

This method should get called in case a drawable becomes invalid, and will not be recovered.

This allows the animator thread to become not animating, in case the last drawable has been removed.

Parameters
drawable:GLAutoDrawable

the drawable to be removed

Annotations
@Override
resetFPSCounterback to summary
public final void resetFPSCounter()

Implements com.jogamp.opengl.FPSCounter.resetFPSCounter.

Doc from com.jogamp.opengl.FPSCounter.resetFPSCounter.

Reset all performance counter (startTime, currentTime, frame number)

Annotations
@Override
setDrawablesExclCtxStateback to summary
protected final synchronized void setDrawablesExclCtxState(final boolean enable)

Should be called at start() and stop() from within the animator thread.

At stop() an additional display() call shall be issued to allow propagation of releasing the exclusive thread.

setExclusiveContextback to summary
public final synchronized Thread setExclusiveContext(final Thread t)

Dedicate all GLAutoDrawable's context to the given exclusive context thread.

The given thread will be exclusive to all GLAutoDrawable's context while isAnimating().

If already started and disabling, method waits until change is propagated to all GLAutoDrawable if not called from the animator thread or exclusive context thread.

Note

Utilizing this feature w/ AWT could lead to an AWT-EDT deadlock, depending on the AWT implementation. Hence it is advised not to use it with native AWT GLAutoDrawable like GLCanvas.

Returns:Thread

previous value

See Also
setExclusiveContext(boolean), getExclusiveContextThread(), isExclusiveContextEnabled()
setExclusiveContextback to summary
public final boolean setExclusiveContext(final boolean enable)

Dedicate all GLAutoDrawable's context to this animator thread.

The given thread will be exclusive to all GLAutoDrawable's context while isAnimating().

If already started and disabling, method waits until change is propagated to all GLAutoDrawable if not called from the animator thread or exclusive context thread.

Note

Utilizing this feature w/ AWT could lead to an AWT-EDT deadlock, depending on the AWT implementation. Hence it is advised not to use it with native AWT GLAutoDrawable like GLCanvas.

Returns:boolean

previous value

See Also
setExclusiveContext(Thread), getExclusiveContextThread(), isExclusiveContextEnabled()
setIgnoreExceptionsback to summary
public final void setIgnoreExceptions(final boolean ignoreExceptions)

Sets a flag causing this Animator to ignore exceptions produced while redrawing the drawables. By default this flag is set to false, causing any exception thrown to halt the Animator.

setModeBitsback to summary
public final synchronized void setModeBits(final boolean enable, final int bitValues) throws GLException

Enables or disables the given bitValues in this Animators modeBits.

Exceptions
GLException:
if Animator is isStarted() and MODE_EXPECT_AWT_RENDERING_THREAD about to change
See Also
AnimatorBase#MODE_EXPECT_AWT_RENDERING_THREAD
setPrintExceptionsback to summary
public final void setPrintExceptions(final boolean printExceptions)

Sets a flag indicating that when exceptions are being ignored by this Animator (see setIgnoreExceptions), to print the exceptions' stack traces for diagnostic information. Defaults to false.

setUncaughtExceptionHandlerback to summary
public final void setUncaughtExceptionHandler(final GLAnimatorControl.UncaughtExceptionHandler handler)

Implements com.jogamp.opengl.GLAnimatorControl.setUncaughtExceptionHandler.

Doc from com.jogamp.opengl.GLAnimatorControl.setUncaughtExceptionHandler.

Set the handler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables.

Parameters
handler:GLAnimatorControl.UncaughtExceptionHandler

the UncaughtExceptionHandler to use as this animator's uncaught exception handler. Pass null to unset the handler.

Annotations
@Override
setUpdateFPSFramesback to summary
public final void setUpdateFPSFrames(final int frames, final PrintStream out)

Implements com.jogamp.opengl.FPSCounter.setUpdateFPSFrames.

Parameters
frames:int

Doc from com.jogamp.opengl.FPSCounter.setUpdateFPSFrames.

Update interval in frames.
At every rendered frames interval the currentTime and fps values are updated. If the frames interval is <= 0, no update will be issued, ie the FPSCounter feature is turned off. You may choose DEFAULT_FRAMES_PER_INTERVAL.

out:PrintStream

Doc from com.jogamp.opengl.FPSCounter.setUpdateFPSFrames.

optional print stream where the fps values gets printed if not null at every frames interval

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
useAWTAnimatorImplback to summary
private static final boolean useAWTAnimatorImpl(final int modeBits)
validateDrawablesExclCtxStateback to summary
protected final boolean validateDrawablesExclCtxState(final Thread expected)
com.jogamp.opengl.util back to summary

public Interface AnimatorBase.AnimatorImpl

Known Direct Implementers
com.jogamp.opengl.util.AWTAnimatorImpl, com.jogamp.opengl.util.DefaultAnimatorImpl

Method Summary

Modifier and TypeMethod and Description
public boolean
blockUntilDone(final Thread thread)

public void
display(final ArrayList<GLAutoDrawable> drawables, final boolean ignoreExceptions, final boolean printExceptions)

Method Detail

blockUntilDoneback to summary
public boolean blockUntilDone(final Thread thread)
displayback to summary
public void display(final ArrayList<GLAutoDrawable> drawables, final boolean ignoreExceptions, final boolean printExceptions) throws UncaughtAnimatorException
Exceptions
UncaughtAnimatorException:
as caused by GLAutoDrawable#display()
com.jogamp.opengl.util back to summary

protected Interface AnimatorBase.Condition


Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if branching (continue waiting, action), otherwise false
eval
()

Method Detail

evalback to summary
public boolean eval()
Returns:boolean

true if branching (continue waiting, action), otherwise false

com.jogamp.opengl.util back to summary

public Class AnimatorBase.UncaughtAnimatorException

extends RuntimeException
Class Inheritance
Annotations
@SuppressWarnings:serial

Field Summary

Modifier and TypeField and Description
pack-priv final GLAutoDrawable

Constructor Summary

AccessConstructor and Description
public
UncaughtAnimatorException(final GLAutoDrawable drawable, final Throwable cause)

Method Summary

Modifier and TypeMethod and Description
public final GLAutoDrawable

Field Detail

drawableback to summary
pack-priv final GLAutoDrawable drawable

Constructor Detail

UncaughtAnimatorExceptionback to summary
public UncaughtAnimatorException(final GLAutoDrawable drawable, final Throwable cause)

Method Detail

getGLAutoDrawableback to summary
public final GLAutoDrawable getGLAutoDrawable()