aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-07-03 16:21:36 +0200
committerSven Gothel <[email protected]>2014-07-03 16:21:36 +0200
commit556d92b63555a085b25e32b1cd55afce24edd07a (patch)
tree6be2b02c62a77d5aba81ffbe34c46960608be163 /src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
parenta90f4a51dffec3247278e3c683ed4462b1dd9ab5 (diff)
Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74)
- Change non static accesses to static members using declaring type - Change indirect accesses to static members to direct accesses (accesses through subtypes) - Add final modifier to private fields - Add final modifier to method parameters - Add final modifier to local variables - Remove unnecessary casts - Remove unnecessary '$NON-NLS$' tags - Remove trailing white spaces on all lines
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/GLDrawableHelper.java')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableHelper.java90
1 files changed, 46 insertions, 44 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
index bf791822f..aea9a5b7b 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
@@ -60,6 +60,8 @@ import javax.media.opengl.GLFBODrawable;
import javax.media.opengl.GLRunnable;
import javax.media.opengl.GLSharedContextSetter;
+import com.jogamp.common.util.PropertyAccess;
+
/** Encapsulates the implementation of most of the GLAutoDrawable's
methods to be able to share it between GLAutoDrawable implementations like GLAutoDrawableBase, GLCanvas and GLJPanel. */
public class GLDrawableHelper {
@@ -68,7 +70,7 @@ public class GLDrawableHelper {
static {
Debug.initSingleton();
- PERF_STATS = Debug.isPropertyDefined("jogl.debug.GLDrawable.PerfStats", true);
+ PERF_STATS = PropertyAccess.isPropertyDefined("jogl.debug.GLDrawable.PerfStats", true);
}
protected static final boolean DEBUG = GLDrawableImpl.DEBUG;
@@ -108,7 +110,7 @@ public class GLDrawableHelper {
sharedAutoDrawable = null;
}
- public final void setSharedContext(GLContext thisContext, GLContext sharedContext) throws IllegalStateException {
+ public final void setSharedContext(final GLContext thisContext, final GLContext sharedContext) throws IllegalStateException {
if( null == sharedContext ) {
throw new IllegalStateException("Null shared GLContext");
}
@@ -124,7 +126,7 @@ public class GLDrawableHelper {
this.sharedContext = sharedContext;
}
- public final void setSharedAutoDrawable(GLAutoDrawable thisAutoDrawable, GLAutoDrawable sharedAutoDrawable) throws IllegalStateException {
+ public final void setSharedAutoDrawable(final GLAutoDrawable thisAutoDrawable, final GLAutoDrawable sharedAutoDrawable) throws IllegalStateException {
if( null == sharedAutoDrawable ) {
throw new IllegalStateException("Null shared GLAutoDrawable");
}
@@ -146,7 +148,7 @@ public class GLDrawableHelper {
* @return true if initialization is pending due to a set shared GLAutoDrawable or GLContext
* which is not ready yet. Otherwise false.
*/
- public boolean isSharedGLContextPending(GLContext[] shared) {
+ public boolean isSharedGLContextPending(final GLContext[] shared) {
final GLContext shareWith;
final boolean pending;
if ( null != sharedAutoDrawable ) {
@@ -168,12 +170,12 @@ public class GLDrawableHelper {
@Override
public final String toString() {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append("GLAnimatorControl: "+animatorCtrl+", ");
synchronized(listenersLock) {
sb.append("GLEventListeners num "+listeners.size()+" [");
for (int i=0; i < listeners.size(); i++) {
- Object l = listeners.get(i);
+ final Object l = listeners.get(i);
sb.append(l);
sb.append("[init ");
sb.append( !listenersToBeInit.contains(l) );
@@ -195,7 +197,7 @@ public class GLDrawableHelper {
* </p>
* @param ctx
*/
- public static final void forceNativeRelease(GLContext ctx) {
+ public static final void forceNativeRelease(final GLContext ctx) {
int releaseCount = 0;
do {
ctx.release();
@@ -236,7 +238,7 @@ public class GLDrawableHelper {
*
* @see GLAutoDrawable#setContext(GLContext, boolean)
*/
- public static final void switchContext(GLDrawable drawable, GLContext oldCtx, boolean destroyOldCtx, GLContext newCtx, int newCtxCreationFlags) {
+ public static final void switchContext(final GLDrawable drawable, final GLContext oldCtx, final boolean destroyOldCtx, final GLContext newCtx, final int newCtxCreationFlags) {
if( null != oldCtx ) {
if( destroyOldCtx ) {
oldCtx.destroy();
@@ -268,7 +270,7 @@ public class GLDrawableHelper {
* @param context maybe null
* @return the new drawable
*/
- public static final GLDrawableImpl recreateGLDrawable(GLDrawableImpl drawable, GLContext context) {
+ public static final GLDrawableImpl recreateGLDrawable(GLDrawableImpl drawable, final GLContext context) {
if( ! drawable.isRealized() ) {
return drawable;
}
@@ -335,7 +337,7 @@ public class GLDrawableHelper {
* @throws NativeWindowException is drawable is not offscreen or it's surface lock couldn't be claimed
* @throws GLException may be thrown a resize operation
*/
- public static final GLDrawableImpl resizeOffscreenDrawable(GLDrawableImpl drawable, GLContext context, int newWidth, int newHeight)
+ public static final GLDrawableImpl resizeOffscreenDrawable(GLDrawableImpl drawable, final GLContext context, int newWidth, int newHeight)
throws NativeWindowException, GLException
{
final NativeSurface ns = drawable.getNativeSurface();
@@ -385,11 +387,11 @@ public class GLDrawableHelper {
return drawable;
}
- public final void addGLEventListener(GLEventListener listener) {
+ public final void addGLEventListener(final GLEventListener listener) {
addGLEventListener(-1, listener);
}
- public final void addGLEventListener(int index, GLEventListener listener) {
+ public final void addGLEventListener(int index, final GLEventListener listener) {
synchronized(listenersLock) {
if(0>index) {
index = listeners.size();
@@ -408,7 +410,7 @@ public class GLDrawableHelper {
* Consider calling {@link #disposeGLEventListener(GLAutoDrawable, GLDrawable, GLContext, GLEventListener)}.
* @return the removed listener, or null if listener was not added
*/
- public final GLEventListener removeGLEventListener(GLEventListener listener) {
+ public final GLEventListener removeGLEventListener(final GLEventListener listener) {
synchronized(listenersLock) {
listenersToBeInit.remove(listener);
return listeners.remove(listener) ? listener : null;
@@ -447,13 +449,13 @@ public class GLDrawableHelper {
}
}
- public final boolean getGLEventListenerInitState(GLEventListener listener) {
+ public final boolean getGLEventListenerInitState(final GLEventListener listener) {
synchronized(listenersLock) {
return !listenersToBeInit.contains(listener);
}
}
- public final void setGLEventListenerInitState(GLEventListener listener, boolean initialized) {
+ public final void setGLEventListenerInitState(final GLEventListener listener, final boolean initialized) {
synchronized(listenersLock) {
if(initialized) {
listenersToBeInit.remove(listener);
@@ -478,7 +480,7 @@ public class GLDrawableHelper {
* @param remove if true, the listener gets removed
* @return the disposed and/or removed listener, otherwise null if neither action is performed
*/
- public final GLEventListener disposeGLEventListener(GLAutoDrawable autoDrawable, GLEventListener listener, boolean remove) {
+ public final GLEventListener disposeGLEventListener(final GLAutoDrawable autoDrawable, final GLEventListener listener, final boolean remove) {
synchronized(listenersLock) {
if( remove ) {
if( listeners.remove(listener) ) {
@@ -512,7 +514,7 @@ public class GLDrawableHelper {
* @param autoDrawable
* @return the disposal count
*/
- public final int disposeAllGLEventListener(GLAutoDrawable autoDrawable, boolean remove) {
+ public final int disposeAllGLEventListener(final GLAutoDrawable autoDrawable, final boolean remove) {
int disposeCount = 0;
synchronized(listenersLock) {
if( remove ) {
@@ -613,7 +615,7 @@ public class GLDrawableHelper {
}
}
- private final void init(GLEventListener l, GLAutoDrawable drawable, boolean sendReshape, boolean setViewport) {
+ private final void init(final GLEventListener l, final GLAutoDrawable drawable, final boolean sendReshape, final boolean setViewport) {
l.init(drawable);
if(sendReshape) {
reshape(l, drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), setViewport, false /* checkInit */);
@@ -624,7 +626,7 @@ public class GLDrawableHelper {
* The default init action to be called once after ctx is being created @ 1st makeCurrent().
* @param sendReshape set to true if the subsequent display call won't reshape, otherwise false to avoid double reshape.
**/
- public final void init(GLAutoDrawable drawable, boolean sendReshape) {
+ public final void init(final GLAutoDrawable drawable, final boolean sendReshape) {
synchronized(listenersLock) {
final ArrayList<GLEventListener> _listeners = listeners;
final int listenerCount = _listeners.size();
@@ -645,13 +647,13 @@ public class GLDrawableHelper {
}
}
- public final void display(GLAutoDrawable drawable) {
+ public final void display(final GLAutoDrawable drawable) {
displayImpl(drawable);
if( glRunnables.size()>0 && !execGLRunnables(drawable) ) { // glRunnables volatile OK; execGL.. only executed if size > 0
displayImpl(drawable);
}
}
- private final void displayImpl(GLAutoDrawable drawable) {
+ private final void displayImpl(final GLAutoDrawable drawable) {
synchronized(listenersLock) {
final ArrayList<GLEventListener> _listeners = listeners;
final int listenerCount = _listeners.size();
@@ -667,8 +669,8 @@ public class GLDrawableHelper {
}
}
- private final void reshape(GLEventListener listener, GLAutoDrawable drawable,
- int x, int y, int width, int height, boolean setViewport, boolean checkInit) {
+ private final void reshape(final GLEventListener listener, final GLAutoDrawable drawable,
+ final int x, final int y, final int width, final int height, final boolean setViewport, final boolean checkInit) {
if(checkInit) {
// GLEventListener may need to be init,
// in case this one is added after the realization of the GLAutoDrawable
@@ -692,7 +694,7 @@ public class GLDrawableHelper {
listener.reshape(drawable, x, y, width, height);
}
- public final void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ public final void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
synchronized(listenersLock) {
for (int i=0; i < listeners.size(); i++) {
reshape(listeners.get(i), drawable, x, y, width, height, 0==i /* setViewport */, true /* checkInit */);
@@ -700,7 +702,7 @@ public class GLDrawableHelper {
}
}
- private final boolean execGLRunnables(GLAutoDrawable drawable) { // glRunnables.size()>0
+ private final boolean execGLRunnables(final GLAutoDrawable drawable) { // glRunnables.size()>0
boolean res = true;
// swap one-shot list asap
final ArrayList<GLRunnableTask> _glRunnables;
@@ -742,7 +744,7 @@ public class GLDrawableHelper {
}
}
- public final void setAnimator(GLAnimatorControl animator) throws GLException {
+ public final void setAnimator(final GLAnimatorControl animator) throws GLException {
synchronized(glRunnablesLock) {
if(animatorCtrl!=animator && null!=animator && null!=animatorCtrl) {
throw new GLException("Trying to register GLAnimatorControl "+animator+", where "+animatorCtrl+" is already registered. Unregister first.");
@@ -789,14 +791,14 @@ public class GLDrawableHelper {
* @param glRunnable the {@link GLRunnable} to execute within {@link #display()}
* @return <code>true</code> if the {@link GLRunnable} has been processed or queued, otherwise <code>false</code>.
*/
- public final boolean invoke(GLAutoDrawable drawable, boolean wait, GLRunnable glRunnable) {
+ public final boolean invoke(final GLAutoDrawable drawable, boolean wait, final GLRunnable glRunnable) {
if( null == glRunnable || null == drawable ||
wait && ( !drawable.isRealized() || null==drawable.getContext() ) ) {
return false;
}
GLRunnableTask rTask = null;
- Object rTaskLock = new Object();
+ final Object rTaskLock = new Object();
Throwable throwable = null;
synchronized(rTaskLock) {
final boolean deferred;
@@ -815,7 +817,7 @@ public class GLDrawableHelper {
} else if( wait ) {
try {
rTaskLock.wait(); // free lock, allow execution of rTask
- } catch (InterruptedException ie) {
+ } catch (final InterruptedException ie) {
throwable = ie;
}
if(null==throwable) {
@@ -829,7 +831,7 @@ public class GLDrawableHelper {
return true;
}
- public final boolean invoke(GLAutoDrawable drawable, boolean wait, List<GLRunnable> newGLRunnables) {
+ public final boolean invoke(final GLAutoDrawable drawable, boolean wait, final List<GLRunnable> newGLRunnables) {
if( null == newGLRunnables || newGLRunnables.size() == 0 || null == drawable ||
wait && ( !drawable.isRealized() || null==drawable.getContext() ) ) {
return false;
@@ -837,7 +839,7 @@ public class GLDrawableHelper {
final int count = newGLRunnables.size();
GLRunnableTask rTask = null;
- Object rTaskLock = new Object();
+ final Object rTaskLock = new Object();
Throwable throwable = null;
synchronized(rTaskLock) {
final boolean deferred;
@@ -859,7 +861,7 @@ public class GLDrawableHelper {
} else if( wait ) {
try {
rTaskLock.wait(); // free lock, allow execution of rTask
- } catch (InterruptedException ie) {
+ } catch (final InterruptedException ie) {
throwable = ie;
}
if(null==throwable) {
@@ -873,7 +875,7 @@ public class GLDrawableHelper {
return true;
}
- public final void enqueue(GLRunnable glRunnable) {
+ public final void enqueue(final GLRunnable glRunnable) {
if( null == glRunnable) {
return;
}
@@ -882,7 +884,7 @@ public class GLDrawableHelper {
}
}
- public final void setAutoSwapBufferMode(boolean enable) {
+ public final void setAutoSwapBufferMode(final boolean enable) {
autoSwapBufferMode = enable;
}
@@ -921,7 +923,7 @@ public class GLDrawableHelper {
* @return previous exclusive context thread
* @throws GLException If an exclusive thread is still active but a new one is attempted to be set
*/
- public final Thread setExclusiveContextThread(Thread t, GLContext context) throws GLException {
+ public final Thread setExclusiveContextThread(final Thread t, final GLContext context) throws GLException {
if (DEBUG) {
System.err.println("GLDrawableHelper.setExclusiveContextThread(): START switch "+getExclusiveContextSwitchString()+", thread "+exclusiveContextThread+" -> "+t+" -- currentThread "+Thread.currentThread());
}
@@ -938,7 +940,7 @@ public class GLDrawableHelper {
if( null != context && context.isCurrent() ) {
try {
forceNativeRelease(context);
- } catch (Throwable ex) {
+ } catch (final Throwable ex) {
ex.printStackTrace();
throw new GLException(ex);
}
@@ -982,7 +984,7 @@ public class GLDrawableHelper {
final Runnable initAction) {
if(null==context) {
if (DEBUG) {
- Exception e = new GLException(getThreadName()+" Info: GLDrawableHelper " + this + ".invokeGL(): NULL GLContext");
+ final Exception e = new GLException(getThreadName()+" Info: GLDrawableHelper " + this + ".invokeGL(): NULL GLContext");
e.printStackTrace();
}
return;
@@ -1010,7 +1012,7 @@ public class GLDrawableHelper {
* @param destroyContext destroy context in the end while holding the lock
*/
public final void disposeGL(final GLAutoDrawable autoDrawable,
- final GLContext context, boolean destroyContext) {
+ final GLContext context, final boolean destroyContext) {
// Support for recursive makeCurrent() calls as well as calling
// other drawables' display() methods from within another one's
GLContext lastContext = GLContext.getCurrent();
@@ -1044,7 +1046,7 @@ public class GLDrawableHelper {
forceNativeRelease(context);
}
flushGLRunnables();
- } catch (Exception e) {
+ } catch (final Exception e) {
System.err.println("Caught exception on thread "+getThreadName());
e.printStackTrace();
}
@@ -1130,7 +1132,7 @@ public class GLDrawableHelper {
if( releaseContext ) {
try {
context.release();
- } catch (Exception e) {
+ } catch (final Exception e) {
System.err.println("Caught exception on thread "+getThreadName());
e.printStackTrace();
}
@@ -1188,14 +1190,14 @@ public class GLDrawableHelper {
}
}
- long t0 = System.currentTimeMillis();
+ final long t0 = System.currentTimeMillis();
long tdA = 0; // makeCurrent
long tdR = 0; // render time
long tdS = 0; // swapBuffers
long tdX = 0; // release
boolean ctxClaimed = false;
boolean ctxReleased = false;
- boolean ctxDestroyed = false;
+ final boolean ctxDestroyed = false;
try {
final boolean releaseContext;
if( GLContext.CONTEXT_NOT_CURRENT == res ) {
@@ -1236,7 +1238,7 @@ public class GLDrawableHelper {
try {
context.release();
ctxReleased = true;
- } catch (Exception e) {
+ } catch (final Exception e) {
System.err.println("Caught exception on thread "+getThreadName());
e.printStackTrace();
}
@@ -1252,7 +1254,7 @@ public class GLDrawableHelper {
}
}
}
- long td = System.currentTimeMillis() - t0;
+ final long td = System.currentTimeMillis() - t0;
System.err.println("td0 "+td+"ms, fps "+(1.0/(td/1000.0))+", td-makeCurrent: "+tdA+"ms, td-render "+tdR+"ms, td-swap "+tdS+"ms, td-release "+tdX+"ms, ctx claimed: "+ctxClaimed+", ctx release: "+ctxReleased+", ctx destroyed "+ctxDestroyed);
}