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