aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-02-22 17:30:56 +0100
committerSven Gothel <[email protected]>2012-02-22 17:30:56 +0100
commit7085c11e493e5a7bbe56a602a3252f4e28c2f974 (patch)
tree62032e7c4a7ce14d3a5a3c8c2b4964dbc87a4577 /src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
parenta5a3d0dfa2c8c7e1e68dc4b066dda1011f471606 (diff)
EGL Display Lifecycle Robustness Patch (impl. workaround)
Added EGLDisplayUtil helper class managing the lifecycle of the EGL display handle recursively. This class is required, due to implementation bugs within EGL where EGL.eglTerminate(long) does not mark the resource for deletion when still in use, bug releases them immediatly. This fixes unit test com.jogamp.opengl.test.junit.jogl.acore.TestInitConcurrentNEWT on Linux ARM w/ Omap4 and Tegra2.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java')
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
new file mode 100644
index 000000000..207a8e674
--- /dev/null
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright 2012 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package jogamp.opengl.egl;
+
+import java.nio.IntBuffer;
+
+import jogamp.opengl.Debug;
+
+import com.jogamp.common.util.LongIntHashMap;
+
+/**
+ * This implementation provides recursive calls to
+ * {@link EGL#eglInitialize(long, IntBuffer, IntBuffer)} and {@link EGL#eglTerminate(long)},
+ * where <code>eglInitialize(..)</code> is issued only for the 1st call per <code>eglDisplay</code>
+ * and <code>eglTerminate(..)</code> is issued only for the last call.
+ * <p>
+ * This class is required, due to implementation bugs within EGL where {@link EGL#eglTerminate(long)}
+ * does not mark the resource for deletion when still in use, bug releases them immediatly.
+ * </p>
+ */
+public class EGLDisplayUtil {
+ protected static final boolean DEBUG = Debug.debug("EGL");
+
+ static LongIntHashMap eglDisplayCounter;
+
+ static {
+ eglDisplayCounter = new LongIntHashMap();
+ eglDisplayCounter.setKeyNotFoundValue(0);
+ }
+
+ public static long eglGetDisplay(long nativeDisplay_id) {
+ return EGL.eglGetDisplay(nativeDisplay_id);
+ }
+
+ public static synchronized boolean eglInitialize(long eglDisplay, int[] major, int major_offset, int[] minor, int minor_offset) {
+ final boolean res;
+ final int refCnt = eglDisplayCounter.get(eglDisplay) + 1; // 0 + 1 = 1 -> 1st init
+ if(1==refCnt) {
+ res = EGL.eglInitialize(eglDisplay, major, major_offset, minor, minor_offset);
+ } else {
+ res = true;
+ }
+ eglDisplayCounter.put(eglDisplay, refCnt);
+ if(DEBUG) {
+ System.err.println("EGL.eglInitialize(0x"+Long.toHexString(eglDisplay)+" ...): #"+refCnt+" = "+res);
+ }
+ return res;
+ }
+
+ public static synchronized boolean eglInitialize(long eglDisplay, IntBuffer major, IntBuffer minor) {
+ final boolean res;
+ final int refCnt = eglDisplayCounter.get(eglDisplay) + 1; // 0 + 1 = 1 -> 1st init
+ if(1==refCnt) { // only initialize once
+ res = EGL.eglInitialize(eglDisplay, major, minor);
+ } else {
+ res = true;
+ }
+ eglDisplayCounter.put(eglDisplay, refCnt);
+ if(DEBUG) {
+ System.err.println("EGL.eglInitialize(0x"+Long.toHexString(eglDisplay)+" ...): #"+refCnt+" = "+res);
+ }
+ return res;
+ }
+
+ public static synchronized boolean eglTerminate(long eglDisplay) {
+ final boolean res;
+ final int refCnt = eglDisplayCounter.get(eglDisplay) - 1; // 1 - 1 = 0 -> final terminate
+ if(0==refCnt) { // no terminate if still in use or already terminated
+ res = EGL.eglTerminate(eglDisplay);
+ } else {
+ res = true;
+ }
+ if(0<=refCnt) { // no negative refCount
+ eglDisplayCounter.put(eglDisplay, refCnt);
+ }
+ if(DEBUG) {
+ System.err.println("EGL.eglTerminate(0x"+Long.toHexString(eglDisplay)+" ...): #"+refCnt+" = "+res);
+ }
+ return res;
+ }
+}