diff options
author | Sven Gothel <[email protected]> | 2014-03-10 22:14:34 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-03-10 22:14:34 +0100 |
commit | fdd60adb1d421f2018b47ee17e9079c94b54910f (patch) | |
tree | 3be9345319ed6cccfe77b38e444dd92b2b4dba5c /make/config/jogl/glx-CustomCCode.c | |
parent | 132f6fe9eeada4321d776d6332482854c82f24e2 (diff) |
Bug 961: Stabilize glXGetFBConfigAttrib(..) and glXChooseFBConfig(..) Usage Against OpenGL Bugs ; Fix glXGetFBConfigs
- glXChooseFBConfig(..)
- Remove NULL FBConfig pointer from result in native code,
which has been observed in Mesa 8.0.5-4 libgl1-mesa-swx11 (Debian-7).
- glXGetFBConfigs
- Add manual implementation similar to glXChooseFBConfig
- glXGetFBConfigAttrib(..)
- glXGetFBConfig(..)
- Returns boolean reflecting success, don't throw exception - caller handles error
- Caller ignore failure if not essential (i.e. already chosen config)
Diffstat (limited to 'make/config/jogl/glx-CustomCCode.c')
-rw-r--r-- | make/config/jogl/glx-CustomCCode.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/make/config/jogl/glx-CustomCCode.c b/make/config/jogl/glx-CustomCCode.c index 5c73dfea6..3f5cf1121 100644 --- a/make/config/jogl/glx-CustomCCode.c +++ b/make/config/jogl/glx-CustomCCode.c @@ -12,6 +12,8 @@ #define RTLD_DEFAULT NULL #endif +#include <string.h> + /* We expect glXGetProcAddressARB to be defined */ extern void (*glXGetProcAddressARB(const GLubyte *procname))(); @@ -124,7 +126,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseFBConfig(JNIEnv *env, jclass _ int * _attribList_ptr = NULL; int * _nitems_ptr = NULL; GLXFBConfig * _res; - int count; + int count, i; jobject jbyteSource; jobject jbyteCopy; if ( NULL != attribList ) { @@ -139,6 +141,65 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseFBConfig(JNIEnv *env, jclass _ count = _nitems_ptr[0]; if (NULL == _res) return NULL; + /** Bug 961: Validate returned 'GLXFBConfig *', i.e. remove NULL pointer. */ + // fprintf(stderr, "glXChooseFBConfig.0: Count %d\n", count); + i=0; + while( i < count ) { + if( NULL == _res[i] ) { + if( 0 < count-i-1 ) { + memmove(_res+i, _res+i+1, count-i-1); + } + count--; + } else { + i++; + } + } + // fprintf(stderr, "glXChooseFBConfig.X: Count %d\n", count); + _initClazzAccess(env); + + jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(GLXFBConfig)); + jbyteCopy = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffers, jbyteSource); + (*env)->DeleteLocalRef(env, jbyteSource); + XFree(_res); + + return jbyteCopy; +} + +/* Java->C glue code: + * Java package: jogamp.opengl.x11.glx.GLX + * Java method: com.jogamp.common.nio.PointerBuffer dispatch_glXGetFBConfigs(long dpy, int screen, java.nio.IntBuffer nelements) + * C function: GLXFBConfig * glXGetFBConfigs(Display * dpy, int screen, int * nelements); + */ +JNIEXPORT jobject JNICALL +Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetFBConfigs(JNIEnv *env, jclass _unused, jlong dpy, jint screen, jobject nelements, jint nelements_byte_offset, jlong procAddress) { + typedef GLXFBConfig * (APIENTRY*_local_PFNGLXGETFBCONFIGSPROC)(Display * dpy, int screen, int * nelements); + _local_PFNGLXGETFBCONFIGSPROC ptr_glXGetFBConfigs; + int * _nelements_ptr = NULL; + GLXFBConfig * _res; + int count, i; + jobject jbyteSource; + jobject jbyteCopy; + if ( NULL != nelements ) { + _nelements_ptr = (int *) (((char*) (*env)->GetDirectBufferAddress(env, nelements)) + nelements_byte_offset); + } + ptr_glXGetFBConfigs = (_local_PFNGLXGETFBCONFIGSPROC) (intptr_t) procAddress; + assert(ptr_glXGetFBConfigs != NULL); + _res = (* ptr_glXGetFBConfigs) ((Display *) (intptr_t) dpy, (int) screen, (int *) _nelements_ptr); + count = _nelements_ptr[0]; + if (NULL == _res) return NULL; + + /** Bug 961: Validate returned 'GLXFBConfig *', i.e. remove NULL pointer. */ + i=0; + while( i < count ) { + if( NULL == _res[i] ) { + if( 0 < count-i-1 ) { + memmove(_res+i, _res+i+1, count-i-1); + } + count--; + } else { + i++; + } + } _initClazzAccess(env); jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(GLXFBConfig)); |