aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-06-29 04:15:21 +0200
committerSven Gothel <[email protected]>2012-06-29 04:15:21 +0200
commit0d7c3ed619044723cf561df424eac9992e5281c7 (patch)
tree3ffa52aa71536a3321b9bf7e59de7ee28ede5917 /src/jogl/classes/jogamp
parentd10c7916a2444b6cb1cf45be3ccb3d6e91a2f1b4 (diff)
GLContextImpl/GLDrawableImpl: More fail-safe, cleanup, mark some methods final
GLContextImpl: Cleanup - release(): simplify the conditions - destroy(): allow locked twice before (destroy case) GLDrawableImpl: - fail safe: swapBuffers - final methods: getFactoryImpl, toHexString, getGLProfile, getRequestedGLCapabilities, getFactory, isRealized, lockSurface, unlockSurface
Diffstat (limited to 'src/jogl/classes/jogamp')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java19
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableImpl.java19
-rw-r--r--src/jogl/classes/jogamp/opengl/GLPbufferImpl.java6
3 files changed, 25 insertions, 19 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
index ea024e691..4ef8b9750 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
@@ -233,12 +233,10 @@ public abstract class GLContextImpl extends GLContext {
if ( !lock.isOwner(Thread.currentThread()) ) {
throw new GLException("Context not current on current thread "+Thread.currentThread().getName()+": "+this);
}
- final boolean actualRelease = force || lock.getHoldCount() == 1 ;
+ final boolean actualRelease = ( force || lock.getHoldCount() == 1 ) && 0 != contextHandle;
try {
if( actualRelease ) {
- if (contextHandle != 0) { // allow dbl-release
- releaseImpl();
- }
+ releaseImpl();
}
} finally {
// exception prone ..
@@ -269,11 +267,16 @@ public abstract class GLContextImpl extends GLContext {
try {
// Must hold the lock around the destroy operation to make sure we
// don't destroy the context while another thread renders to it.
- // FIXME: This is actually impossible now, since we acquired the surface lock already,
- // which is a prerequisite to acquire the context lock.
- lock.lock(); // holdCount++ -> 1 or 2
+ lock.lock(); // holdCount++ -> 1 - 3 (1: not locked, 2-3: destroy while rendering)
if ( lock.getHoldCount() > 2 ) {
- throw new GLException(getThreadName() + ": Lock was hold more than once - makeCurrent/release imbalance: "+lock);
+ final String msg = getThreadName() + ": GLContextImpl.destroy: obj " + toHexString(hashCode()) + ", ctx " + toHexString(contextHandle);
+ if (DEBUG || TRACE_SWITCH) {
+ System.err.println(msg+" - Lock was hold more than once - makeCurrent/release imbalance: "+lock);
+ Thread.dumpStack();
+ }
+ if ( lock.getHoldCount() > 3 ) {
+ throw new GLException(msg+" - Lock was hold more than twice - makeCurrent/release imbalance: "+lock);
+ }
}
try {
// release current context
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java
index c843e5571..b3884830a 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java
@@ -66,7 +66,7 @@ public abstract class GLDrawableImpl implements GLDrawable {
*/
public abstract GLDynamicLookupHelper getGLDynamicLookupHelper();
- public GLDrawableFactoryImpl getFactoryImpl() {
+ public final GLDrawableFactoryImpl getFactoryImpl() {
return (GLDrawableFactoryImpl) getFactory();
}
@@ -86,6 +86,9 @@ public abstract class GLDrawableImpl implements GLDrawable {
@Override
public final void swapBuffers() throws GLException {
+ if( !realized ) {
+ return; // destroyed already
+ }
GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)surface.getGraphicsConfiguration().getChosenCapabilities();
if ( caps.getDoubleBuffered() ) {
if(!surface.surfaceSwap()) {
@@ -112,12 +115,12 @@ public abstract class GLDrawableImpl implements GLDrawable {
}
protected abstract void swapBuffersImpl();
- public static String toHexString(long hex) {
+ public final static String toHexString(long hex) {
return "0x" + Long.toHexString(hex);
}
@Override
- public GLProfile getGLProfile() {
+ public final GLProfile getGLProfile() {
return requestedCapabilities.getGLProfile();
}
@@ -126,7 +129,7 @@ public abstract class GLDrawableImpl implements GLDrawable {
return (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getChosenCapabilities();
}
- public GLCapabilitiesImmutable getRequestedGLCapabilities() {
+ public final GLCapabilitiesImmutable getRequestedGLCapabilities() {
return requestedCapabilities;
}
@@ -147,7 +150,7 @@ public abstract class GLDrawableImpl implements GLDrawable {
}
@Override
- public GLDrawableFactory getFactory() {
+ public final GLDrawableFactory getFactory() {
return factory;
}
@@ -187,7 +190,7 @@ public abstract class GLDrawableImpl implements GLDrawable {
protected abstract void setRealizedImpl();
@Override
- public synchronized boolean isRealized() {
+ public final synchronized boolean isRealized() {
return realized;
}
@@ -201,11 +204,11 @@ public abstract class GLDrawableImpl implements GLDrawable {
return surface.getHeight();
}
- public int lockSurface() throws GLException {
+ public final int lockSurface() throws GLException {
return surface.lockSurface();
}
- public void unlockSurface() {
+ public final void unlockSurface() {
surface.unlockSurface();
}
diff --git a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
index 9b3def434..0ed3be48b 100644
--- a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
@@ -88,16 +88,16 @@ public class GLPbufferImpl implements GLPbuffer {
}
@Override
- public GLContext createContext(GLContext shareWith) {
+ public final GLContext createContext(GLContext shareWith) {
return pbufferDrawable.createContext(shareWith);
}
@Override
- public void setRealized(boolean realized) {
+ public final void setRealized(boolean realized) {
}
@Override
- public boolean isRealized() {
+ public final boolean isRealized() {
return true;
}