blob: 4aeed8765165482a456056c49918498b2b8af4aa [file] [log] [blame]
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -06001/*
2** Copyright 2018, 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
Orion Hodsonc240f222019-02-26 18:05:03 +000017// This source file is automatically generated
18
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060019#pragma GCC diagnostic ignored "-Wunused-variable"
20#pragma GCC diagnostic ignored "-Wunused-function"
21
22#include "jni.h"
23#include <nativehelper/JNIHelp.h>
24#include <android_runtime/AndroidRuntime.h>
25#include <utils/misc.h>
26
27#include <assert.h>
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -060028#include <vector>
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060029#include <EGL/egl.h>
30
31#include <ui/ANativeObjectBase.h>
32
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060033// classes from EGL 1.4
34static jclass egldisplayClass;
35static jclass eglsurfaceClass;
36static jclass eglconfigClass;
37static jclass eglcontextClass;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060038
39static jmethodID egldisplayGetHandleID;
40static jmethodID eglconfigGetHandleID;
41static jmethodID eglcontextGetHandleID;
42static jmethodID eglsurfaceGetHandleID;
43
44static jmethodID egldisplayConstructor;
45static jmethodID eglcontextConstructor;
46static jmethodID eglsurfaceConstructor;
47static jmethodID eglconfigConstructor;
48
49static jobject eglNoContextObject;
50static jobject eglNoDisplayObject;
51static jobject eglNoSurfaceObject;
52
53// classes from EGL 1.5
54static jclass eglimageClass;
55static jclass eglsyncClass;
56
57static jmethodID eglimageGetHandleID;
58static jmethodID eglsyncGetHandleID;
59
60static jmethodID eglimageConstructor;
61static jmethodID eglsyncConstructor;
62
63static jobject eglNoImageObject;
64static jobject eglNoSyncObject;
65
66/* Cache method IDs each time the class is loaded. */
67
68static void
69nativeClassInit(JNIEnv *_env, jclass glImplClass)
70{
71 // EGL 1.4 Init
72 jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
73 eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
74 jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
75 eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
76 jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
77 egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
78 jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
79 eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
80
81 eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
82 eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
83 egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
84 eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
85
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060086 eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
87 eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
88 egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
89 eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
90
91 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
92 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
93 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
94 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
95 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
96 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
97
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060098 jclass eglClass = _env->FindClass("android/opengl/EGL15");
99 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
100 _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
101
102 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
103 _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
104
105 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
106 _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
107
108 // EGL 1.5 init
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600109 jclass eglimageClassLocal = _env->FindClass("android/opengl/EGLImage");
110 eglimageClass = (jclass) _env->NewGlobalRef(eglimageClassLocal);
111 jclass eglsyncClassLocal = _env->FindClass("android/opengl/EGLSync");
112 eglsyncClass = (jclass) _env->NewGlobalRef(eglsyncClassLocal);
113
114 eglimageGetHandleID = _env->GetMethodID(eglimageClass, "getNativeHandle", "()J");
115 eglsyncGetHandleID = _env->GetMethodID(eglsyncClass, "getNativeHandle", "()J");
116
117 eglimageConstructor = _env->GetMethodID(eglimageClass, "<init>", "(J)V");
118 eglsyncConstructor = _env->GetMethodID(eglsyncClass, "<init>", "(J)V");
119
120 jfieldID noImageFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_IMAGE", "Landroid/opengl/EGLImage;");
121 _env->SetStaticObjectField(eglClass, noImageFieldID, eglNoImageObject);
122
123 jfieldID noSyncFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SYNC", "Landroid/opengl/EGLSync;");
124 _env->SetStaticObjectField(eglClass, noSyncFieldID, eglNoSyncObject);
125}
126
127static void *
128getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset)
129{
130 jint position;
131 jint limit;
132 jint elementSizeShift;
133 jlong pointer;
134
Orion Hodson02440d32019-02-28 15:15:34 +0000135 pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift);
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600136 *remaining = (limit - position) << elementSizeShift;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600137 if (pointer != 0L) {
Orion Hodson02440d32019-02-28 15:15:34 +0000138 *array = nullptr;
139 pointer += position << elementSizeShift;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600140 return reinterpret_cast<void*>(pointer);
141 }
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600142
Orion Hodson02440d32019-02-28 15:15:34 +0000143 *array = jniGetNioBufferBaseArray(_env, buffer);
144 *offset = jniGetNioBufferBaseArrayOffset(_env, buffer);
145 return nullptr;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600146}
147
148static void
149releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
150{
151 _env->ReleasePrimitiveArrayCritical(array, data,
152 commit ? 0 : JNI_ABORT);
153}
154
155static void *
156fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
Orion Hodsonc240f222019-02-26 18:05:03 +0000157 if (obj == NULL) {
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600158 jniThrowException(_env, "java/lang/IllegalArgumentException",
159 "Object is set to null.");
John Reck003fda02019-02-07 13:51:30 -0800160 return nullptr;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600161 }
162
163 jlong handle = _env->CallLongMethod(obj, mid);
164 return reinterpret_cast<void*>(handle);
165}
166
167static jobject
Orion Hodsonc240f222019-02-26 18:05:03 +0000168toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void *handle) {
169 if (cls == eglimageClass && (EGLImage)handle == EGL_NO_IMAGE) {
170 return eglNoImageObject;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600171 }
172
173 return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
174}
175
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600176struct WrappedEGLAttribs {
177private:
178 std::vector<EGLAttrib> backing; // only for 32-bit
179public:
180 EGLAttrib *attribs;
181 WrappedEGLAttribs(): attribs(nullptr) { };
182 void init(jlong *array, jint size) {
183 if (sizeof(EGLAttrib) != sizeof(jlong)) {
184 for (jint i = 0; i < size; ++i) {
185 backing.push_back(array[i]);
186 }
187 attribs = backing.data();
188 } else {
189 attribs = (EGLAttrib*)array;
190 }
191 }
192};
193
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600194// --------------------------------------------------------------------------
195/* EGLSync eglCreateSync ( EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list ) */
196static jobject
197android_eglCreateSync
198 (JNIEnv *_env, jobject _this, jobject dpy, jint type, jlongArray attrib_list_ref, jint offset) {
199 jint _exception = 0;
200 const char * _exceptionType = NULL;
201 const char * _exceptionMessage = NULL;
202 EGLSync _returnValue = (EGLSync) 0;
203 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600204 jlong *attrib_list_base = (jlong *) 0;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600205 jint _remaining;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600206 WrappedEGLAttribs attrib_list;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600207
208 if (!attrib_list_ref) {
209 _exception = 1;
210 _exceptionType = "java/lang/IllegalArgumentException";
211 _exceptionMessage = "attrib_list == null";
212 goto exit;
213 }
214 if (offset < 0) {
215 _exception = 1;
216 _exceptionType = "java/lang/IllegalArgumentException";
217 _exceptionMessage = "offset < 0";
218 goto exit;
219 }
220 _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600221 attrib_list_base = (jlong *)
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600222 _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0);
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600223 attrib_list.init(attrib_list_base + offset, _remaining);
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600224
225 _returnValue = eglCreateSync(
226 (EGLDisplay)dpy_native,
227 (EGLenum)type,
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600228 attrib_list.attribs
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600229 );
230
231exit:
232 if (attrib_list_base) {
233 _env->ReleaseLongArrayElements(attrib_list_ref, (jlong*)attrib_list_base,
234 JNI_ABORT);
235 }
236 if (_exception) {
237 jniThrowException(_env, _exceptionType, _exceptionMessage);
John Reck003fda02019-02-07 13:51:30 -0800238 return nullptr;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600239 }
240 return toEGLHandle(_env, eglsyncClass, eglsyncConstructor, _returnValue);
241}
242
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600243/* EGLBoolean eglGetSyncAttrib ( EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value ) */
244static jboolean
245android_eglGetSyncAttrib
246 (JNIEnv *_env, jobject _this, jobject dpy, jobject sync, jint attribute, jlongArray value_ref, jint offset) {
247 jint _exception = 0;
248 const char * _exceptionType = NULL;
249 const char * _exceptionMessage = NULL;
250 EGLBoolean _returnValue = (EGLBoolean) 0;
251 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
252 EGLSync sync_native = (EGLSync) fromEGLHandle(_env, eglsyncGetHandleID, sync);
253 jlong *value_base = (jlong *) 0;
254 jint _remaining;
255 EGLAttrib value;
256
257 if (!value_ref) {
258 _exception = 1;
259 _exceptionType = "java/lang/IllegalArgumentException";
260 _exceptionMessage = "value == null";
261 goto exit;
262 }
263 if (offset < 0) {
264 _exception = 1;
265 _exceptionType = "java/lang/IllegalArgumentException";
266 _exceptionMessage = "offset < 0";
267 goto exit;
268 }
269 _remaining = _env->GetArrayLength(value_ref) - offset;
270 value_base = (jlong *)
271 _env->GetLongArrayElements(value_ref, (jboolean *)0);
272
273 _returnValue = eglGetSyncAttrib(
274 (EGLDisplay)dpy_native,
275 (EGLSync)sync_native,
276 (EGLint)attribute,
277 &value
278 );
279
280 if (value_base && _returnValue == EGL_TRUE) {
281 *(value_base + offset) = (jlong) value;
282 }
283
284exit:
285 if (value_base) {
286 _env->ReleaseLongArrayElements(value_ref, (jlong*)value_base,
287 _exception ? JNI_ABORT: 0);
288 }
289 if (_exception) {
290 jniThrowException(_env, _exceptionType, _exceptionMessage);
291 return JNI_FALSE;
292 }
293 return (jboolean)_returnValue;
294}
295
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600296/* EGLBoolean eglDestroySync ( EGLDisplay dpy, EGLSync sync ) */
297static jboolean
298android_eglDestroySync
299 (JNIEnv *_env, jobject _this, jobject dpy, jobject sync) {
300 EGLBoolean _returnValue = (EGLBoolean) 0;
301 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
302 EGLSync sync_native = (EGLSync) fromEGLHandle(_env, eglsyncGetHandleID, sync);
303
304 _returnValue = eglDestroySync(
305 (EGLDisplay)dpy_native,
306 (EGLSync)sync_native
307 );
308 return (jboolean)_returnValue;
309}
310
311/* EGLint eglClientWaitSync ( EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout ) */
312static jint
313android_eglClientWaitSync
314 (JNIEnv *_env, jobject _this, jobject dpy, jobject sync, jint flags, jlong timeout) {
315 EGLint _returnValue = (EGLint) 0;
316 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
317 EGLSync sync_native = (EGLSync) fromEGLHandle(_env, eglsyncGetHandleID, sync);
318
319 _returnValue = eglClientWaitSync(
320 (EGLDisplay)dpy_native,
321 (EGLSync)sync_native,
322 (EGLint)flags,
323 (EGLTime)timeout
324 );
325 return (jint)_returnValue;
326}
327
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600328/* EGLDisplay eglGetPlatformDisplay ( EGLenum platform, EGLAttrib native_display, const EGLAttrib *attrib_list ) */
329static jobject
330android_eglGetPlatformDisplay
331 (JNIEnv *_env, jobject _this, jint platform, jlong native_display, jlongArray attrib_list_ref, jint offset) {
332 jint _exception = 0;
333 const char * _exceptionType = NULL;
334 const char * _exceptionMessage = NULL;
335 EGLDisplay _returnValue = (EGLDisplay) 0;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600336 jlong *attrib_list_base = (jlong *) 0;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600337 jint _remaining;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600338 WrappedEGLAttribs attrib_list;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600339
340 if (!attrib_list_ref) {
341 _exception = 1;
342 _exceptionType = "java/lang/IllegalArgumentException";
343 _exceptionMessage = "attrib_list == null";
344 goto exit;
345 }
346 if (offset < 0) {
347 _exception = 1;
348 _exceptionType = "java/lang/IllegalArgumentException";
349 _exceptionMessage = "offset < 0";
350 goto exit;
351 }
352 _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600353 attrib_list_base = (jlong *)
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600354 _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0);
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600355 attrib_list.init(attrib_list_base + offset, _remaining);
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600356
357 _returnValue = eglGetPlatformDisplay(
358 (EGLenum)platform,
359 (void *)native_display,
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600360 attrib_list.attribs
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600361 );
362
363exit:
364 if (attrib_list_base) {
365 _env->ReleaseLongArrayElements(attrib_list_ref, (jlong*)attrib_list_base,
366 JNI_ABORT);
367 }
368 if (_exception) {
369 jniThrowException(_env, _exceptionType, _exceptionMessage);
John Reck003fda02019-02-07 13:51:30 -0800370 return nullptr;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600371 }
372 return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue);
373}
374
375/* EGLSurface eglCreatePlatformWindowSurface ( EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list ) */
376static jobject
377android_eglCreatePlatformWindowSurface
378 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject native_window_buf, jlongArray attrib_list_ref, jint offset) {
379 jint _exception = 0;
380 const char * _exceptionType = NULL;
381 const char * _exceptionMessage = NULL;
382 jarray _array = (jarray) 0;
383 jint _bufferOffset = (jint) 0;
384 EGLSurface _returnValue = (EGLSurface) 0;
385 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
386 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
387 jint _native_windowRemaining;
388 void *native_window = (void *) 0;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600389 jlong *attrib_list_base = (jlong *) 0;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600390 jint _attrib_listRemaining;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600391 WrappedEGLAttribs attrib_list;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600392
393 if (!native_window_buf) {
394 _exception = 1;
395 _exceptionType = "java/lang/IllegalArgumentException";
396 _exceptionMessage = "native_window == null";
397 goto exit;
398 }
399 native_window = (void *)getPointer(_env, native_window_buf, (jarray*)&_array, &_native_windowRemaining, &_bufferOffset);
400 if (!attrib_list_ref) {
401 _exception = 1;
402 _exceptionType = "java/lang/IllegalArgumentException";
403 _exceptionMessage = "attrib_list == null";
404 goto exit;
405 }
406 if (offset < 0) {
407 _exception = 1;
408 _exceptionType = "java/lang/IllegalArgumentException";
409 _exceptionMessage = "offset < 0";
410 goto exit;
411 }
412 _attrib_listRemaining = _env->GetArrayLength(attrib_list_ref) - offset;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600413 attrib_list_base = (jlong *)
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600414 _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0);
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600415 attrib_list.init(attrib_list_base + offset, _attrib_listRemaining);
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600416
417 if (native_window == NULL) {
418 char * _native_windowBase = (char *)_env->GetPrimitiveArrayCritical(_array, (jboolean *) 0);
419 native_window = (void *) (_native_windowBase + _bufferOffset);
420 }
421 _returnValue = eglCreatePlatformWindowSurface(
422 (EGLDisplay)dpy_native,
423 (EGLConfig)config_native,
424 (void *)native_window,
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600425 attrib_list.attribs
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600426 );
427
428exit:
429 if (attrib_list_base) {
430 _env->ReleaseLongArrayElements(attrib_list_ref, (jlong*)attrib_list_base,
431 JNI_ABORT);
432 }
433 if (_array) {
434 releasePointer(_env, _array, native_window, _exception ? JNI_FALSE : JNI_TRUE);
435 }
436 if (_exception) {
437 jniThrowException(_env, _exceptionType, _exceptionMessage);
John Reck003fda02019-02-07 13:51:30 -0800438 return nullptr;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600439 }
440 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
441}
442
443/* EGLSurface eglCreatePlatformPixmapSurface ( EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list ) */
444static jobject
445android_eglCreatePlatformPixmapSurface
446 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject native_pixmap_buf, jlongArray attrib_list_ref, jint offset) {
Orion Hodsonc240f222019-02-26 18:05:03 +0000447 jniThrowException(_env, "java/lang/UnsupportedOperationException",
448 "eglCreatePlatformPixmapSurface");
John Reck003fda02019-02-07 13:51:30 -0800449 return nullptr;
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600450}
451
452/* EGLBoolean eglWaitSync ( EGLDisplay dpy, EGLSync sync, EGLint flags ) */
453static jboolean
454android_eglWaitSync
455 (JNIEnv *_env, jobject _this, jobject dpy, jobject sync, jint flags) {
456 EGLBoolean _returnValue = (EGLBoolean) 0;
457 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
458 EGLSync sync_native = (EGLSync) fromEGLHandle(_env, eglsyncGetHandleID, sync);
459
460 _returnValue = eglWaitSync(
461 (EGLDisplay)dpy_native,
462 (EGLSync)sync_native,
463 (EGLint)flags
464 );
465 return (jboolean)_returnValue;
466}
467
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600468/* EGLImage eglCreateImage ( EGLDisplay dpy, EGLContext context, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list ) */
469static jobject
470android_eglCreateImage
471 (JNIEnv *_env, jobject _this, jobject dpy, jobject context, jint target, jlong buffer, jlongArray attrib_list_ref, jint offset) {
472 jint _exception = 0;
473 const char * _exceptionType = NULL;
474 const char * _exceptionMessage = NULL;
475 EGLImage _returnValue = (EGLImage) 0;
476 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
477 EGLContext context_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, context);
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600478 jlong *attrib_list_base = (jlong *) 0;
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600479 jint _remaining;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600480 WrappedEGLAttribs attrib_list;
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600481
482 if (!attrib_list_ref) {
483 _exception = 1;
484 _exceptionType = "java/lang/IllegalArgumentException";
485 _exceptionMessage = "attrib_list == null";
486 goto exit;
487 }
488 if (offset < 0) {
489 _exception = 1;
490 _exceptionType = "java/lang/IllegalArgumentException";
491 _exceptionMessage = "offset < 0";
492 goto exit;
493 }
494 _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600495 attrib_list_base = (jlong *)
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600496 _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0);
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600497 attrib_list.init(attrib_list_base + offset, _remaining);
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600498
499 _returnValue = eglCreateImage(
500 (EGLDisplay)dpy_native,
501 (EGLContext)context_native,
502 (EGLenum)target,
503 (EGLClientBuffer)buffer,
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600504 attrib_list.attribs
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600505 );
506
507exit:
508 if (attrib_list_base) {
509 _env->ReleaseLongArrayElements(attrib_list_ref, (jlong*)attrib_list_base,
510 JNI_ABORT);
511 }
512 if (_exception) {
513 jniThrowException(_env, _exceptionType, _exceptionMessage);
John Reck003fda02019-02-07 13:51:30 -0800514 return nullptr;
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600515 }
516 return toEGLHandle(_env, eglimageClass, eglimageConstructor, _returnValue);
517}
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600518/* EGLBoolean eglDestroyImage ( EGLDisplay dpy, EGLImage image ) */
519static jboolean
520android_eglDestroyImage
521 (JNIEnv *_env, jobject _this, jobject dpy, jobject image) {
522 EGLBoolean _returnValue = (EGLBoolean) 0;
523 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
524 EGLImage image_native = (EGLImage) fromEGLHandle(_env, eglimageGetHandleID, image);
525
526 _returnValue = eglDestroyImage(
527 (EGLDisplay)dpy_native,
528 (EGLImage)image_native
529 );
530 return (jboolean)_returnValue;
531}
532
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600533static const char *classPathName = "android/opengl/EGL15";
534
535static const JNINativeMethod methods[] = {
536{"_nativeClassInit", "()V", (void*)nativeClassInit },
537{"eglCreateSync", "(Landroid/opengl/EGLDisplay;I[JI)Landroid/opengl/EGLSync;", (void *) android_eglCreateSync },
Courtney Goeltzenleuchter43ef0c32019-04-03 17:30:40 -0600538{"eglGetSyncAttrib", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSync;I[JI)Z", (void *) android_eglGetSyncAttrib },
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600539{"eglDestroySync", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSync;)Z", (void *) android_eglDestroySync },
540{"eglClientWaitSync", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSync;IJ)I", (void *) android_eglClientWaitSync },
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600541{"eglGetPlatformDisplay", "(IJ[JI)Landroid/opengl/EGLDisplay;", (void *) android_eglGetPlatformDisplay },
542{"eglCreatePlatformWindowSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/nio/Buffer;[JI)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePlatformWindowSurface },
543{"eglCreatePlatformPixmapSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/nio/Buffer;[JI)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePlatformPixmapSurface },
544{"eglWaitSync", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSync;I)Z", (void *) android_eglWaitSync },
Courtney Goeltzenleuchter6e8c60c2018-10-19 11:19:53 -0600545{"eglCreateImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLContext;IJ[JI)Landroid/opengl/EGLImage;", (void *) android_eglCreateImage },
546{"eglDestroyImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLImage;)Z", (void *) android_eglDestroyImage },
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -0600547};
548
549int register_android_opengl_jni_EGL15(JNIEnv *_env)
550{
551 int err;
552 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
553 return err;
554}