diff options
author | Kenneth Russel <[email protected]> | 2006-02-21 09:43:43 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-02-21 09:43:43 +0000 |
commit | 36887db6c983244917802f3ec761a0d28171887a (patch) | |
tree | 7a79ed8a39d4278507482cd11d170e235111292d /src/classes/com/sun/opengl/impl/GLDrawableHelper.java | |
parent | 704375911f3f01e9d4318783301ea3aba7891cb2 (diff) |
Added optimized path to GLDrawableHelper for situation where
GLWorkerThread is being used; last context made current on that thread
is left current on that thread. In the case where only a single OpenGL
context is in use this eliminates the repeated calls to makeCurrent.
Ran into same NVidia driver bug causing crashes upon exit with
Java2D/OpenGL pipeline. Added workaround to GLDrawableHelper which can
be enabled with -Djogl.nvidia.crash.workaround, which just disables
this optimization. Fixed GLCanvas and GLPbufferImpl's destruction
paths to behave correctly in the face of the context being left
current on the GLWorkerThread. Updated code in Threading related to
GLWorkerThread to interoperate better with Java2D/OpenGL pipeline.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@629 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl/GLDrawableHelper.java')
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLDrawableHelper.java | 123 |
1 files changed, 92 insertions, 31 deletions
diff --git a/src/classes/com/sun/opengl/impl/GLDrawableHelper.java b/src/classes/com/sun/opengl/impl/GLDrawableHelper.java index 614b26096..920fac624 100644 --- a/src/classes/com/sun/opengl/impl/GLDrawableHelper.java +++ b/src/classes/com/sun/opengl/impl/GLDrawableHelper.java @@ -49,6 +49,7 @@ public class GLDrawableHelper { private volatile List listeners = new ArrayList(); private static final boolean DEBUG = Debug.debug("GLDrawableHelper"); private static final boolean VERBOSE = Debug.verbose(); + private static final boolean NVIDIA_CRASH_WORKAROUND = Debug.isPropertyDefined("jogl.nvidia.crash.workaround"); private boolean autoSwapBufferMode = true; public GLDrawableHelper() { @@ -104,46 +105,106 @@ public class GLDrawableHelper { GLContext context, Runnable runnable, Runnable initAction) { - // Support for recursive makeCurrent() calls as well as calling - // other drawables' display() methods from within another one's - GLContext lastContext = GLContext.getCurrent(); - Runnable lastInitAction = (Runnable) perThreadInitAction.get(); - if (lastContext != null) { - lastContext.release(); - } - - int res = 0; - try { - res = context.makeCurrent(); - if (res != GLContext.CONTEXT_NOT_CURRENT) { - perThreadInitAction.set(initAction); - if (res == GLContext.CONTEXT_CURRENT_NEW) { - if (DEBUG) { - System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running initAction"); + if (GLWorkerThread.isStarted() && + GLWorkerThread.isWorkerThread()) { + // We're going to allow a context to be left current on the + // GLWorkerThread for optimization purposes + GLContext lastContext = GLContext.getCurrent(); + Runnable lastInitAction = (Runnable) perThreadInitAction.get(); + if (lastContext != null && lastContext != context) { + lastContext.release(); + } else { + lastContext = null; + } + + // FIXME: probably need to handle the case where the user is + // waiting for this context to be released; need to periodically + // release the context? See if anybody is waiting to make it + // current on another thread? (The latter would require the use + // of internal APIs...) + + int res = 0; + try { + res = context.makeCurrent(); + if (res != GLContext.CONTEXT_NOT_CURRENT) { + perThreadInitAction.set(initAction); + if (res == GLContext.CONTEXT_CURRENT_NEW) { + if (DEBUG) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running initAction"); + } + initAction.run(); + } + if (DEBUG && VERBOSE) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running runnable"); + } + runnable.run(); + if (autoSwapBufferMode) { + if (drawable != null) { + drawable.swapBuffers(); + } } - initAction.run(); } - if (DEBUG && VERBOSE) { - System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running runnable"); + } finally { + + // FIXME: take this out as soon as possible + if (NVIDIA_CRASH_WORKAROUND) { + try { + if (res != GLContext.CONTEXT_NOT_CURRENT) { + context.release(); + } + } catch (Exception e) { + } } - runnable.run(); - if (autoSwapBufferMode) { - if (drawable != null) { - drawable.swapBuffers(); + + if (lastContext != null) { + int res2 = lastContext.makeCurrent(); + if (res2 == GLContext.CONTEXT_CURRENT_NEW) { + lastInitAction.run(); } } } - } finally { + } else { + // Support for recursive makeCurrent() calls as well as calling + // other drawables' display() methods from within another one's + GLContext lastContext = GLContext.getCurrent(); + Runnable lastInitAction = (Runnable) perThreadInitAction.get(); + if (lastContext != null) { + lastContext.release(); + } + + int res = 0; try { + res = context.makeCurrent(); if (res != GLContext.CONTEXT_NOT_CURRENT) { - context.release(); + perThreadInitAction.set(initAction); + if (res == GLContext.CONTEXT_CURRENT_NEW) { + if (DEBUG) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running initAction"); + } + initAction.run(); + } + if (DEBUG && VERBOSE) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running runnable"); + } + runnable.run(); + if (autoSwapBufferMode) { + if (drawable != null) { + drawable.swapBuffers(); + } + } } - } catch (Exception e) { - } - if (lastContext != null) { - int res2 = lastContext.makeCurrent(); - if (res2 == GLContext.CONTEXT_CURRENT_NEW) { - lastInitAction.run(); + } finally { + try { + if (res != GLContext.CONTEXT_NOT_CURRENT) { + context.release(); + } + } catch (Exception e) { + } + if (lastContext != null) { + int res2 = lastContext.makeCurrent(); + if (res2 == GLContext.CONTEXT_CURRENT_NEW) { + lastInitAction.run(); + } } } } |