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