Home | History | Annotate | Download | only in jni
      1 /*
      2 ** Copyright 2012, The Android Open Source Project
      3 **
      4 ** Licensed under the Apache License, Version 2.0 (the "License");
      5 ** you may not use this file except in compliance with the License.
      6 ** You may obtain a copy of the License at
      7 **
      8 **     http://www.apache.org/licenses/LICENSE-2.0
      9 **
     10 ** Unless required by applicable law or agreed to in writing, software
     11 ** distributed under the License is distributed on an "AS IS" BASIS,
     12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 ** See the License for the specific language governing permissions and
     14 ** limitations under the License.
     15 */
     16 
     17 // This source file is automatically generated
     18 
     19 #pragma GCC diagnostic ignored "-Wunused-variable"
     20 #pragma GCC diagnostic ignored "-Wunused-function"
     21 
     22 #include "jni.h"
     23 #include <nativehelper/JNIHelp.h>
     24 #include <android_runtime/AndroidRuntime.h>
     25 #include <android_runtime/android_view_Surface.h>
     26 #include <android_runtime/android_graphics_SurfaceTexture.h>
     27 #include <utils/misc.h>
     28 
     29 #include <assert.h>
     30 #include <EGL/egl.h>
     31 
     32 #include <gui/Surface.h>
     33 #include <gui/GLConsumer.h>
     34 #include <gui/Surface.h>
     35 
     36 #include <ui/ANativeObjectBase.h>
     37 
     38 static int initialized = 0;
     39 
     40 static jclass egldisplayClass;
     41 static jclass eglcontextClass;
     42 static jclass eglsurfaceClass;
     43 static jclass eglconfigClass;
     44 
     45 static jmethodID egldisplayGetHandleID;
     46 static jmethodID eglcontextGetHandleID;
     47 static jmethodID eglsurfaceGetHandleID;
     48 static jmethodID eglconfigGetHandleID;
     49 
     50 static jmethodID egldisplayConstructor;
     51 static jmethodID eglcontextConstructor;
     52 static jmethodID eglsurfaceConstructor;
     53 static jmethodID eglconfigConstructor;
     54 
     55 static jobject eglNoContextObject;
     56 static jobject eglNoDisplayObject;
     57 static jobject eglNoSurfaceObject;
     58 
     59 
     60 
     61 /* Cache method IDs each time the class is loaded. */
     62 
     63 static void
     64 nativeClassInit(JNIEnv *_env, jclass glImplClass)
     65 {
     66     jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
     67     egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
     68     jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
     69     eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
     70     jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
     71     eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
     72     jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
     73     eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
     74 
     75     egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
     76     eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
     77     eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
     78     eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
     79 
     80 
     81     egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
     82     eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
     83     eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
     84     eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
     85 
     86     jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
     87     eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
     88     jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
     89     eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
     90     jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
     91     eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
     92 
     93 
     94     jclass eglClass = _env->FindClass("android/opengl/EGL14");
     95     jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
     96     _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
     97 
     98     jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
     99     _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
    100 
    101     jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
    102     _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
    103 }
    104 
    105 static void *
    106 fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
    107     if (obj == NULL){
    108         jniThrowException(_env, "java/lang/IllegalArgumentException",
    109                           "Object is set to null.");
    110     }
    111 
    112     jlong handle = _env->CallLongMethod(obj, mid);
    113     return reinterpret_cast<void*>(handle);
    114 }
    115 
    116 static jobject
    117 toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) {
    118     if (cls == eglcontextClass &&
    119        (EGLContext)handle == EGL_NO_CONTEXT) {
    120            return eglNoContextObject;
    121     }
    122 
    123     if (cls == egldisplayClass &&
    124        (EGLDisplay)handle == EGL_NO_DISPLAY) {
    125            return eglNoDisplayObject;
    126     }
    127 
    128     if (cls == eglsurfaceClass &&
    129        (EGLSurface)handle == EGL_NO_SURFACE) {
    130            return eglNoSurfaceObject;
    131     }
    132 
    133     return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
    134 }
    135 
    136 // --------------------------------------------------------------------------
    137 /* EGLint eglGetError ( void ) */
    138 static jint
    139 android_eglGetError
    140   (JNIEnv *_env, jobject _this) {
    141     EGLint _returnValue = (EGLint) 0;
    142     _returnValue = eglGetError();
    143     return (jint)_returnValue;
    144 }
    145 
    146 /* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */
    147 static jobject
    148 android_eglGetDisplay
    149   (JNIEnv *_env, jobject _this, jlong display_id) {
    150     EGLDisplay _returnValue = (EGLDisplay) 0;
    151     _returnValue = eglGetDisplay(
    152         reinterpret_cast<EGLNativeDisplayType>(display_id)
    153     );
    154     return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue);
    155 }
    156 
    157 /* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */
    158 static jobject
    159 android_eglGetDisplayInt
    160   (JNIEnv *_env, jobject _this, jint display_id) {
    161 
    162     if (static_cast<uintptr_t>(display_id) !=
    163         reinterpret_cast<uintptr_t>(EGL_DEFAULT_DISPLAY)) {
    164         jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglGetDisplay");
    165         return 0;
    166     }
    167     return android_eglGetDisplay(_env, _this, display_id);
    168 }
    169 
    170 /* EGLBoolean eglInitialize ( EGLDisplay dpy, EGLint *major, EGLint *minor ) */
    171 static jboolean
    172 android_eglInitialize
    173   (JNIEnv *_env, jobject _this, jobject dpy, jintArray major_ref, jint majorOffset, jintArray minor_ref, jint minorOffset) {
    174     jint _exception = 0;
    175     const char * _exceptionType = NULL;
    176     const char * _exceptionMessage = NULL;
    177     EGLBoolean _returnValue = (EGLBoolean) 0;
    178     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    179     EGLint *major_base = (EGLint *) 0;
    180     jint _majorRemaining;
    181     EGLint *major = (EGLint *) 0;
    182     EGLint *minor_base = (EGLint *) 0;
    183     jint _minorRemaining;
    184     EGLint *minor = (EGLint *) 0;
    185 
    186     if (major_ref) {
    187         if (majorOffset < 0) {
    188             _exception = 1;
    189             _exceptionType = "java/lang/IllegalArgumentException";
    190             _exceptionMessage = "majorOffset < 0";
    191             goto exit;
    192         }
    193         _majorRemaining = _env->GetArrayLength(major_ref) - majorOffset;
    194         if (_majorRemaining < 1) {
    195             _exception = 1;
    196             _exceptionType = "java/lang/IllegalArgumentException";
    197             _exceptionMessage = "length - majorOffset < 1 < needed";
    198             goto exit;
    199         }
    200         major_base = (EGLint *)
    201             _env->GetIntArrayElements(major_ref, (jboolean *)0);
    202         major = major_base + majorOffset;
    203     }
    204 
    205     if (minor_ref) {
    206         if (minorOffset < 0) {
    207             _exception = 1;
    208             _exceptionType = "java/lang/IllegalArgumentException";
    209             _exceptionMessage = "minorOffset < 0";
    210             goto exit;
    211         }
    212         _minorRemaining = _env->GetArrayLength(minor_ref) - minorOffset;
    213         if (_minorRemaining < 1) {
    214             _exception = 1;
    215             _exceptionType = "java/lang/IllegalArgumentException";
    216             _exceptionMessage = "length - minorOffset < 1 < needed";
    217             goto exit;
    218         }
    219         minor_base = (EGLint *)
    220             _env->GetIntArrayElements(minor_ref, (jboolean *)0);
    221         minor = minor_base + minorOffset;
    222     }
    223 
    224     _returnValue = eglInitialize(
    225         (EGLDisplay)dpy_native,
    226         (EGLint *)major,
    227         (EGLint *)minor
    228     );
    229 
    230 exit:
    231     if (minor_base) {
    232         _env->ReleaseIntArrayElements(minor_ref, (jint*)minor_base,
    233             _exception ? JNI_ABORT: 0);
    234     }
    235     if (major_base) {
    236         _env->ReleaseIntArrayElements(major_ref, (jint*)major_base,
    237             _exception ? JNI_ABORT: 0);
    238     }
    239     if (_exception) {
    240         jniThrowException(_env, _exceptionType, _exceptionMessage);
    241     }
    242     return (jboolean)_returnValue;
    243 }
    244 
    245 /* EGLBoolean eglTerminate ( EGLDisplay dpy ) */
    246 static jboolean
    247 android_eglTerminate
    248   (JNIEnv *_env, jobject _this, jobject dpy) {
    249     EGLBoolean _returnValue = (EGLBoolean) 0;
    250     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    251 
    252     _returnValue = eglTerminate(
    253         (EGLDisplay)dpy_native
    254     );
    255     return (jboolean)_returnValue;
    256 }
    257 
    258 /* const char * eglQueryString ( EGLDisplay dpy, EGLint name ) */
    259 static jstring
    260 android_eglQueryString__Landroind_opengl_EGLDisplay_2I
    261   (JNIEnv *_env, jobject _this, jobject dpy, jint name) {
    262     const char* chars = (const char*) eglQueryString(
    263         (EGLDisplay)fromEGLHandle(_env, egldisplayGetHandleID, dpy),
    264         (EGLint)name
    265     );
    266     return _env->NewStringUTF(chars);
    267 }
    268 /* EGLBoolean eglGetConfigs ( EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */
    269 static jboolean
    270 android_eglGetConfigs
    271   (JNIEnv *_env, jobject _this, jobject dpy, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) {
    272     jint _exception = 0;
    273     const char * _exceptionType = NULL;
    274     const char * _exceptionMessage = NULL;
    275     EGLBoolean _returnValue = (EGLBoolean) 0;
    276     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    277     jint _configsRemaining;
    278     EGLConfig *configs = (EGLConfig *) 0;
    279     EGLint *num_config_base = (EGLint *) 0;
    280     jint _num_configRemaining;
    281     EGLint *num_config = (EGLint *) 0;
    282 
    283     if (configs_ref) {
    284         if (configsOffset < 0) {
    285             _exception = 1;
    286             _exceptionType = "java/lang/IllegalArgumentException";
    287             _exceptionMessage = "configsOffset < 0";
    288             goto exit;
    289         }
    290         _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset;
    291         if (_configsRemaining < config_size) {
    292             _exception = 1;
    293             _exceptionType = "java/lang/IllegalArgumentException";
    294             _exceptionMessage = "length - configsOffset < config_size < needed";
    295             goto exit;
    296         }
    297         configs = new EGLConfig[_configsRemaining];
    298     }
    299 
    300     if (!num_config_ref) {
    301         _exception = 1;
    302         _exceptionType = "java/lang/IllegalArgumentException";
    303         _exceptionMessage = "num_config == null";
    304         goto exit;
    305     }
    306     if (num_configOffset < 0) {
    307         _exception = 1;
    308         _exceptionType = "java/lang/IllegalArgumentException";
    309         _exceptionMessage = "num_configOffset < 0";
    310         goto exit;
    311     }
    312     _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset;
    313     num_config_base = (EGLint *)
    314         _env->GetIntArrayElements(num_config_ref, (jboolean *)0);
    315     num_config = num_config_base + num_configOffset;
    316 
    317     _returnValue = eglGetConfigs(
    318         (EGLDisplay)dpy_native,
    319         (EGLConfig *)configs,
    320         (EGLint)config_size,
    321         (EGLint *)num_config
    322     );
    323 
    324 exit:
    325     if (num_config_base) {
    326         _env->ReleaseIntArrayElements(num_config_ref, (jint*)num_config_base,
    327             _exception ? JNI_ABORT: 0);
    328     }
    329     if (configs) {
    330         for (int i = 0; i < _configsRemaining; i++) {
    331             jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]);
    332             _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new);
    333         }
    334         delete[] configs;
    335     }
    336     if (_exception) {
    337         jniThrowException(_env, _exceptionType, _exceptionMessage);
    338     }
    339     return (jboolean)_returnValue;
    340 }
    341 
    342 /* EGLBoolean eglChooseConfig ( EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */
    343 static jboolean
    344 android_eglChooseConfig
    345   (JNIEnv *_env, jobject _this, jobject dpy, jintArray attrib_list_ref, jint attrib_listOffset, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) {
    346     jint _exception = 0;
    347     const char * _exceptionType = NULL;
    348     const char * _exceptionMessage = NULL;
    349     EGLBoolean _returnValue = (EGLBoolean) 0;
    350     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    351     bool attrib_list_sentinel = false;
    352     EGLint *attrib_list_base = (EGLint *) 0;
    353     jint _attrib_listRemaining;
    354     EGLint *attrib_list = (EGLint *) 0;
    355     jint _configsRemaining;
    356     EGLConfig *configs = (EGLConfig *) 0;
    357     EGLint *num_config_base = (EGLint *) 0;
    358     jint _num_configRemaining;
    359     EGLint *num_config = (EGLint *) 0;
    360 
    361     if (!attrib_list_ref) {
    362         _exception = 1;
    363         _exceptionType = "java/lang/IllegalArgumentException";
    364         _exceptionMessage = "attrib_list == null";
    365         goto exit;
    366     }
    367     if (attrib_listOffset < 0) {
    368         _exception = 1;
    369         _exceptionType = "java/lang/IllegalArgumentException";
    370         _exceptionMessage = "attrib_listOffset < 0";
    371         goto exit;
    372     }
    373     _attrib_listRemaining = _env->GetArrayLength(attrib_list_ref) - attrib_listOffset;
    374     attrib_list_base = (EGLint *)
    375         _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    376     attrib_list = attrib_list_base + attrib_listOffset;
    377     attrib_list_sentinel = false;
    378     for (int i = _attrib_listRemaining - 1; i >= 0; i--)  {
    379         if (attrib_list[i] == EGL_NONE){
    380             attrib_list_sentinel = true;
    381             break;
    382         }
    383     }
    384     if (attrib_list_sentinel == false) {
    385         _exception = 1;
    386         _exceptionType = "java/lang/IllegalArgumentException";
    387         _exceptionMessage = "attrib_list must contain EGL_NONE!";
    388         goto exit;
    389     }
    390 
    391     if (configs_ref) {
    392         if (configsOffset < 0) {
    393             _exception = 1;
    394             _exceptionType = "java/lang/IllegalArgumentException";
    395             _exceptionMessage = "configsOffset < 0";
    396             goto exit;
    397         }
    398         _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset;
    399         if (_configsRemaining < config_size) {
    400             _exception = 1;
    401             _exceptionType = "java/lang/IllegalArgumentException";
    402             _exceptionMessage = "length - configsOffset < config_size < needed";
    403             goto exit;
    404         }
    405         configs = new EGLConfig[_configsRemaining];
    406     }
    407 
    408     if (!num_config_ref) {
    409         _exception = 1;
    410         _exceptionType = "java/lang/IllegalArgumentException";
    411         _exceptionMessage = "num_config == null";
    412         goto exit;
    413     }
    414     if (num_configOffset < 0) {
    415         _exception = 1;
    416         _exceptionType = "java/lang/IllegalArgumentException";
    417         _exceptionMessage = "num_configOffset < 0";
    418         goto exit;
    419     }
    420     _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset;
    421     if (_num_configRemaining < 1) {
    422         _exception = 1;
    423         _exceptionType = "java/lang/IllegalArgumentException";
    424         _exceptionMessage = "length - num_configOffset < 1 < needed";
    425         goto exit;
    426     }
    427     num_config_base = (EGLint *)
    428         _env->GetIntArrayElements(num_config_ref, (jboolean *)0);
    429     num_config = num_config_base + num_configOffset;
    430 
    431     _returnValue = eglChooseConfig(
    432         (EGLDisplay)dpy_native,
    433         (EGLint *)attrib_list,
    434         (EGLConfig *)configs,
    435         (EGLint)config_size,
    436         (EGLint *)num_config
    437     );
    438 
    439 exit:
    440     if (num_config_base) {
    441         _env->ReleaseIntArrayElements(num_config_ref, (jint*)num_config_base,
    442             _exception ? JNI_ABORT: 0);
    443     }
    444     if (attrib_list_base) {
    445         _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
    446             JNI_ABORT);
    447     }
    448     if (configs) {
    449         for (int i = 0; i < _configsRemaining; i++) {
    450             jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]);
    451             _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new);
    452         }
    453         delete[] configs;
    454     }
    455     if (_exception) {
    456         jniThrowException(_env, _exceptionType, _exceptionMessage);
    457     }
    458     return (jboolean)_returnValue;
    459 }
    460 
    461 /* EGLBoolean eglGetConfigAttrib ( EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value ) */
    462 static jboolean
    463 android_eglGetConfigAttrib
    464   (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint attribute, jintArray value_ref, jint offset) {
    465     jint _exception = 0;
    466     const char * _exceptionType = NULL;
    467     const char * _exceptionMessage = NULL;
    468     EGLBoolean _returnValue = (EGLBoolean) 0;
    469     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    470     EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
    471     EGLint *value_base = (EGLint *) 0;
    472     jint _remaining;
    473     EGLint *value = (EGLint *) 0;
    474 
    475     if (!value_ref) {
    476         _exception = 1;
    477         _exceptionType = "java/lang/IllegalArgumentException";
    478         _exceptionMessage = "value == null";
    479         goto exit;
    480     }
    481     if (offset < 0) {
    482         _exception = 1;
    483         _exceptionType = "java/lang/IllegalArgumentException";
    484         _exceptionMessage = "offset < 0";
    485         goto exit;
    486     }
    487     _remaining = _env->GetArrayLength(value_ref) - offset;
    488     if (_remaining < 1) {
    489         _exception = 1;
    490         _exceptionType = "java/lang/IllegalArgumentException";
    491         _exceptionMessage = "length - offset < 1 < needed";
    492         goto exit;
    493     }
    494     value_base = (EGLint *)
    495         _env->GetIntArrayElements(value_ref, (jboolean *)0);
    496     value = value_base + offset;
    497 
    498     _returnValue = eglGetConfigAttrib(
    499         (EGLDisplay)dpy_native,
    500         (EGLConfig)config_native,
    501         (EGLint)attribute,
    502         (EGLint *)value
    503     );
    504 
    505 exit:
    506     if (value_base) {
    507         _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
    508             _exception ? JNI_ABORT: 0);
    509     }
    510     if (_exception) {
    511         jniThrowException(_env, _exceptionType, _exceptionMessage);
    512     }
    513     return (jboolean)_returnValue;
    514 }
    515 
    516 /* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */
    517 static jobject
    518 android_eglCreateWindowSurface
    519   (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) {
    520     jint _exception = 0;
    521     const char * _exceptionType = "";
    522     const char * _exceptionMessage = "";
    523     EGLSurface _returnValue = (EGLSurface) 0;
    524     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    525     EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
    526     int attrib_list_sentinel = 0;
    527     EGLint *attrib_list_base = (EGLint *) 0;
    528     jint _remaining;
    529     EGLint *attrib_list = (EGLint *) 0;
    530     android::sp<ANativeWindow> window;
    531 
    532     if (attrib_list_ref) {
    533         if (offset < 0) {
    534             _exception = 1;
    535             _exceptionType = "java/lang/IllegalArgumentException";
    536             _exceptionMessage = "offset < 0";
    537             goto exit;
    538         }
    539         _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    540         attrib_list_base = (EGLint *)
    541             _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    542         attrib_list = attrib_list_base + offset;
    543         attrib_list_sentinel = 0;
    544         for (int i = _remaining - 1; i >= 0; i--)  {
    545             if (*((EGLint*)(attrib_list + i)) == EGL_NONE){
    546                 attrib_list_sentinel = 1;
    547                 break;
    548             }
    549         }
    550         if (attrib_list_sentinel == 0) {
    551             _exception = 1;
    552             _exceptionType = "java/lang/IllegalArgumentException";
    553             _exceptionMessage = "attrib_list must contain EGL_NONE!";
    554             goto exit;
    555         }
    556     }
    557 
    558     if (win == NULL) {
    559 not_valid_surface:
    560         _exception = 1;
    561         _exceptionType = "java/lang/IllegalArgumentException";
    562         _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface";
    563         goto exit;
    564     }
    565 
    566     window = android::android_view_Surface_getNativeWindow(_env, win);
    567 
    568     if (window == NULL)
    569         goto not_valid_surface;
    570 
    571     _returnValue = eglCreateWindowSurface(
    572         (EGLDisplay)dpy_native,
    573         (EGLConfig)config_native,
    574         (EGLNativeWindowType)window.get(),
    575         (EGLint *)attrib_list
    576     );
    577 
    578 exit:
    579     if (attrib_list_base) {
    580         _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
    581             JNI_ABORT);
    582     }
    583     if (_exception) {
    584         jniThrowException(_env, _exceptionType, _exceptionMessage);
    585     }
    586     return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
    587 }
    588 
    589 /* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */
    590 static jobject
    591 android_eglCreateWindowSurfaceTexture
    592   (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) {
    593     jint _exception = 0;
    594     const char * _exceptionType = "";
    595     const char * _exceptionMessage = "";
    596     EGLSurface _returnValue = (EGLSurface) 0;
    597     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    598     EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
    599     int attrib_list_sentinel = 0;
    600     EGLint *attrib_list_base = (EGLint *) 0;
    601     jint _remaining;
    602     EGLint *attrib_list = (EGLint *) 0;
    603     android::sp<ANativeWindow> window;
    604     android::sp<android::IGraphicBufferProducer> producer;
    605 
    606     if (!attrib_list_ref) {
    607         _exception = 1;
    608         _exceptionType = "java/lang/IllegalArgumentException";
    609         _exceptionMessage = "attrib_list == null";
    610         goto exit;
    611     }
    612     if (offset < 0) {
    613         _exception = 1;
    614         _exceptionType = "java/lang/IllegalArgumentException";
    615         _exceptionMessage = "offset < 0";
    616         goto exit;
    617     }
    618     if (win == NULL) {
    619 not_valid_surface:
    620         _exception = 1;
    621         _exceptionType = "java/lang/IllegalArgumentException";
    622         _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface";
    623         goto exit;
    624     }
    625     producer = android::SurfaceTexture_getProducer(_env, win);
    626 
    627     if (producer == NULL)
    628         goto not_valid_surface;
    629 
    630     window = new android::Surface(producer, true);
    631 
    632     if (window == NULL)
    633         goto not_valid_surface;
    634 
    635     _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    636     attrib_list_base = (EGLint *)
    637         _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    638     attrib_list = attrib_list_base + offset;
    639     attrib_list_sentinel = 0;
    640     for (int i = _remaining - 1; i >= 0; i--)  {
    641         if (*((EGLint*)(attrib_list + i)) == EGL_NONE){
    642             attrib_list_sentinel = 1;
    643             break;
    644         }
    645     }
    646     if (attrib_list_sentinel == 0) {
    647         _exception = 1;
    648         _exceptionType = "java/lang/IllegalArgumentException";
    649         _exceptionMessage = "attrib_list must contain EGL_NONE!";
    650         goto exit;
    651     }
    652 
    653     _returnValue = eglCreateWindowSurface(
    654         (EGLDisplay)dpy_native,
    655         (EGLConfig)config_native,
    656         (EGLNativeWindowType)window.get(),
    657         (EGLint *)attrib_list
    658     );
    659 
    660 exit:
    661     if (attrib_list_base) {
    662         _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
    663             JNI_ABORT);
    664     }
    665     if (_exception) {
    666         jniThrowException(_env, _exceptionType, _exceptionMessage);
    667     }
    668     return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
    669 }
    670 /* EGLSurface eglCreatePbufferSurface ( EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list ) */
    671 static jobject
    672 android_eglCreatePbufferSurface
    673   (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jintArray attrib_list_ref, jint offset) {
    674     jint _exception = 0;
    675     const char * _exceptionType = NULL;
    676     const char * _exceptionMessage = NULL;
    677     EGLSurface _returnValue = (EGLSurface) 0;
    678     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    679     EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
    680     bool attrib_list_sentinel = false;
    681     EGLint *attrib_list_base = (EGLint *) 0;
    682     jint _remaining;
    683     EGLint *attrib_list = (EGLint *) 0;
    684 
    685     if (attrib_list_ref) {
    686         if (offset < 0) {
    687             _exception = 1;
    688             _exceptionType = "java/lang/IllegalArgumentException";
    689             _exceptionMessage = "offset < 0";
    690             goto exit;
    691         }
    692         _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    693         attrib_list_base = (EGLint *)
    694             _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    695         attrib_list = attrib_list_base + offset;
    696         attrib_list_sentinel = false;
    697         for (int i = _remaining - 1; i >= 0; i--)  {
    698             if (attrib_list[i] == EGL_NONE){
    699                 attrib_list_sentinel = true;
    700                 break;
    701             }
    702         }
    703         if (attrib_list_sentinel == false) {
    704             _exception = 1;
    705             _exceptionType = "java/lang/IllegalArgumentException";
    706             _exceptionMessage = "attrib_list must contain EGL_NONE!";
    707             goto exit;
    708         }
    709     }
    710 
    711     _returnValue = eglCreatePbufferSurface(
    712         (EGLDisplay)dpy_native,
    713         (EGLConfig)config_native,
    714         (EGLint *)attrib_list
    715     );
    716 
    717 exit:
    718     if (attrib_list_base) {
    719         _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
    720             JNI_ABORT);
    721     }
    722     if (_exception) {
    723         jniThrowException(_env, _exceptionType, _exceptionMessage);
    724     }
    725     return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
    726 }
    727 
    728 /* EGLSurface eglCreatePixmapSurface ( EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list ) */
    729 static jobject
    730 android_eglCreatePixmapSurface
    731   (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint pixmap, jintArray attrib_list_ref, jint offset) {
    732     jniThrowException(_env, "java/lang/UnsupportedOperationException",
    733         "eglCreatePixmapSurface");
    734     return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, (EGLSurface) 0);
    735 }
    736 
    737 /* EGLBoolean eglDestroySurface ( EGLDisplay dpy, EGLSurface surface ) */
    738 static jboolean
    739 android_eglDestroySurface
    740   (JNIEnv *_env, jobject _this, jobject dpy, jobject surface) {
    741     EGLBoolean _returnValue = (EGLBoolean) 0;
    742     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    743     EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
    744 
    745     _returnValue = eglDestroySurface(
    746         (EGLDisplay)dpy_native,
    747         (EGLSurface)surface_native
    748     );
    749     return (jboolean)_returnValue;
    750 }
    751 
    752 /* EGLBoolean eglQuerySurface ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value ) */
    753 static jboolean
    754 android_eglQuerySurface
    755   (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jintArray value_ref, jint offset) {
    756     jint _exception = 0;
    757     const char * _exceptionType = NULL;
    758     const char * _exceptionMessage = NULL;
    759     EGLBoolean _returnValue = (EGLBoolean) 0;
    760     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    761     EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
    762     EGLint *value_base = (EGLint *) 0;
    763     jint _remaining;
    764     EGLint *value = (EGLint *) 0;
    765 
    766     if (!value_ref) {
    767         _exception = 1;
    768         _exceptionType = "java/lang/IllegalArgumentException";
    769         _exceptionMessage = "value == null";
    770         goto exit;
    771     }
    772     if (offset < 0) {
    773         _exception = 1;
    774         _exceptionType = "java/lang/IllegalArgumentException";
    775         _exceptionMessage = "offset < 0";
    776         goto exit;
    777     }
    778     _remaining = _env->GetArrayLength(value_ref) - offset;
    779     if (_remaining < 1) {
    780         _exception = 1;
    781         _exceptionType = "java/lang/IllegalArgumentException";
    782         _exceptionMessage = "length - offset < 1 < needed";
    783         goto exit;
    784     }
    785     value_base = (EGLint *)
    786         _env->GetIntArrayElements(value_ref, (jboolean *)0);
    787     value = value_base + offset;
    788 
    789     _returnValue = eglQuerySurface(
    790         (EGLDisplay)dpy_native,
    791         (EGLSurface)surface_native,
    792         (EGLint)attribute,
    793         (EGLint *)value
    794     );
    795 
    796 exit:
    797     if (value_base) {
    798         _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
    799             _exception ? JNI_ABORT: 0);
    800     }
    801     if (_exception) {
    802         jniThrowException(_env, _exceptionType, _exceptionMessage);
    803     }
    804     return (jboolean)_returnValue;
    805 }
    806 
    807 /* EGLBoolean eglBindAPI ( EGLenum api ) */
    808 static jboolean
    809 android_eglBindAPI
    810   (JNIEnv *_env, jobject _this, jint api) {
    811     EGLBoolean _returnValue = (EGLBoolean) 0;
    812     _returnValue = eglBindAPI(
    813         (EGLenum)api
    814     );
    815     return (jboolean)_returnValue;
    816 }
    817 
    818 /* EGLenum eglQueryAPI ( void ) */
    819 static jint
    820 android_eglQueryAPI
    821   (JNIEnv *_env, jobject _this) {
    822     EGLenum _returnValue = (EGLenum) 0;
    823     _returnValue = eglQueryAPI();
    824     return (jint)_returnValue;
    825 }
    826 
    827 /* EGLBoolean eglWaitClient ( void ) */
    828 static jboolean
    829 android_eglWaitClient
    830   (JNIEnv *_env, jobject _this) {
    831     EGLBoolean _returnValue = (EGLBoolean) 0;
    832     _returnValue = eglWaitClient();
    833     return (jboolean)_returnValue;
    834 }
    835 
    836 /* EGLBoolean eglReleaseThread ( void ) */
    837 static jboolean
    838 android_eglReleaseThread
    839   (JNIEnv *_env, jobject _this) {
    840     EGLBoolean _returnValue = (EGLBoolean) 0;
    841     _returnValue = eglReleaseThread();
    842     return (jboolean)_returnValue;
    843 }
    844 
    845 /* EGLSurface eglCreatePbufferFromClientBuffer ( EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list ) */
    846 static jobject
    847 android_eglCreatePbufferFromClientBuffer
    848   (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jlong buffer, jobject config, jintArray attrib_list_ref, jint offset) {
    849     jint _exception = 0;
    850     const char * _exceptionType = NULL;
    851     const char * _exceptionMessage = NULL;
    852     EGLSurface _returnValue = (EGLSurface) 0;
    853     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    854     EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
    855     bool attrib_list_sentinel = false;
    856     EGLint *attrib_list_base = (EGLint *) 0;
    857     jint _remaining;
    858     EGLint *attrib_list = (EGLint *) 0;
    859 
    860     if (attrib_list_ref) {
    861         if (offset < 0) {
    862             _exception = 1;
    863             _exceptionType = "java/lang/IllegalArgumentException";
    864             _exceptionMessage = "offset < 0";
    865             goto exit;
    866         }
    867         _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    868         attrib_list_base = (EGLint *)
    869             _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    870         attrib_list = attrib_list_base + offset;
    871         attrib_list_sentinel = false;
    872         for (int i = _remaining - 1; i >= 0; i--)  {
    873             if (attrib_list[i] == EGL_NONE){
    874                 attrib_list_sentinel = true;
    875                 break;
    876             }
    877         }
    878         if (attrib_list_sentinel == false) {
    879             _exception = 1;
    880             _exceptionType = "java/lang/IllegalArgumentException";
    881             _exceptionMessage = "attrib_list must contain EGL_NONE!";
    882             goto exit;
    883         }
    884     }
    885 
    886     _returnValue = eglCreatePbufferFromClientBuffer(
    887         (EGLDisplay)dpy_native,
    888         (EGLenum)buftype,
    889         reinterpret_cast<EGLClientBuffer>(buffer),
    890         (EGLConfig)config_native,
    891         (EGLint *)attrib_list
    892     );
    893 
    894 exit:
    895     if (attrib_list_base) {
    896         _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
    897             JNI_ABORT);
    898     }
    899     if (_exception) {
    900         jniThrowException(_env, _exceptionType, _exceptionMessage);
    901     }
    902     return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
    903 }
    904 
    905 static jobject
    906 android_eglCreatePbufferFromClientBufferInt
    907   (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jint buffer, jobject config, jintArray attrib_list_ref, jint offset) {
    908     if(sizeof(void*) != sizeof(uint32_t)) {
    909         jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglCreatePbufferFromClientBuffer");
    910         return 0;
    911     }
    912     return android_eglCreatePbufferFromClientBuffer(_env, _this, dpy, buftype, buffer, config, attrib_list_ref, offset);
    913 }
    914 /* EGLBoolean eglSurfaceAttrib ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value ) */
    915 static jboolean
    916 android_eglSurfaceAttrib
    917   (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jint value) {
    918     EGLBoolean _returnValue = (EGLBoolean) 0;
    919     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    920     EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
    921 
    922     _returnValue = eglSurfaceAttrib(
    923         (EGLDisplay)dpy_native,
    924         (EGLSurface)surface_native,
    925         (EGLint)attribute,
    926         (EGLint)value
    927     );
    928     return (jboolean)_returnValue;
    929 }
    930 
    931 /* EGLBoolean eglBindTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */
    932 static jboolean
    933 android_eglBindTexImage
    934   (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint buffer) {
    935     EGLBoolean _returnValue = (EGLBoolean) 0;
    936     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    937     EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
    938 
    939     _returnValue = eglBindTexImage(
    940         (EGLDisplay)dpy_native,
    941         (EGLSurface)surface_native,
    942         (EGLint)buffer
    943     );
    944     return (jboolean)_returnValue;
    945 }
    946 
    947 /* EGLBoolean eglReleaseTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */
    948 static jboolean
    949 android_eglReleaseTexImage
    950   (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint buffer) {
    951     EGLBoolean _returnValue = (EGLBoolean) 0;
    952     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    953     EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
    954 
    955     _returnValue = eglReleaseTexImage(
    956         (EGLDisplay)dpy_native,
    957         (EGLSurface)surface_native,
    958         (EGLint)buffer
    959     );
    960     return (jboolean)_returnValue;
    961 }
    962 
    963 /* EGLBoolean eglSwapInterval ( EGLDisplay dpy, EGLint interval ) */
    964 static jboolean
    965 android_eglSwapInterval
    966   (JNIEnv *_env, jobject _this, jobject dpy, jint interval) {
    967     EGLBoolean _returnValue = (EGLBoolean) 0;
    968     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    969 
    970     _returnValue = eglSwapInterval(
    971         (EGLDisplay)dpy_native,
    972         (EGLint)interval
    973     );
    974     return (jboolean)_returnValue;
    975 }
    976 
    977 /* EGLContext eglCreateContext ( EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list ) */
    978 static jobject
    979 android_eglCreateContext
    980   (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject share_context, jintArray attrib_list_ref, jint offset) {
    981     jint _exception = 0;
    982     const char * _exceptionType = NULL;
    983     const char * _exceptionMessage = NULL;
    984     EGLContext _returnValue = (EGLContext) 0;
    985     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    986     EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
    987     EGLContext share_context_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, share_context);
    988     bool attrib_list_sentinel = false;
    989     EGLint *attrib_list_base = (EGLint *) 0;
    990     jint _remaining;
    991     EGLint *attrib_list = (EGLint *) 0;
    992 
    993     if (!attrib_list_ref) {
    994         _exception = 1;
    995         _exceptionType = "java/lang/IllegalArgumentException";
    996         _exceptionMessage = "attrib_list == null";
    997         goto exit;
    998     }
    999     if (offset < 0) {
   1000         _exception = 1;
   1001         _exceptionType = "java/lang/IllegalArgumentException";
   1002         _exceptionMessage = "offset < 0";
   1003         goto exit;
   1004     }
   1005     _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
   1006     attrib_list_base = (EGLint *)
   1007         _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
   1008     attrib_list = attrib_list_base + offset;
   1009     attrib_list_sentinel = false;
   1010     for (int i = _remaining - 1; i >= 0; i--)  {
   1011         if (attrib_list[i] == EGL_NONE){
   1012             attrib_list_sentinel = true;
   1013             break;
   1014         }
   1015     }
   1016     if (attrib_list_sentinel == false) {
   1017         _exception = 1;
   1018         _exceptionType = "java/lang/IllegalArgumentException";
   1019         _exceptionMessage = "attrib_list must contain EGL_NONE!";
   1020         goto exit;
   1021     }
   1022 
   1023     _returnValue = eglCreateContext(
   1024         (EGLDisplay)dpy_native,
   1025         (EGLConfig)config_native,
   1026         (EGLContext)share_context_native,
   1027         (EGLint *)attrib_list
   1028     );
   1029 
   1030 exit:
   1031     if (attrib_list_base) {
   1032         _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
   1033             JNI_ABORT);
   1034     }
   1035     if (_exception) {
   1036         jniThrowException(_env, _exceptionType, _exceptionMessage);
   1037     }
   1038     return toEGLHandle(_env, eglcontextClass, eglcontextConstructor, _returnValue);
   1039 }
   1040 
   1041 /* EGLBoolean eglDestroyContext ( EGLDisplay dpy, EGLContext ctx ) */
   1042 static jboolean
   1043 android_eglDestroyContext
   1044   (JNIEnv *_env, jobject _this, jobject dpy, jobject ctx) {
   1045     EGLBoolean _returnValue = (EGLBoolean) 0;
   1046     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
   1047     EGLContext ctx_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, ctx);
   1048 
   1049     _returnValue = eglDestroyContext(
   1050         (EGLDisplay)dpy_native,
   1051         (EGLContext)ctx_native
   1052     );
   1053     return (jboolean)_returnValue;
   1054 }
   1055 
   1056 /* EGLBoolean eglMakeCurrent ( EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx ) */
   1057 static jboolean
   1058 android_eglMakeCurrent
   1059   (JNIEnv *_env, jobject _this, jobject dpy, jobject draw, jobject read, jobject ctx) {
   1060     EGLBoolean _returnValue = (EGLBoolean) 0;
   1061     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
   1062     EGLSurface draw_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, draw);
   1063     EGLSurface read_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, read);
   1064     EGLContext ctx_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, ctx);
   1065 
   1066     _returnValue = eglMakeCurrent(
   1067         (EGLDisplay)dpy_native,
   1068         (EGLSurface)draw_native,
   1069         (EGLSurface)read_native,
   1070         (EGLContext)ctx_native
   1071     );
   1072     return (jboolean)_returnValue;
   1073 }
   1074 
   1075 /* EGLContext eglGetCurrentContext ( void ) */
   1076 static jobject
   1077 android_eglGetCurrentContext
   1078   (JNIEnv *_env, jobject _this) {
   1079     EGLContext _returnValue = (EGLContext) 0;
   1080     _returnValue = eglGetCurrentContext();
   1081     return toEGLHandle(_env, eglcontextClass, eglcontextConstructor, _returnValue);
   1082 }
   1083 
   1084 /* EGLSurface eglGetCurrentSurface ( EGLint readdraw ) */
   1085 static jobject
   1086 android_eglGetCurrentSurface
   1087   (JNIEnv *_env, jobject _this, jint readdraw) {
   1088     EGLSurface _returnValue = (EGLSurface) 0;
   1089     _returnValue = eglGetCurrentSurface(
   1090         (EGLint)readdraw
   1091     );
   1092     return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
   1093 }
   1094 
   1095 /* EGLDisplay eglGetCurrentDisplay ( void ) */
   1096 static jobject
   1097 android_eglGetCurrentDisplay
   1098   (JNIEnv *_env, jobject _this) {
   1099     EGLDisplay _returnValue = (EGLDisplay) 0;
   1100     _returnValue = eglGetCurrentDisplay();
   1101     return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue);
   1102 }
   1103 
   1104 /* EGLBoolean eglQueryContext ( EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value ) */
   1105 static jboolean
   1106 android_eglQueryContext
   1107   (JNIEnv *_env, jobject _this, jobject dpy, jobject ctx, jint attribute, jintArray value_ref, jint offset) {
   1108     jint _exception = 0;
   1109     const char * _exceptionType = NULL;
   1110     const char * _exceptionMessage = NULL;
   1111     EGLBoolean _returnValue = (EGLBoolean) 0;
   1112     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
   1113     EGLContext ctx_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, ctx);
   1114     EGLint *value_base = (EGLint *) 0;
   1115     jint _remaining;
   1116     EGLint *value = (EGLint *) 0;
   1117 
   1118     if (!value_ref) {
   1119         _exception = 1;
   1120         _exceptionType = "java/lang/IllegalArgumentException";
   1121         _exceptionMessage = "value == null";
   1122         goto exit;
   1123     }
   1124     if (offset < 0) {
   1125         _exception = 1;
   1126         _exceptionType = "java/lang/IllegalArgumentException";
   1127         _exceptionMessage = "offset < 0";
   1128         goto exit;
   1129     }
   1130     _remaining = _env->GetArrayLength(value_ref) - offset;
   1131     if (_remaining < 1) {
   1132         _exception = 1;
   1133         _exceptionType = "java/lang/IllegalArgumentException";
   1134         _exceptionMessage = "length - offset < 1 < needed";
   1135         goto exit;
   1136     }
   1137     value_base = (EGLint *)
   1138         _env->GetIntArrayElements(value_ref, (jboolean *)0);
   1139     value = value_base + offset;
   1140 
   1141     _returnValue = eglQueryContext(
   1142         (EGLDisplay)dpy_native,
   1143         (EGLContext)ctx_native,
   1144         (EGLint)attribute,
   1145         (EGLint *)value
   1146     );
   1147 
   1148 exit:
   1149     if (value_base) {
   1150         _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
   1151             _exception ? JNI_ABORT: 0);
   1152     }
   1153     if (_exception) {
   1154         jniThrowException(_env, _exceptionType, _exceptionMessage);
   1155     }
   1156     return (jboolean)_returnValue;
   1157 }
   1158 
   1159 /* EGLBoolean eglWaitGL ( void ) */
   1160 static jboolean
   1161 android_eglWaitGL
   1162   (JNIEnv *_env, jobject _this) {
   1163     EGLBoolean _returnValue = (EGLBoolean) 0;
   1164     _returnValue = eglWaitGL();
   1165     return (jboolean)_returnValue;
   1166 }
   1167 
   1168 /* EGLBoolean eglWaitNative ( EGLint engine ) */
   1169 static jboolean
   1170 android_eglWaitNative
   1171   (JNIEnv *_env, jobject _this, jint engine) {
   1172     EGLBoolean _returnValue = (EGLBoolean) 0;
   1173     _returnValue = eglWaitNative(
   1174         (EGLint)engine
   1175     );
   1176     return (jboolean)_returnValue;
   1177 }
   1178 
   1179 /* EGLBoolean eglSwapBuffers ( EGLDisplay dpy, EGLSurface surface ) */
   1180 static jboolean
   1181 android_eglSwapBuffers
   1182   (JNIEnv *_env, jobject _this, jobject dpy, jobject surface) {
   1183     EGLBoolean _returnValue = (EGLBoolean) 0;
   1184     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
   1185     EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
   1186 
   1187     _returnValue = eglSwapBuffers(
   1188         (EGLDisplay)dpy_native,
   1189         (EGLSurface)surface_native
   1190     );
   1191     return (jboolean)_returnValue;
   1192 }
   1193 
   1194 /* EGLBoolean eglCopyBuffers ( EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target ) */
   1195 static jboolean
   1196 android_eglCopyBuffers
   1197   (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint target) {
   1198     jniThrowException(_env, "java/lang/UnsupportedOperationException",
   1199         "eglCopyBuffers");
   1200     return (EGLBoolean) 0;
   1201 }
   1202 
   1203 static const char *classPathName = "android/opengl/EGL14";
   1204 
   1205 static const JNINativeMethod methods[] = {
   1206 {"_nativeClassInit", "()V", (void*)nativeClassInit },
   1207 {"eglGetError", "()I", (void *) android_eglGetError },
   1208 {"eglGetDisplay", "(I)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplayInt },
   1209 {"eglGetDisplay", "(J)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplay },
   1210 {"eglInitialize", "(Landroid/opengl/EGLDisplay;[II[II)Z", (void *) android_eglInitialize },
   1211 {"eglTerminate", "(Landroid/opengl/EGLDisplay;)Z", (void *) android_eglTerminate },
   1212 {"eglQueryString", "(Landroid/opengl/EGLDisplay;I)Ljava/lang/String;", (void *) android_eglQueryString__Landroind_opengl_EGLDisplay_2I },
   1213 {"eglGetConfigs", "(Landroid/opengl/EGLDisplay;[Landroid/opengl/EGLConfig;II[II)Z", (void *) android_eglGetConfigs },
   1214 {"eglChooseConfig", "(Landroid/opengl/EGLDisplay;[II[Landroid/opengl/EGLConfig;II[II)Z", (void *) android_eglChooseConfig },
   1215 {"eglGetConfigAttrib", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;I[II)Z", (void *) android_eglGetConfigAttrib },
   1216 {"_eglCreateWindowSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/lang/Object;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreateWindowSurface },
   1217 {"_eglCreateWindowSurfaceTexture", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/lang/Object;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreateWindowSurfaceTexture },
   1218 {"eglCreatePbufferSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferSurface },
   1219 {"eglCreatePixmapSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;I[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePixmapSurface },
   1220 {"eglDestroySurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;)Z", (void *) android_eglDestroySurface },
   1221 {"eglQuerySurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I[II)Z", (void *) android_eglQuerySurface },
   1222 {"eglBindAPI", "(I)Z", (void *) android_eglBindAPI },
   1223 {"eglQueryAPI", "()I", (void *) android_eglQueryAPI },
   1224 {"eglWaitClient", "()Z", (void *) android_eglWaitClient },
   1225 {"eglReleaseThread", "()Z", (void *) android_eglReleaseThread },
   1226 {"eglCreatePbufferFromClientBuffer", "(Landroid/opengl/EGLDisplay;IILandroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferFromClientBufferInt },
   1227 {"eglCreatePbufferFromClientBuffer", "(Landroid/opengl/EGLDisplay;IJLandroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferFromClientBuffer },
   1228 {"eglSurfaceAttrib", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;II)Z", (void *) android_eglSurfaceAttrib },
   1229 {"eglBindTexImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglBindTexImage },
   1230 {"eglReleaseTexImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglReleaseTexImage },
   1231 {"eglSwapInterval", "(Landroid/opengl/EGLDisplay;I)Z", (void *) android_eglSwapInterval },
   1232 {"eglCreateContext", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Landroid/opengl/EGLContext;[II)Landroid/opengl/EGLContext;", (void *) android_eglCreateContext },
   1233 {"eglDestroyContext", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLContext;)Z", (void *) android_eglDestroyContext },
   1234 {"eglMakeCurrent", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;Landroid/opengl/EGLSurface;Landroid/opengl/EGLContext;)Z", (void *) android_eglMakeCurrent },
   1235 {"eglGetCurrentContext", "()Landroid/opengl/EGLContext;", (void *) android_eglGetCurrentContext },
   1236 {"eglGetCurrentSurface", "(I)Landroid/opengl/EGLSurface;", (void *) android_eglGetCurrentSurface },
   1237 {"eglGetCurrentDisplay", "()Landroid/opengl/EGLDisplay;", (void *) android_eglGetCurrentDisplay },
   1238 {"eglQueryContext", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLContext;I[II)Z", (void *) android_eglQueryContext },
   1239 {"eglWaitGL", "()Z", (void *) android_eglWaitGL },
   1240 {"eglWaitNative", "(I)Z", (void *) android_eglWaitNative },
   1241 {"eglSwapBuffers", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;)Z", (void *) android_eglSwapBuffers },
   1242 {"eglCopyBuffers", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglCopyBuffers },
   1243 };
   1244 
   1245 int register_android_opengl_jni_EGL14(JNIEnv *_env)
   1246 {
   1247     int err;
   1248     err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
   1249     return err;
   1250 }
   1251