diff options
author | Sven Gothel <[email protected]> | 2008-06-28 23:50:30 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-06-28 23:50:30 +0000 |
commit | 7be2d71e458dd37789ceac43dede4b308eff45c2 (patch) | |
tree | 3bdf63df9b5dce95ad8ac28047513191e2a04251 /src | |
parent | d96486967efcfb6f43226da9fa60cbc3d68ab323 (diff) |
Synced locking of EGLDrawable/EGLContext with X11GLX* counterpart.
However, the 'unofficial combination' X11/AWT/EGL-Emulation
will freeze when AWT locking will be used.
Hence AWT locking is disabled within EGL,
which has no impact for the NEWT/EGL product.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1701 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
3 files changed, 70 insertions, 25 deletions
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLContext.java b/src/classes/com/sun/opengl/impl/egl/EGLContext.java index 932cf5822..0e6d07a8e 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLContext.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLContext.java @@ -56,7 +56,7 @@ public class EGLContext extends GLContextImpl { return context; } - protected int makeCurrentImpl() throws GLException { + private int makeCurrentImplInner() throws GLException { boolean created = false; if (context == 0) { create(); @@ -66,13 +66,14 @@ public class EGLContext extends GLContextImpl { } created = true; } - - if (!EGL.eglMakeCurrent(drawable.getDisplay(), - drawable.getSurface(), - drawable.getSurface(), - context)) { - throw new GLException("Error making context 0x" + - Long.toHexString(context) + " current: error code " + EGL.eglGetError()); + if (EGL.eglGetCurrentContext() != context) { + if (!EGL.eglMakeCurrent(drawable.getDisplay(), + drawable.getSurface(), + drawable.getSurface(), + context)) { + throw new GLException("Error making context 0x" + + Long.toHexString(context) + " current: error code " + EGL.eglGetError()); + } } if (created) { @@ -82,7 +83,38 @@ public class EGLContext extends GLContextImpl { return CONTEXT_CURRENT; } + protected int makeCurrentImpl() throws GLException { + if(EGL.EGL_NO_DISPLAY==drawable.getDisplay() ) { + System.err.println("drawable not properly initialized"); + return CONTEXT_NOT_CURRENT; + } + drawable.setSurface(); + + int lockRes = NativeWindow.LOCK_SUCCESS; + // FIXME: freezes AWT: int lockRes = drawable.lockSurface(); + boolean exceptionOccurred = false; + try { + if (lockRes == NativeWindow.LOCK_SURFACE_NOT_READY) { + return CONTEXT_NOT_CURRENT; + } + if (lockRes == NativeWindow.LOCK_SURFACE_CHANGED) { + destroyImpl(); + } + return makeCurrentImplInner(); + } catch (RuntimeException e) { + exceptionOccurred = true; + throw e; + } finally { + if (exceptionOccurred || + (isOptimizable() && lockRes != NativeWindow.LOCK_SURFACE_NOT_READY)) { + drawable.unlockSurface(); + } + } + } + protected void releaseImpl() throws GLException { + getGLDrawable().getFactory().lockToolkit(); + try { if (!EGL.eglMakeCurrent(drawable.getDisplay(), EGL.EGL_NO_SURFACE, EGL.EGL_NO_SURFACE, @@ -90,9 +122,15 @@ public class EGLContext extends GLContextImpl { throw new GLException("Error freeing OpenGL context 0x" + Long.toHexString(context) + ": error code " + EGL.eglGetError()); } + } finally { + getGLDrawable().getFactory().unlockToolkit(); + drawable.unlockSurface(); + } } protected void destroyImpl() throws GLException { + getGLDrawable().getFactory().lockToolkit(); + try { if (context != 0) { if (!EGL.eglDestroyContext(drawable.getDisplay(), context)) { throw new GLException("Error destroying OpenGL context 0x" + @@ -101,6 +139,9 @@ public class EGLContext extends GLContextImpl { context = 0; GLContextShareSet.contextDestroyed(this); } + } finally { + getGLDrawable().getFactory().unlockToolkit(); + } } protected void create() throws GLException { diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java index 034471b00..061a3eb38 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -40,8 +40,8 @@ import com.sun.opengl.impl.GLDrawableImpl; import javax.media.opengl.*; public class EGLDrawable extends GLDrawableImpl { - private long display; private GLCapabilitiesChooser chooser; + private long display; private _EGLConfig config; private long surface; private int[] tmp = new int[1]; @@ -50,9 +50,10 @@ public class EGLDrawable extends GLDrawableImpl { NativeWindow component, GLCapabilities capabilities, GLCapabilitiesChooser chooser) throws GLException { - super(factory, component, true); + super(factory, component, false); setChosenGLCapabilities(capabilities); this.chooser = chooser; + surface=EGL.EGL_NO_SURFACE; display = EGL.eglGetDisplay((component.getDisplayHandle()>0)?component.getDisplayHandle():EGL.EGL_DEFAULT_DISPLAY); if (display == EGL.EGL_NO_DISPLAY) { @@ -97,25 +98,28 @@ public class EGLDrawable extends GLDrawableImpl { return surface; } + protected void setSurface() { + if (EGL.EGL_NO_SURFACE==surface) { + try { + lockSurface(); + // Create the window surface + surface = EGL.eglCreateWindowSurface(display, config, component.getWindowHandle(), null); + if (EGL.EGL_NO_SURFACE==surface) { + throw new GLException("Creation of window surface (eglCreateWindowSurface) failed, component: "+component); + } + } finally { + unlockSurface(); + } + } + } + public GLContext createContext(GLContext shareWith) { return new EGLContext(this, shareWith); } public void setRealized(boolean realized) { if (realized) { - getFactory().lockToolkit(); - try { - lockSurface(); - - // Create the window surface - surface = EGL.eglCreateWindowSurface(display, config, component.getWindowHandle(), null); - } finally { - unlockSurface(); - getFactory().unlockToolkit(); - } - if (surface == EGL.EGL_NO_SURFACE) { - throw new GLException("Creation of window surface (eglCreateWindowSurface) failed, component: "+component); - } + // setSurface(); } else if( surface != EGL.EGL_NO_SURFACE ) { // Destroy the window surface // FIXME: we should expose a destroy() method on diff --git a/src/classes/com/sun/opengl/impl/egl/awt/EGLAWTDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/awt/EGLAWTDrawableFactory.java index e5d1387e8..501de1d01 100644 --- a/src/classes/com/sun/opengl/impl/egl/awt/EGLAWTDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/egl/awt/EGLAWTDrawableFactory.java @@ -44,11 +44,11 @@ public class EGLAWTDrawableFactory extends EGLDrawableFactory { public void lockToolkit() { super.lockToolkit(); - // freezes AWT: JAWTUtil.lockToolkit(); + //JAWTUtil.lockToolkit(); } public void unlockToolkit() { - // freezes AWT: JAWTUtil.unlockToolkit(); + //JAWTUtil.unlockToolkit(); super.unlockToolkit(); } |