diff options
author | Jack Palevich <> | 2009-03-24 22:48:26 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-24 22:48:26 -0700 |
commit | 4c7533cfc81a0dda4c25355e86558199accab3ea (patch) | |
tree | cf422c41de1377eb09736edd83b8aabd196da5fa | |
parent | 7d1e577d5f7ae96bfc533e1c73a3a6a272a4a16d (diff) | |
download | frameworks_base-4c7533cfc81a0dda4c25355e86558199accab3ea.zip frameworks_base-4c7533cfc81a0dda4c25355e86558199accab3ea.tar.gz frameworks_base-4c7533cfc81a0dda4c25355e86558199accab3ea.tar.bz2 |
Automated import from //branches/donutburger/...@142484,142484
-rw-r--r-- | core/jni/com_google_android_gles_jni_EGLImpl.cpp | 305 | ||||
-rw-r--r-- | opengl/libagl/egl.cpp | 24 | ||||
-rw-r--r-- | opengl/libs/EGL/egl.cpp | 35 |
3 files changed, 231 insertions, 133 deletions
diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp index fbbd852..4452065 100644 --- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp +++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp @@ -2,16 +2,16 @@ ** ** Copyright 2006, The Android Open Source Project ** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at ** -** http://www.apache.org/licenses/LICENSE-2.0 +** http://www.apache.org/licenses/LICENSE-2.0 ** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and ** limitations under the License. */ @@ -89,7 +89,7 @@ static void nativeClassInit(JNIEnv *_env, jclass eglImplClass) gConfig_class = make_globalref(_env, "com/google/android/gles_jni/EGLConfigImpl"); gConfig_ctorID = _env->GetMethodID(gConfig_class, "<init>", "(I)V"); - + gDisplay_EGLDisplayFieldID = _env->GetFieldID(gDisplay_class, "mEGLDisplay", "I"); gContext_EGLContextFieldID = _env->GetFieldID(gContext_class, "mEGLContext", "I"); gSurface_EGLSurfaceFieldID = _env->GetFieldID(gSurface_class, "mEGLSurface", "I"); @@ -100,12 +100,46 @@ static void nativeClassInit(JNIEnv *_env, jclass eglImplClass) gSurface_SurfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I"); jclass bitmap_class = _env->FindClass("android/graphics/Bitmap"); - gBitmap_NativeBitmapFieldID = _env->GetFieldID(bitmap_class, "mNativeBitmap", "I"); + gBitmap_NativeBitmapFieldID = _env->GetFieldID(bitmap_class, "mNativeBitmap", "I"); +} + +static const jint gNull_attrib_base[] = {EGL_NONE}; + +static bool validAttribList(JNIEnv *_env, jintArray attrib_list) { + if (attrib_list == NULL) { + return true; + } + jsize len = _env->GetArrayLength(attrib_list); + if (len < 1) { + return false; + } + jint item = 0; + _env->GetIntArrayRegion(attrib_list, len-1, 1, &item); + return item == EGL_NONE; +} + +static jint* beginNativeAttribList(JNIEnv *_env, jintArray attrib_list) { + if (attrib_list != NULL) { + return (jint *)_env->GetPrimitiveArrayCritical(attrib_list, (jboolean *)0); + } else { + return(jint*) gNull_attrib_base; + } } -jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display, +static void endNativeAttributeList(JNIEnv *_env, jintArray attrib_list, jint* attrib_base) { + if (attrib_list != NULL) { + _env->ReleasePrimitiveArrayCritical(attrib_list, attrib_base, JNI_ABORT); + } +} + +static jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display, jintArray major_minor) { - + if (display == NULL || (major_minor != NULL && + _env->GetArrayLength(major_minor) < 2)) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } + EGLDisplay dpy = getDisplay(_env, display); jboolean success = eglInitialize(dpy, NULL, NULL); if (success && major_minor) { @@ -121,14 +155,15 @@ jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display, return success; } -jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display, +static jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display, jobject context, jint attribute, jintArray value) { - EGLDisplay dpy = getDisplay(_env, display); - EGLContext ctx = getContext(_env, context); - if (value == NULL) { - doThrow(_env, "java/lang/NullPointerException"); + if (display == NULL || context == NULL || value == NULL + || _env->GetArrayLength(value) < 1) { + doThrow(_env, "java/lang/IllegalArgumentException"); return JNI_FALSE; } + EGLDisplay dpy = getDisplay(_env, display); + EGLContext ctx = getContext(_env, context); jboolean success = JNI_FALSE; int len = _env->GetArrayLength(value); if (len) { @@ -138,15 +173,17 @@ jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display, } return success; } - -jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display, + +static jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface, jint attribute, jintArray value) { - EGLDisplay dpy = getDisplay(_env, display); - EGLContext sur = getSurface(_env, surface); - if (value == NULL) { - doThrow(_env, "java/lang/NullPointerException"); + if (display == NULL || surface == NULL || value == NULL + || _env->GetArrayLength(value) < 1) { + doThrow(_env, "java/lang/IllegalArgumentException"); return JNI_FALSE; } + EGLDisplay dpy = getDisplay(_env, display); + EGLContext sur = getSurface(_env, surface); + jboolean success = JNI_FALSE; int len = _env->GetArrayLength(value); if (len) { @@ -157,60 +194,69 @@ jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display, return success; } -jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display, - jintArray attrib_list, jobjectArray configs, jint config_size, jintArray num_config) { - EGLDisplay dpy = getDisplay(_env, display); - if (attrib_list==NULL || configs==NULL || num_config==NULL) { - doThrow(_env, "java/lang/NullPointerException"); +static jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display, + jintArray attrib_list, jobjectArray configs, jint config_size, jintArray num_config) { + if (display == NULL + || !validAttribList(_env, attrib_list) + || (configs != NULL && _env->GetArrayLength(configs) < config_size) + || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) { + doThrow(_env, "java/lang/IllegalArgumentException"); return JNI_FALSE; } + EGLDisplay dpy = getDisplay(_env, display); jboolean success = JNI_FALSE; - jint* attrib_base = (jint *)_env->GetPrimitiveArrayCritical(attrib_list, (jboolean *)0); - jint* num_base = (jint *)_env->GetPrimitiveArrayCritical(num_config, (jboolean *)0); + + if (configs == NULL) { + config_size = 0; + } EGLConfig nativeConfigs[config_size]; - success = eglChooseConfig(dpy, attrib_base, nativeConfigs, config_size, num_base); - int num = num_base[0]; - _env->ReleasePrimitiveArrayCritical(num_config, num_base, JNI_ABORT); - _env->ReleasePrimitiveArrayCritical(attrib_list, attrib_base, JNI_ABORT); - if (success) { + + int num = 0; + jint* attrib_base = beginNativeAttribList(_env, attrib_list); + success = eglChooseConfig(dpy, attrib_base, configs ? nativeConfigs : 0, config_size, &num); + endNativeAttributeList(_env, attrib_list, attrib_base); + + if (num_config != NULL) { + _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num); + } + + if (success && configs!=NULL) { for (int i=0 ; i<num ; i++) { jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, (jint)nativeConfigs[i]); _env->SetObjectArrayElement(configs, i, obj); } } return success; -} +} -jint jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display, +static jint jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display, jobject config, jobject share_context, jintArray attrib_list) { + if (display == NULL || config == NULL || share_context == NULL + || !validAttribList(_env, attrib_list)) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); EGLConfig cnf = getConfig(_env, config); EGLContext shr = getContext(_env, share_context); - jint* base = 0; - if (attrib_list) { - // XXX: if array is malformed, we should return an NPE instead of segfault - base = (jint *)_env->GetPrimitiveArrayCritical(attrib_list, (jboolean *)0); - } + jint* base = beginNativeAttribList(_env, attrib_list); EGLContext ctx = eglCreateContext(dpy, cnf, shr, base); - if (attrib_list) { - _env->ReleasePrimitiveArrayCritical(attrib_list, base, JNI_ABORT); - } + endNativeAttributeList(_env, attrib_list, base); return (jint)ctx; } -jint jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display, +static jint jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display, jobject config, jintArray attrib_list) { + if (display == NULL || config == NULL + || !validAttribList(_env, attrib_list)) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); EGLConfig cnf = getConfig(_env, config); - jint* base = 0; - if (attrib_list) { - // XXX: if array is malformed, we should return an NPE instead of segfault - base = (jint *)_env->GetPrimitiveArrayCritical(attrib_list, (jboolean *)0); - } + jint* base = beginNativeAttribList(_env, attrib_list); EGLSurface sur = eglCreatePbufferSurface(dpy, cnf, base); - if (attrib_list) { - _env->ReleasePrimitiveArrayCritical(attrib_list, base, JNI_ABORT); - } + endNativeAttributeList(_env, attrib_list, base); return (jint)sur; } @@ -225,10 +271,15 @@ static PixelFormat convertPixelFormat(SkBitmap::Config format) } } -void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur, +static void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur, jobject display, jobject config, jobject native_pixmap, - jintArray attrib_list) + jintArray attrib_list) { + if (display == NULL || config == NULL || native_pixmap == NULL + || !validAttribList(_env, attrib_list)) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return; + } EGLDisplay dpy = getDisplay(_env, display); EGLConfig cnf = getConfig(_env, config); jint* base = 0; @@ -238,13 +289,13 @@ void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur, gBitmap_NativeBitmapFieldID); SkPixelRef* ref = nativeBitmap ? nativeBitmap->pixelRef() : 0; if (ref == NULL) { - doThrow(_env, "java/lang/NullPointerException", "Bitmap has no PixelRef"); + doThrow(_env, "java/lang/IllegalArgumentException", "Bitmap has no PixelRef"); return; } - + ref->safeRef(); ref->lockPixels(); - + egl_native_pixmap_t pixmap; pixmap.version = sizeof(pixmap); pixmap.width = nativeBitmap->width(); @@ -252,15 +303,10 @@ void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur, pixmap.stride = nativeBitmap->rowBytes() / nativeBitmap->bytesPerPixel(); pixmap.format = convertPixelFormat(nativeBitmap->config()); pixmap.data = (uint8_t*)ref->pixels(); - - if (attrib_list) { - // XXX: if array is malformed, we should return an NPE instead of segfault - base = (jint *)_env->GetPrimitiveArrayCritical(attrib_list, (jboolean *)0); - } + + base = beginNativeAttribList(_env, attrib_list); EGLSurface sur = eglCreatePixmapSurface(dpy, cnf, &pixmap, base); - if (attrib_list) { - _env->ReleasePrimitiveArrayCritical(attrib_list, base, JNI_ABORT); - } + endNativeAttributeList(_env, attrib_list, base); if (sur != EGL_NO_SURFACE) { _env->SetIntField(out_sur, gSurface_EGLSurfaceFieldID, (int)sur); @@ -271,14 +317,19 @@ void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur, } } -jint jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display, +static jint jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display, jobject config, jobject native_window, jintArray attrib_list) { + if (display == NULL || config == NULL + || !validAttribList(_env, attrib_list)) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); EGLContext cnf = getConfig(_env, config); Surface* window = 0; if (native_window == NULL) { not_valid_surface: - doThrow(_env, "java/lang/NullPointerException", + doThrow(_env, "java/lang/IllegalArgumentException", "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"); return 0; } @@ -286,50 +337,48 @@ not_valid_surface: if (window == NULL) goto not_valid_surface; - jint* base = 0; - if (attrib_list) { - // XXX: if array is malformed, we should return an NPE instead of segfault - base = (jint *)_env->GetPrimitiveArrayCritical(attrib_list, (jboolean *)0); - } + jint* base = beginNativeAttribList(_env, attrib_list); EGLSurface sur = eglCreateWindowSurface(dpy, cnf, new EGLNativeWindowSurface(window), base); - if (attrib_list) { - _env->ReleasePrimitiveArrayCritical(attrib_list, base, JNI_ABORT); - } + endNativeAttributeList(_env, attrib_list, base); return (jint)sur; } -jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject display, +static jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject display, jobject config, jint attribute, jintArray value) { - EGLDisplay dpy = getDisplay(_env, display); - EGLContext cnf = getConfig(_env, config); - if (value == NULL) { - doThrow(_env, "java/lang/NullPointerException"); + if (display == NULL || config == NULL + || (value == NULL || _env->GetArrayLength(value) < 1)) { + doThrow(_env, "java/lang/IllegalArgumentException"); return JNI_FALSE; } + EGLDisplay dpy = getDisplay(_env, display); + EGLContext cnf = getConfig(_env, config); jboolean success = JNI_FALSE; - int len = _env->GetArrayLength(value); - if (len) { - jint* base = (jint *)_env->GetPrimitiveArrayCritical(value, (jboolean *)0); - success = eglGetConfigAttrib(dpy, cnf, attribute, base); - _env->ReleasePrimitiveArrayCritical(value, base, JNI_ABORT); + jint localValue; + success = eglGetConfigAttrib(dpy, cnf, attribute, &localValue); + if (success) { + _env->SetIntArrayRegion(value, 0, 1, &localValue); } return success; } -jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display, +static jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display, jobjectArray configs, jint config_size, jintArray num_config) { + if (display == NULL || (configs != NULL && _env->GetArrayLength(configs) < config_size) + || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); jboolean success = JNI_FALSE; - if (num_config == NULL) { - doThrow(_env, "java/lang/NullPointerException"); - return JNI_FALSE; + if (configs == NULL) { + config_size = 0; } - jint* num_base = (jint *)_env->GetPrimitiveArrayCritical(num_config, (jboolean *)0); EGLConfig nativeConfigs[config_size]; - success = eglGetConfigs(dpy, configs ? nativeConfigs : 0, config_size, num_base); - int num = num_base[0]; - _env->ReleasePrimitiveArrayCritical(num_config, num_base, JNI_ABORT); - + int num; + success = eglGetConfigs(dpy, configs ? nativeConfigs : 0, config_size, &num); + if (num_config != NULL) { + _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num); + } if (success && configs) { for (int i=0 ; i<num ; i++) { jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, (jint)nativeConfigs[i]); @@ -338,31 +387,43 @@ jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display, } return success; } - -jint jni_eglGetError(JNIEnv *_env, jobject _this) { + +static jint jni_eglGetError(JNIEnv *_env, jobject _this) { EGLint error = eglGetError(); return error; } -jint jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) { +static jint jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) { return (jint)eglGetCurrentContext(); } -jint jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) { +static jint jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) { return (jint)eglGetCurrentDisplay(); } -jint jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) { +static jint jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) { + if (!(readdraw == EGL_READ) || (readdraw == EGL_DRAW)) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return 0; + } return (jint)eglGetCurrentSurface(readdraw); } -jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject display, jobject context) { +static jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject display, jobject context) { + if (display == NULL || context == NULL) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); EGLContext ctx = getContext(_env, context); return eglDestroyContext(dpy, ctx); } -jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface) { +static jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface) { + if (display == NULL || surface == NULL) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); EGLSurface sur = getSurface(_env, surface); @@ -377,11 +438,15 @@ jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, job return eglDestroySurface(dpy, sur); } -jint jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) { +static jint jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) { return (jint)eglGetDisplay(EGL_DEFAULT_DISPLAY); } -jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobject draw, jobject read, jobject context) { +static jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobject draw, jobject read, jobject context) { + if (display == NULL || draw == NULL || read == NULL || context == NULL) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); EGLSurface sdr = getSurface(_env, draw); EGLSurface srd = getSurface(_env, read); @@ -389,34 +454,50 @@ jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobjec return eglMakeCurrent(dpy, sdr, srd, ctx); } -jstring jni_eglQueryString(JNIEnv *_env, jobject _this, jobject display, jint name) { +static jstring jni_eglQueryString(JNIEnv *_env, jobject _this, jobject display, jint name) { + if (display == NULL) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return NULL; + } EGLDisplay dpy = getDisplay(_env, display); const char* chars = eglQueryString(dpy, name); return _env->NewStringUTF(chars); } -jboolean jni_eglSwapBuffers(JNIEnv *_env, jobject _this, jobject display, jobject surface) { +static jboolean jni_eglSwapBuffers(JNIEnv *_env, jobject _this, jobject display, jobject surface) { + if (display == NULL || surface == NULL) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); EGLSurface sur = getSurface(_env, surface); return eglSwapBuffers(dpy, sur); } -jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) { +static jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) { + if (display == NULL) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } EGLDisplay dpy = getDisplay(_env, display); return eglTerminate(dpy); } -jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display, +static jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display, jobject surface, jobject native_pixmap) { - // TODO: implement me + if (display == NULL || surface == NULL || native_pixmap == NULL) { + doThrow(_env, "java/lang/IllegalArgumentException"); + return JNI_FALSE; + } + // TODO: Implement this return JNI_FALSE; } -jboolean jni_eglWaitGL(JNIEnv *_env, jobject _this) { +static jboolean jni_eglWaitGL(JNIEnv *_env, jobject _this) { return eglWaitGL(); } -jboolean jni_eglWaitNative(JNIEnv *_env, jobject _this, jint engine, jobject bindTarget) { +static jboolean jni_eglWaitNative(JNIEnv *_env, jobject _this, jint engine, jobject bindTarget) { return eglWaitNative(engine); } diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp index 5b90bf0..3b4c041 100644 --- a/opengl/libagl/egl.cpp +++ b/opengl/libagl/egl.cpp @@ -1055,8 +1055,12 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, { if (egl_display_t::is_valid(dpy) == EGL_FALSE) return setError(EGL_BAD_DISPLAY, EGL_FALSE); + + if (ggl_unlikely(num_config==0)) { + return setError(EGL_BAD_PARAMETER, EGL_FALSE); + } - if (ggl_unlikely(configs==0 || attrib_list==0)) { + if (ggl_unlikely(attrib_list==0)) { *num_config = 0; return EGL_TRUE; } @@ -1102,11 +1106,19 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, // return the configurations found int n=0; if (possibleMatch) { - for (int i=0 ; config_size && i<numConfigs ; i++) { - if (possibleMatch & (1<<i)) { - *configs++ = (EGLConfig)i; - config_size--; - n++; + if (configs) { + for (int i=0 ; config_size && i<numConfigs ; i++) { + if (possibleMatch & (1<<i)) { + *configs++ = (EGLConfig)i; + config_size--; + n++; + } + } + } else { + for (int i=0 ; i<numConfigs ; i++) { + if (possibleMatch & (1<<i)) { + n++; + } } } } diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index 687c8bc..0b4bcce 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -725,9 +725,8 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, egl_display_t const * const dp = get_display(dpy); if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); - if (configs == 0) { - *num_config = 0; - return EGL_TRUE; + if (num_config==0) { + return setError(EGL_BAD_PARAMETER, EGL_FALSE); } EGLint n; @@ -784,7 +783,9 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, if (res && n>0) { // n has to be 0 or 1, by construction, and we already know // which config it will return (since there can be only one). - configs[0] = MAKE_CONFIG(i, index); + if (configs) { + configs[0] = MAKE_CONFIG(i, index); + } *num_config = 1; } } @@ -798,19 +799,23 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, if (cnx->dso) { if (cnx->hooks->egl.eglChooseConfig( dp->dpys[i], attrib_list, configs, config_size, &n)) { - // now we need to convert these client EGLConfig to our - // internal EGLConfig format. This is done in O(n log n). - for (int j=0 ; j<n ; j++) { - int index = binarySearch<EGLConfig>( - dp->configs[i], 0, dp->numConfigs[i]-1, configs[j]); - if (index >= 0) { - configs[j] = MAKE_CONFIG(i, index); - } else { - return setError(EGL_BAD_CONFIG, EGL_FALSE); + if (configs) { + // now we need to convert these client EGLConfig to our + // internal EGLConfig format. This is done in O(n log n). + for (int j=0 ; j<n ; j++) { + int index = binarySearch<EGLConfig>( + dp->configs[i], 0, dp->numConfigs[i]-1, configs[j]); + if (index >= 0) { + if (configs) { + configs[j] = MAKE_CONFIG(i, index); + } + } else { + return setError(EGL_BAD_CONFIG, EGL_FALSE); + } } + configs += n; + config_size -= n; } - configs += n; - config_size -= n; *num_config += n; res = EGL_TRUE; } |