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