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