aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-11-22 17:13:50 +0100
committerSven Gothel <[email protected]>2019-11-22 17:13:50 +0100
commit4b9754d210b22f32e5f083d3524da8f3d886bfb7 (patch)
treef238fbe9ae3f8cb7498baf10e4827c3e4d345c8a
parent29ec5eeccbe683e79106a44646c4ad99326609fa (diff)
Bug 1156: EGL-GBM: [Re]use EGL Platform type for eglCreatePlatformWindowSurface as well (like eglGetPlatformDisplay)
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java63
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLSurface.java38
2 files changed, 66 insertions, 35 deletions
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
index a2903e713..d5ab61e20 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
@@ -188,46 +188,65 @@ public class EGLDisplayUtil {
/* pp */ static synchronized void setSingletonEGLDisplayOnly(final boolean v) { useSingletonEGLDisplay = v; }
- private static synchronized long eglGetDisplay(final long nativeDisplay_id) {
- if( useSingletonEGLDisplay && null != singletonEGLDisplay ) {
- if(DEBUG) {
- System.err.println("EGLDisplayUtil.eglGetDisplay.s: eglDisplay("+EGLContext.toHexString(nativeDisplay_id)+"): "+
- EGLContext.toHexString(singletonEGLDisplay.eglDisplay)+
- ", "+((EGL.EGL_NO_DISPLAY != singletonEGLDisplay.eglDisplay)?"OK":"Failed")+", singletonEGLDisplay "+singletonEGLDisplay+" (use "+useSingletonEGLDisplay+")");
- }
- return singletonEGLDisplay.eglDisplay;
- }
+ /**
+ * @param useCustom see {@link NativeWindowFactory#getNativeWindowType(boolean)}
+ * @return the EGL platform type, e.g. {@link EGLExt#EGL_PLATFORM_X11_KHR} or {@link EGLExt#EGL_PLATFORM_GBM_KHR}
+ * @see NativeWindowFactory#getNativeWindowType(boolean)
+ * @see #getEGLPlatformType(String)
+ */
+ public static int getEGLPlatformType(final boolean useCustom) {
+ return getEGLPlatformType( NativeWindowFactory.getNativeWindowType(useCustom) );
+ }
- final String nativeWindowType = NativeWindowFactory.getNativeWindowType(false);
- final int platform;
- final long eglDisplay;
+ /**
+ * @param nativeWindowType return value of {@link NativeWindowFactory#getNativeWindowType(boolean)}
+ * @return the EGL platform type, e.g. {@link EGLExt#EGL_PLATFORM_X11_KHR} or {@link EGLExt#EGL_PLATFORM_GBM_KHR}
+ * @see NativeWindowFactory#getNativeWindowType(boolean)
+ * @see #getEGLPlatformType(boolean)
+ */
+ public static int getEGLPlatformType(final String nativeWindowType) {
+ final int eglPlatform;
switch( nativeWindowType ) {
case NativeWindowFactory.TYPE_X11:
- platform = EGLExt.EGL_PLATFORM_X11_KHR;
+ eglPlatform = EGLExt.EGL_PLATFORM_X11_KHR;
break;
case NativeWindowFactory.TYPE_ANDROID:
- platform = EGLExt.EGL_PLATFORM_ANDROID_KHR;
+ eglPlatform = EGLExt.EGL_PLATFORM_ANDROID_KHR;
break;
case NativeWindowFactory.TYPE_EGL_GBM:
- platform = EGLExt.EGL_PLATFORM_GBM_KHR; // same EGLExt.EGL_PLATFORM_GBM_MESA;
+ eglPlatform = EGLExt.EGL_PLATFORM_GBM_KHR; // same EGLExt.EGL_PLATFORM_GBM_MESA;
break;
case NativeWindowFactory.TYPE_WAYLAND:
// TODO
- platform = EGLExt.EGL_PLATFORM_WAYLAND_KHR;
+ eglPlatform = EGLExt.EGL_PLATFORM_WAYLAND_KHR;
break;
default:
- platform = 0;
+ eglPlatform = 0;
}
- if( 0 != platform ) {
- eglDisplay = EGL.eglGetPlatformDisplay(platform, nativeDisplay_id, null);
+ return eglPlatform;
+ }
+
+ private static synchronized long eglGetDisplay(final long nativeDisplay_id) {
+ if( useSingletonEGLDisplay && null != singletonEGLDisplay ) {
+ if(DEBUG) {
+ System.err.println("EGLDisplayUtil.eglGetDisplay.s: eglDisplay("+EGLContext.toHexString(nativeDisplay_id)+"): "+
+ EGLContext.toHexString(singletonEGLDisplay.eglDisplay)+
+ ", "+((EGL.EGL_NO_DISPLAY != singletonEGLDisplay.eglDisplay)?"OK":"Failed")+", singletonEGLDisplay "+singletonEGLDisplay+" (use "+useSingletonEGLDisplay+")");
+ }
+ return singletonEGLDisplay.eglDisplay;
}
- else{
- eglDisplay = EGL.eglGetDisplay(nativeDisplay_id);
+
+ final int eglPlatform = getEGLPlatformType(true);
+ final long eglDisplay;
+ if( 0 != eglPlatform ) {
+ eglDisplay = EGL.eglGetPlatformDisplay(eglPlatform, nativeDisplay_id, null);
+ } else {
+ eglDisplay = EGL.eglGetDisplay(nativeDisplay_id);
}
if(DEBUG) {
System.err.println("EGLDisplayUtil.eglGetDisplay.X: eglDisplay("+EGLContext.toHexString(nativeDisplay_id)+") @ "+
- platform+"/"+nativeWindowType+": "+
+ eglPlatform+"/"+NativeWindowFactory.getNativeWindowType(true)+": "+
EGLContext.toHexString(eglDisplay)+
", "+((EGL.EGL_NO_DISPLAY != eglDisplay)?"OK":"Failed")+", singletonEGLDisplay "+singletonEGLDisplay+" (use "+useSingletonEGLDisplay+")");
}
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLSurface.java b/src/jogl/classes/jogamp/opengl/egl/EGLSurface.java
index 8956bcbd9..20e067eac 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLSurface.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLSurface.java
@@ -31,6 +31,7 @@ import java.nio.IntBuffer;
import com.jogamp.nativewindow.NativeSurface;
import com.jogamp.nativewindow.NativeWindow;
+import com.jogamp.nativewindow.NativeWindowFactory;
import com.jogamp.nativewindow.ProxySurface;
import com.jogamp.nativewindow.UpstreamSurfaceHook;
import com.jogamp.opengl.GLCapabilitiesImmutable;
@@ -93,14 +94,14 @@ public class EGLSurface extends WrappedSurface {
}
public void setEGLSurfaceHandle() throws GLException {
- setSurfaceHandle( createEGLSurfaceHandle() );
+ setSurfaceHandle( createEGLSurface() );
}
- private long createEGLSurfaceHandle() throws GLException {
+ private long createEGLSurface() throws GLException {
final EGLGraphicsConfiguration config = (EGLGraphicsConfiguration) getGraphicsConfiguration();
final NativeSurface nativeSurface = getUpstreamSurface();
final boolean isPBuffer = ((GLCapabilitiesImmutable) config.getChosenCapabilities()).isPBuffer();
- long eglSurface = createEGLSurfaceHandle(isPBuffer, true /* useSurfaceHandle */, config, nativeSurface);
+ long eglSurface = createEGLSurface(isPBuffer, true /* useNativeSurface */, config, nativeSurface);
if( DEBUG ) {
System.err.println(getThreadName() + ": EGLSurface: EGL.eglCreateSurface.0: 0x"+Long.toHexString(eglSurface));
ProxySurfaceImpl.dumpHierarchy(System.err, this);
@@ -112,7 +113,7 @@ public class EGLSurface extends WrappedSurface {
// Try window handle if available and differs (Windows HDC / HWND).
// ANGLE impl. required HWND on Windows.
if( hasUniqueNativeWindowHandle(nativeSurface) ) {
- eglSurface = createEGLSurfaceHandle(isPBuffer, false /* useSurfaceHandle */, config, nativeSurface);
+ eglSurface = createEGLSurface(isPBuffer, false /* useNativeSurface */, config, nativeSurface);
if( DEBUG ) {
System.err.println(getThreadName() + ": Info: Creation of window surface w/ surface handle failed: "+config+", error "+GLDrawableImpl.toHexString(eglError0)+", retry w/ windowHandle");
System.err.println(getThreadName() + ": EGLSurface: EGL.eglCreateSurface.1: 0x"+Long.toHexString(eglSurface));
@@ -132,20 +133,31 @@ public class EGLSurface extends WrappedSurface {
}
return eglSurface;
}
- private long createEGLSurfaceHandle(final boolean isPBuffer, final boolean useSurfaceHandle,
- final EGLGraphicsConfiguration config, final NativeSurface nativeSurface) {
+ private long createEGLSurface(final boolean isPBuffer, final boolean useNativeSurface,
+ final EGLGraphicsConfiguration config, final NativeSurface nativeSurface) {
if( isPBuffer ) {
return EGLDrawableFactory.createPBufferSurfaceImpl(config, getSurfaceWidth(), getSurfaceHeight(), false);
} else {
- if( useSurfaceHandle ) {
- return EGL.eglCreateWindowSurface(config.getScreen().getDevice().getHandle(),
- config.getNativeConfig(),
- nativeSurface.getSurfaceHandle(), null);
+ final int eglPlatform = EGLDisplayUtil.getEGLPlatformType(true);
+ final long eglNativeWin = useNativeSurface ? nativeSurface.getSurfaceHandle() : ((NativeWindow)nativeSurface).getWindowHandle();
+ final long eglSurface;
+ if( 0 != eglPlatform ) {
+ eglSurface = EGL.eglCreatePlatformWindowSurface(config.getScreen().getDevice().getHandle(),
+ config.getNativeConfig(),
+ eglNativeWin, null);
} else {
- return EGL.eglCreateWindowSurface(config.getScreen().getDevice().getHandle(),
- config.getNativeConfig(),
- ((NativeWindow)nativeSurface).getWindowHandle(), null);
+ eglSurface = EGL.eglCreateWindowSurface(config.getScreen().getDevice().getHandle(),
+ config.getNativeConfig(),
+ eglNativeWin, null);
}
+ if(DEBUG) {
+ System.err.println("EGLSurface.createEGLSurface.X: useNativeSurface "+useNativeSurface+
+ ", nativeWin "+EGLContext.toHexString(eglNativeWin)+") @ "+
+ eglPlatform+"/"+NativeWindowFactory.getNativeWindowType(true)+": "+
+ EGLContext.toHexString(eglSurface)+
+ ", "+((EGL.EGL_NO_SURFACE != eglSurface)?"OK":"Failed"));
+ }
+ return eglSurface;
}
}
private static boolean hasUniqueNativeWindowHandle(final NativeSurface nativeSurface) {