From da0391975092bbd1adce296477646b004c3562c3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 9 Aug 2011 20:17:11 +0200 Subject: EGL Fixes ... - EGLDrawableFactory: createProxySurfaceImpl: add proper config choosing - EGLCapabilities/EGLGraphicsConfiguration: Add nativeVisualID - All: Avoid critical array access -> use NIO --- .../classes/jogamp/opengl/egl/EGLDrawable.java | 2 - .../jogamp/opengl/egl/EGLDrawableFactory.java | 11 ++- .../jogamp/opengl/egl/EGLGLCapabilities.java | 6 +- .../opengl/egl/EGLGraphicsConfiguration.java | 92 +++++++++++++--------- .../egl/EGLGraphicsConfigurationFactory.java | 45 +++++------ 5 files changed, 91 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java index 4ab311479..a9cc40335 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java @@ -127,8 +127,6 @@ public abstract class EGLDrawable extends GLDrawableImpl { } else { // EGLSurface is ours .. ownEGLSurface=true; - - // redundant, already a proper chosen EGLCapabilities eglConfig.updateGraphicsConfiguration(); recreateSurface(); } } else { diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java index 509ef1f99..e0283abd7 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java @@ -44,7 +44,6 @@ import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.util.*; import jogamp.opengl.*; -import jogamp.opengl.x11.glx.X11GLXContext; import jogamp.nativewindow.WrappedSurface; import java.util.HashMap; @@ -276,10 +275,14 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { return ns; } - protected ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice device, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { - WrappedSurface ns = new WrappedSurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsRequested, capsRequested, chooser), windowHandle); + protected ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice adevice, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + // FIXME device/windowHandle -> screen ?! + EGLGraphicsDevice device = (EGLGraphicsDevice) adevice; + DefaultGraphicsScreen screen = new DefaultGraphicsScreen(device, 0); + EGLGraphicsConfiguration cfg = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsRequested, capsRequested, chooser, screen); + WrappedSurface ns = new WrappedSurface(cfg, windowHandle); return ns; - } + } protected GLContext createExternalGLContextImpl() { AbstractGraphicsScreen absScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_EGL); diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java b/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java index 1ec27c36c..ab332e659 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java @@ -37,7 +37,8 @@ public class EGLGLCapabilities extends GLCapabilities { final long eglcfg; final int eglcfgid; final int renderableType; - + int nativeVisualID; + /** Comparing EGLConfig ID only */ public static class EglCfgIDComparator implements Comparator { @@ -101,6 +102,8 @@ public class EGLGLCapabilities extends GLCapabilities { final public long getEGLConfig() { return eglcfg; } final public int getEGLConfigID() { return eglcfgid; } final public int getRenderableType() { return renderableType; } + final public void setNativeVisualID(int vid) { nativeVisualID=vid; } + final public int getNativeVisualID() { return nativeVisualID; } public static boolean isCompatible(GLProfile glp, int renderableType) { if(null == glp) { @@ -157,6 +160,7 @@ public class EGLGLCapabilities extends GLCapabilities { } // sink.append("0x").append(Long.toHexString(eglcfg)).append(", "); sink.append("0x").append(Long.toHexString(eglcfgid)).append(": "); + sink.append("vid 0x").append(Integer.toHexString(nativeVisualID)).append(", "); super.toString(sink); sink.append(", ["); renderableTypeToString(sink, renderableType); diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java index 17f4d2b2e..1eda2fb7a 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java @@ -36,10 +36,13 @@ package jogamp.opengl.egl; +import java.nio.IntBuffer; import java.util.ArrayList; import javax.media.nativewindow.*; import javax.media.nativewindow.egl.*; import javax.media.opengl.*; + +import com.jogamp.common.nio.Buffers; import com.jogamp.common.nio.PointerBuffer; import jogamp.opengl.*; @@ -149,83 +152,100 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple GLProfile glp, long display, long config, int winattrmask) { final int allDrawableTypeBits = EGLConfigDrawableTypeBits(display, config); - final int drawableTypeBits = winattrmask & allDrawableTypeBits; + int drawableTypeBits = winattrmask & allDrawableTypeBits; if( 0 == drawableTypeBits ) { return false; } - int[] cfgID = new int[1]; - int[] rType = new int[1]; - + final IntBuffer val = Buffers.newDirectIntBuffer(1); + int cfgID; + int rType; + // get the configID - if(!EGL.eglGetConfigAttrib(display, config, EGL.EGL_CONFIG_ID, cfgID, 0)) { + if(!EGL.eglGetConfigAttrib(display, config, EGL.EGL_CONFIG_ID, val)) { if(DEBUG) { // FIXME: this happens on a ATI PC Emulation .. System.err.println("EGL couldn't retrieve ConfigID for config "+toHexString(config)+", error "+toHexString(EGL.eglGetError())); } return false; } + cfgID = val.get(0); - if(!EGL.eglGetConfigAttrib(display, config, EGL.EGL_RENDERABLE_TYPE, rType, 0)) { + if(!EGL.eglGetConfigAttrib(display, config, EGL.EGL_RENDERABLE_TYPE, val)) { if(DEBUG) { System.err.println("EGL couldn't retrieve EGL_RENDERABLE_TYPE for config "+toHexString(config)+", error "+toHexString(EGL.eglGetError())); } return false; } + rType = val.get(0); + EGLGLCapabilities caps = null; try { - caps = new EGLGLCapabilities(config, cfgID[0], glp, rType[0]); + caps = new EGLGLCapabilities(config, cfgID, glp, rType); } catch (GLException gle) { if(DEBUG) { System.err.println("config "+toHexString(config)+": "+gle); } return false; - } - - int[] val = new int[1]; - + } + // Read the actual configuration into the chosen caps - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_RED_SIZE, val, 0)) { - caps.setRedBits(val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_NATIVE_VISUAL_ID, val)) { + caps.setNativeVisualID(val.get(0)); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_RED_SIZE, val)) { + caps.setRedBits(val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_GREEN_SIZE, val, 0)) { - caps.setGreenBits(val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_GREEN_SIZE, val)) { + caps.setGreenBits(val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_BLUE_SIZE, val, 0)) { - caps.setBlueBits(val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_BLUE_SIZE, val)) { + caps.setBlueBits(val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_ALPHA_SIZE, val, 0)) { - caps.setAlphaBits(val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_ALPHA_SIZE, val)) { + caps.setAlphaBits(val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_STENCIL_SIZE, val, 0)) { - caps.setStencilBits(val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_STENCIL_SIZE, val)) { + caps.setStencilBits(val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_DEPTH_SIZE, val, 0)) { - caps.setDepthBits(val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_DEPTH_SIZE, val)) { + caps.setDepthBits(val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_SAMPLES, val, 0)) { - caps.setSampleBuffers(val[0]>0?true:false); - caps.setNumSamples(val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_SAMPLES, val)) { + caps.setSampleBuffers(val.get(0)>0?true:false); + caps.setNumSamples(val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_TYPE, val, 0)) { - caps.setBackgroundOpaque(val[0] != EGL.EGL_TRANSPARENT_RGB); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_TYPE, val)) { + caps.setBackgroundOpaque(val.get(0) != EGL.EGL_TRANSPARENT_RGB); } if(!caps.isBackgroundOpaque()) { - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_RED_VALUE, val, 0)) { - caps.setTransparentRedValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_RED_VALUE, val)) { + caps.setTransparentRedValue(val.get(0)==EGL.EGL_DONT_CARE?-1:val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_GREEN_VALUE, val, 0)) { - caps.setTransparentGreenValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_GREEN_VALUE, val)) { + caps.setTransparentGreenValue(val.get(0)==EGL.EGL_DONT_CARE?-1:val.get(0)); } - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_BLUE_VALUE, val, 0)) { - caps.setTransparentBlueValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_BLUE_VALUE, val)) { + caps.setTransparentBlueValue(val.get(0)==EGL.EGL_DONT_CARE?-1:val.get(0)); } /** Not defined in EGL - if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_ALPHA_VALUE, val, 0)) { - caps.setTransparentAlphaValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_ALPHA_VALUE, val)) { + caps.setTransparentAlphaValue(val.get(0)==EGL.EGL_DONT_CARE?-1:val.get(0)); } */ } + /** + if(caps.getNativeVisualID() == 0) { + boolean isWindowBit = 0 != ( drawableTypeBits & GLGraphicsConfigurationUtil.WINDOW_BIT ); + drawableTypeBits &= ~GLGraphicsConfigurationUtil.WINDOW_BIT; + if( 0 == drawableTypeBits ) { + if(DEBUG) { + System.err.println("EGL_NATIVE_VISUAL_ID: 0, windowBit removed: "+isWindowBit+ + ", no drawable bits left, bail out for: "+ caps); + } + return false; + } + } */ return GLGraphicsConfigurationUtil.addGLCapabilitiesPermutations(capsBucket, caps, drawableTypeBits ); } diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java index 70ad842f8..3154818db 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java @@ -49,13 +49,16 @@ import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; import javax.media.opengl.GLDrawableFactory; +import com.jogamp.common.nio.Buffers; import com.jogamp.common.nio.PointerBuffer; + import jogamp.opengl.GLGraphicsConfigurationFactory; import jogamp.opengl.GLGraphicsConfigurationUtil; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.io.PrintStream; +import java.nio.IntBuffer; /** Subclass of GraphicsConfigurationFactory used when non-AWT tookits @@ -106,23 +109,22 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact long eglDisplay = eglDevice.getHandle(); List/**/ availableCaps = null; - int[] maxConfigs = new int[1]; + IntBuffer numConfigs = Buffers.newDirectIntBuffer(1); - if(!EGL.eglGetConfigs(eglDisplay, null, 0, maxConfigs, 0)) { + if(!EGL.eglGetConfigs(eglDisplay, null, 0, numConfigs)) { throw new GLException("Graphics configuration get maxConfigs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); } - if(0 == maxConfigs[0]) { + if(0 == numConfigs.get(0)) { throw new GLException("Graphics configuration get maxConfigs (eglGetConfigs) no configs"); } - PointerBuffer configs = PointerBuffer.allocateDirect(maxConfigs[0]); - int[] numConfigs = new int[1]; + PointerBuffer configs = PointerBuffer.allocateDirect(numConfigs.get(0)); - if(!EGL.eglGetConfigs(eglDisplay, configs, configs.capacity(), numConfigs, 0)) { + if(!EGL.eglGetConfigs(eglDisplay, configs, configs.capacity(), numConfigs)) { throw new GLException("Graphics configuration get all configs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); } - if (numConfigs[0] > 0) { - availableCaps = eglConfigs2GLCaps(null, eglDisplay, configs, numConfigs[0], GLGraphicsConfigurationUtil.ALL_BITS); + if (numConfigs.get(0) > 0) { + availableCaps = eglConfigs2GLCaps(null, eglDisplay, configs, numConfigs.get(0), GLGraphicsConfigurationUtil.ALL_BITS); if( null != availableCaps && availableCaps.size() > 1) { Collections.sort(availableCaps, EglCfgIDComparator); } @@ -131,7 +133,7 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact return availableCaps; } - private static EGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilitiesImmutable capsChosen, + /*package*/ static EGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsReq, GLCapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { @@ -229,30 +231,29 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact List/**/ availableCaps = null; int recommendedIndex = -1; long recommendedEGLConfig = -1; - int[] maxConfigs = new int[1]; + IntBuffer numConfigs = Buffers.newDirectIntBuffer(1); - if(!EGL.eglGetConfigs(eglDisplay, null, 0, maxConfigs, 0)) { + if(!EGL.eglGetConfigs(eglDisplay, null, 0, numConfigs)) { throw new GLException("EGLGraphicsConfiguration.eglChooseConfig: Get maxConfigs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); } - if(0 == maxConfigs[0]) { + if(0 == numConfigs.get(0)) { throw new GLException("EGLGraphicsConfiguration.eglChooseConfig: Get maxConfigs (eglGetConfigs) no configs"); } if (DEBUG) { - System.err.println("EGLGraphicsConfiguration.eglChooseConfig: eglChooseConfig maxConfigs: "+maxConfigs[0]); + System.err.println("EGLGraphicsConfiguration.eglChooseConfig: eglChooseConfig maxConfigs: "+numConfigs.get(0)); System.err.println("EGLGraphicsConfiguration.eglChooseConfig: eglDisplay "+toHexString(eglDisplay)+", "+capsChosen); } - final int[] attrs = EGLGraphicsConfiguration.GLCapabilities2AttribList(capsChosen); - PointerBuffer configs = PointerBuffer.allocateDirect(maxConfigs[0]); - int[] numConfigs = new int[1]; + final IntBuffer attrs = Buffers.newDirectIntBuffer(EGLGraphicsConfiguration.GLCapabilities2AttribList(capsChosen)); + PointerBuffer configs = PointerBuffer.allocateDirect(numConfigs.get(0)); // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice - if( ! EGL.eglChooseConfig(eglDisplay, attrs, 0, configs, configs.capacity(), numConfigs, 0) ) { + if( ! EGL.eglChooseConfig(eglDisplay, attrs, configs, configs.capacity(), numConfigs) ) { if(DEBUG) { System.err.println("EGLGraphicsConfiguration.eglChooseConfig: #1 eglChooseConfig: false"); } - } else if (numConfigs[0] > 0) { - availableCaps = eglConfigs2GLCaps(glp, eglDisplay, configs, numConfigs[0], winattrmask); + } else if (numConfigs.get(0) > 0) { + availableCaps = eglConfigs2GLCaps(glp, eglDisplay, configs, numConfigs.get(0), winattrmask); if(availableCaps.size() > 0) { recommendedEGLConfig = configs.get(0); recommendedIndex = 0; @@ -273,11 +274,11 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact recommendedEGLConfig = -1; recommendedIndex = -1; - if(!EGL.eglGetConfigs(eglDisplay, configs, configs.capacity(), numConfigs, 0)) { + if(!EGL.eglGetConfigs(eglDisplay, configs, configs.capacity(), numConfigs)) { throw new GLException("EGLGraphicsConfiguration.eglChooseConfig: #2 Get all configs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); } - if (numConfigs[0] > 0) { - availableCaps = eglConfigs2GLCaps(glp, eglDisplay, configs, numConfigs[0], winattrmask); + if (numConfigs.get(0) > 0) { + availableCaps = eglConfigs2GLCaps(glp, eglDisplay, configs, numConfigs.get(0), winattrmask); } } -- cgit v1.2.3