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