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