blob: 568473c14dc50eef74024a6b337fb13b7e7a874f [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
Andreas Gampebfe63332014-11-12 14:12:45 -080019#pragma GCC diagnostic ignored "-Wunused-variable"
20#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
21#pragma GCC diagnostic ignored "-Wunused-function"
22
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070023#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>
Andy McFaddend47f7d82012-12-18 09:48:38 -080034#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080035#include <gui/Surface.h>
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070036
37#include <ui/ANativeObjectBase.h>
38
39static int initialized = 0;
40
41static jclass egldisplayClass;
42static jclass eglcontextClass;
43static jclass eglsurfaceClass;
44static jclass eglconfigClass;
45
46static jmethodID egldisplayGetHandleID;
47static jmethodID eglcontextGetHandleID;
48static jmethodID eglsurfaceGetHandleID;
49static jmethodID eglconfigGetHandleID;
50
51static jmethodID egldisplayConstructor;
52static jmethodID eglcontextConstructor;
53static jmethodID eglsurfaceConstructor;
54static jmethodID eglconfigConstructor;
55
56static jobject eglNoContextObject;
57static jobject eglNoDisplayObject;
58static jobject eglNoSurfaceObject;
59
60
61
62/* Cache method IDs each time the class is loaded. */
63
64static void
65nativeClassInit(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
Ashok Bhat84bbeb92014-02-24 10:06:55 +000076 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");
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070080
81
Ashok Bhat84bbeb92014-02-24 10:06:55 +000082 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");
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070086
Ashok Bhat84bbeb92014-02-24 10:06:55 +000087 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070088 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
Ashok Bhat84bbeb92014-02-24 10:06:55 +000089 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070090 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
Ashok Bhat84bbeb92014-02-24 10:06:55 +000091 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070092 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
106static void *
107fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
108 if (obj == NULL){
109 jniThrowException(_env, "java/lang/IllegalArgumentException",
110 "Object is set to null.");
111 }
112
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000113 jlong handle = _env->CallLongMethod(obj, mid);
114 return reinterpret_cast<void*>(handle);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700115}
116
117static jobject
118toEGLHandle(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
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000134 return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700135}
136
137// --------------------------------------------------------------------------
138/* EGLint eglGetError ( void ) */
139static jint
140android_eglGetError
141 (JNIEnv *_env, jobject _this) {
142 EGLint _returnValue = (EGLint) 0;
143 _returnValue = eglGetError();
Andy McFaddencee51982013-04-25 16:08:31 -0700144 return (jint)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700145}
146
147/* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */
148static jobject
149android_eglGetDisplay
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000150 (JNIEnv *_env, jobject _this, jlong display_id) {
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700151 EGLDisplay _returnValue = (EGLDisplay) 0;
152 _returnValue = eglGetDisplay(
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000153 reinterpret_cast<EGLNativeDisplayType>(display_id)
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700154 );
155 return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue);
156}
157
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000158/* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */
159static jobject
160android_eglGetDisplayInt
161 (JNIEnv *_env, jobject _this, jint display_id) {
162
Dan Albert10caf032015-02-23 10:41:10 -0800163 if (static_cast<uintptr_t>(display_id) !=
164 reinterpret_cast<uintptr_t>(EGL_DEFAULT_DISPLAY)) {
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000165 jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglGetDisplay");
166 return 0;
167 }
168 return android_eglGetDisplay(_env, _this, display_id);
169}
170
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700171/* EGLBoolean eglInitialize ( EGLDisplay dpy, EGLint *major, EGLint *minor ) */
172static jboolean
173android_eglInitialize
174 (JNIEnv *_env, jobject _this, jobject dpy, jintArray major_ref, jint majorOffset, jintArray minor_ref, jint minorOffset) {
175 jint _exception = 0;
Mathias Agopian15284de2013-02-23 03:12:30 -0800176 const char * _exceptionType = NULL;
177 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700178 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700207 _env->GetIntArrayElements(major_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700208 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700230 _env->GetIntArrayElements(minor_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700231 minor = minor_base + minorOffset;
232
233 _returnValue = eglInitialize(
234 (EGLDisplay)dpy_native,
235 (EGLint *)major,
236 (EGLint *)minor
237 );
238
239exit:
240 if (minor_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700241 _env->ReleaseIntArrayElements(minor_ref, (jint*)minor_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700242 _exception ? JNI_ABORT: 0);
243 }
244 if (major_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700245 _env->ReleaseIntArrayElements(major_ref, (jint*)major_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700246 _exception ? JNI_ABORT: 0);
247 }
248 if (_exception) {
249 jniThrowException(_env, _exceptionType, _exceptionMessage);
250 }
Andy McFaddencee51982013-04-25 16:08:31 -0700251 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700252}
253
254/* EGLBoolean eglTerminate ( EGLDisplay dpy ) */
255static jboolean
256android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -0700264 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700265}
266
267/* const char * eglQueryString ( EGLDisplay dpy, EGLint name ) */
268static jstring
269android_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 ) */
278static jboolean
279android_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;
Mathias Agopian15284de2013-02-23 03:12:30 -0800282 const char * _exceptionType = NULL;
283 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700284 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700327 _env->GetIntArrayElements(num_config_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700328 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
337exit:
338 if (num_config_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700339 _env->ReleaseIntArrayElements(num_config_ref, (jint*)num_config_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700340 _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 }
Andy McFaddencee51982013-04-25 16:08:31 -0700352 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700353}
354
355/* EGLBoolean eglChooseConfig ( EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */
356static jboolean
357android_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;
Mathias Agopian15284de2013-02-23 03:12:30 -0800360 const char * _exceptionType = NULL;
361 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700362 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700388 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700389 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700445 _env->GetIntArrayElements(num_config_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700446 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
456exit:
457 if (num_config_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700458 _env->ReleaseIntArrayElements(num_config_ref, (jint*)num_config_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700459 _exception ? JNI_ABORT: 0);
460 }
461 if (attrib_list_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700462 _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700463 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 }
Andy McFaddencee51982013-04-25 16:08:31 -0700475 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700476}
477
478/* EGLBoolean eglGetConfigAttrib ( EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value ) */
479static jboolean
480android_eglGetConfigAttrib
481 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint attribute, jintArray value_ref, jint offset) {
482 jint _exception = 0;
Mathias Agopian15284de2013-02-23 03:12:30 -0800483 const char * _exceptionType = NULL;
484 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700485 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700512 _env->GetIntArrayElements(value_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700513 value = value_base + offset;
514
515 _returnValue = eglGetConfigAttrib(
516 (EGLDisplay)dpy_native,
517 (EGLConfig)config_native,
518 (EGLint)attribute,
519 (EGLint *)value
520 );
521
522exit:
523 if (value_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700524 _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700525 _exception ? JNI_ABORT: 0);
526 }
527 if (_exception) {
528 jniThrowException(_env, _exceptionType, _exceptionMessage);
529 }
Andy McFaddencee51982013-04-25 16:08:31 -0700530 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700531}
532
533/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */
534static jobject
535android_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) {
562not_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
Jeff Brown64a55af2012-08-26 02:47:39 -0700569 window = android::android_view_Surface_getNativeWindow(_env, win);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700570
571 if (window == NULL)
572 goto not_valid_surface;
573
574 _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
575 attrib_list_base = (EGLint *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700576 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700577 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
599exit:
600 if (attrib_list_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700601 _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700602 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 ) */
611static jobject
612android_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;
Mathias Agopian52a9a102013-08-02 01:38:38 -0700625 android::sp<android::IGraphicBufferProducer> producer;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700626
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) {
640not_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 }
Mathias Agopian52a9a102013-08-02 01:38:38 -0700646 producer = android::SurfaceTexture_getProducer(_env, win);
Jamie Gennis82bb8132012-12-11 17:00:29 -0800647
Mathias Agopian52a9a102013-08-02 01:38:38 -0700648 if (producer == NULL)
Jamie Gennis82bb8132012-12-11 17:00:29 -0800649 goto not_valid_surface;
650
Takahiro Aizawaf9337372013-12-11 19:22:26 +0900651 window = new android::Surface(producer, true);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700652
653 if (window == NULL)
654 goto not_valid_surface;
655
656 _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
657 attrib_list_base = (EGLint *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700658 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700659 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
681exit:
682 if (attrib_list_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700683 _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700684 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 ) */
692static jobject
693android_eglCreatePbufferSurface
694 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jintArray attrib_list_ref, jint offset) {
695 jint _exception = 0;
Mathias Agopian15284de2013-02-23 03:12:30 -0800696 const char * _exceptionType = NULL;
697 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700698 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700720 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700721 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
742exit:
743 if (attrib_list_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700744 _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700745 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 ) */
754static jobject
755android_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 ) */
763static jboolean
764android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -0700774 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700775}
776
777/* EGLBoolean eglQuerySurface ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value ) */
778static jboolean
779android_eglQuerySurface
780 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jintArray value_ref, jint offset) {
781 jint _exception = 0;
Mathias Agopian15284de2013-02-23 03:12:30 -0800782 const char * _exceptionType = NULL;
783 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700784 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700811 _env->GetIntArrayElements(value_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700812 value = value_base + offset;
813
814 _returnValue = eglQuerySurface(
815 (EGLDisplay)dpy_native,
816 (EGLSurface)surface_native,
817 (EGLint)attribute,
818 (EGLint *)value
819 );
820
821exit:
822 if (value_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700823 _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700824 _exception ? JNI_ABORT: 0);
825 }
826 if (_exception) {
827 jniThrowException(_env, _exceptionType, _exceptionMessage);
828 }
Andy McFaddencee51982013-04-25 16:08:31 -0700829 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700830}
831
832/* EGLBoolean eglBindAPI ( EGLenum api ) */
833static jboolean
834android_eglBindAPI
835 (JNIEnv *_env, jobject _this, jint api) {
836 EGLBoolean _returnValue = (EGLBoolean) 0;
837 _returnValue = eglBindAPI(
838 (EGLenum)api
839 );
Andy McFaddencee51982013-04-25 16:08:31 -0700840 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700841}
842
843/* EGLenum eglQueryAPI ( void ) */
844static jint
845android_eglQueryAPI
846 (JNIEnv *_env, jobject _this) {
847 EGLenum _returnValue = (EGLenum) 0;
848 _returnValue = eglQueryAPI();
Andy McFaddencee51982013-04-25 16:08:31 -0700849 return (jint)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700850}
851
852/* EGLBoolean eglWaitClient ( void ) */
853static jboolean
854android_eglWaitClient
855 (JNIEnv *_env, jobject _this) {
856 EGLBoolean _returnValue = (EGLBoolean) 0;
857 _returnValue = eglWaitClient();
Andy McFaddencee51982013-04-25 16:08:31 -0700858 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700859}
860
861/* EGLBoolean eglReleaseThread ( void ) */
862static jboolean
863android_eglReleaseThread
864 (JNIEnv *_env, jobject _this) {
865 EGLBoolean _returnValue = (EGLBoolean) 0;
866 _returnValue = eglReleaseThread();
Andy McFaddencee51982013-04-25 16:08:31 -0700867 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700868}
869
870/* EGLSurface eglCreatePbufferFromClientBuffer ( EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list ) */
871static jobject
872android_eglCreatePbufferFromClientBuffer
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000873 (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 -0700874 jint _exception = 0;
Mathias Agopian15284de2013-02-23 03:12:30 -0800875 const char * _exceptionType = NULL;
876 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700877 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700899 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700900 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,
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000918 reinterpret_cast<EGLClientBuffer>(buffer),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700919 (EGLConfig)config_native,
920 (EGLint *)attrib_list
921 );
922
923exit:
924 if (attrib_list_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700925 _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700926 JNI_ABORT);
927 }
928 if (_exception) {
929 jniThrowException(_env, _exceptionType, _exceptionMessage);
930 }
931 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
932}
933
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000934static jobject
935android_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}
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700943/* EGLBoolean eglSurfaceAttrib ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value ) */
944static jboolean
945android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -0700957 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700958}
959
960/* EGLBoolean eglBindTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */
961static jboolean
962android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -0700973 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700974}
975
976/* EGLBoolean eglReleaseTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */
977static jboolean
978android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -0700989 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -0700990}
991
992/* EGLBoolean eglSwapInterval ( EGLDisplay dpy, EGLint interval ) */
993static jboolean
994android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -07001003 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001004}
1005
1006/* EGLContext eglCreateContext ( EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list ) */
1007static jobject
1008android_eglCreateContext
1009 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject share_context, jintArray attrib_list_ref, jint offset) {
1010 jint _exception = 0;
Mathias Agopian15284de2013-02-23 03:12:30 -08001011 const char * _exceptionType = NULL;
1012 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001013 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -07001036 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001037 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
1059exit:
1060 if (attrib_list_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -07001061 _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001062 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 ) */
1071static jboolean
1072android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -07001082 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001083}
1084
1085/* EGLBoolean eglMakeCurrent ( EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx ) */
1086static jboolean
1087android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -07001101 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001102}
1103
1104/* EGLContext eglGetCurrentContext ( void ) */
1105static jobject
1106android_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 ) */
1114static jobject
1115android_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 ) */
1125static jobject
1126android_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 ) */
1134static jboolean
1135android_eglQueryContext
1136 (JNIEnv *_env, jobject _this, jobject dpy, jobject ctx, jint attribute, jintArray value_ref, jint offset) {
1137 jint _exception = 0;
Mathias Agopian15284de2013-02-23 03:12:30 -08001138 const char * _exceptionType = NULL;
1139 const char * _exceptionMessage = NULL;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001140 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 *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -07001167 _env->GetIntArrayElements(value_ref, (jboolean *)0);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001168 value = value_base + offset;
1169
1170 _returnValue = eglQueryContext(
1171 (EGLDisplay)dpy_native,
1172 (EGLContext)ctx_native,
1173 (EGLint)attribute,
1174 (EGLint *)value
1175 );
1176
1177exit:
1178 if (value_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -07001179 _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001180 _exception ? JNI_ABORT: 0);
1181 }
1182 if (_exception) {
1183 jniThrowException(_env, _exceptionType, _exceptionMessage);
1184 }
Andy McFaddencee51982013-04-25 16:08:31 -07001185 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001186}
1187
1188/* EGLBoolean eglWaitGL ( void ) */
1189static jboolean
1190android_eglWaitGL
1191 (JNIEnv *_env, jobject _this) {
1192 EGLBoolean _returnValue = (EGLBoolean) 0;
1193 _returnValue = eglWaitGL();
Andy McFaddencee51982013-04-25 16:08:31 -07001194 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001195}
1196
1197/* EGLBoolean eglWaitNative ( EGLint engine ) */
1198static jboolean
1199android_eglWaitNative
1200 (JNIEnv *_env, jobject _this, jint engine) {
1201 EGLBoolean _returnValue = (EGLBoolean) 0;
1202 _returnValue = eglWaitNative(
1203 (EGLint)engine
1204 );
Andy McFaddencee51982013-04-25 16:08:31 -07001205 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001206}
1207
1208/* EGLBoolean eglSwapBuffers ( EGLDisplay dpy, EGLSurface surface ) */
1209static jboolean
1210android_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 );
Andy McFaddencee51982013-04-25 16:08:31 -07001220 return (jboolean)_returnValue;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001221}
1222
1223/* EGLBoolean eglCopyBuffers ( EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target ) */
1224static jboolean
1225android_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
1232static const char *classPathName = "android/opengl/EGL14";
1233
Daniel Micay76f6a862015-09-19 17:31:01 -04001234static const JNINativeMethod methods[] = {
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001235{"_nativeClassInit", "()V", (void*)nativeClassInit },
1236{"eglGetError", "()I", (void *) android_eglGetError },
Ashok Bhat84bbeb92014-02-24 10:06:55 +00001237{"eglGetDisplay", "(I)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplayInt },
1238{"eglGetDisplay", "(J)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplay },
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001239{"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 },
Ashok Bhat84bbeb92014-02-24 10:06:55 +00001255{"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 },
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001257{"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 },
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001272};
1273
1274int 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}