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