Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 1 | /* |
| 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 Hodson | c240f22 | 2019-02-26 18:05:03 +0000 | [diff] [blame] | 17 | // This source file is automatically generated |
| 18 | |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 19 | #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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 28 | #include <vector> |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 29 | #include <EGL/egl.h> |
| 30 | |
| 31 | #include <ui/ANativeObjectBase.h> |
| 32 | |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 33 | // classes from EGL 1.4 |
| 34 | static jclass egldisplayClass; |
| 35 | static jclass eglsurfaceClass; |
| 36 | static jclass eglconfigClass; |
| 37 | static jclass eglcontextClass; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 38 | |
| 39 | static jmethodID egldisplayGetHandleID; |
| 40 | static jmethodID eglconfigGetHandleID; |
| 41 | static jmethodID eglcontextGetHandleID; |
| 42 | static jmethodID eglsurfaceGetHandleID; |
| 43 | |
| 44 | static jmethodID egldisplayConstructor; |
| 45 | static jmethodID eglcontextConstructor; |
| 46 | static jmethodID eglsurfaceConstructor; |
| 47 | static jmethodID eglconfigConstructor; |
| 48 | |
| 49 | static jobject eglNoContextObject; |
| 50 | static jobject eglNoDisplayObject; |
| 51 | static jobject eglNoSurfaceObject; |
| 52 | |
| 53 | // classes from EGL 1.5 |
| 54 | static jclass eglimageClass; |
| 55 | static jclass eglsyncClass; |
| 56 | |
| 57 | static jmethodID eglimageGetHandleID; |
| 58 | static jmethodID eglsyncGetHandleID; |
| 59 | |
| 60 | static jmethodID eglimageConstructor; |
| 61 | static jmethodID eglsyncConstructor; |
| 62 | |
| 63 | static jobject eglNoImageObject; |
| 64 | static jobject eglNoSyncObject; |
| 65 | |
| 66 | /* Cache method IDs each time the class is loaded. */ |
| 67 | |
| 68 | static void |
| 69 | nativeClassInit(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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 86 | 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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 98 | 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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 109 | 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 | |
| 127 | static void * |
| 128 | getPointer(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 Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 135 | pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 136 | *remaining = (limit - position) << elementSizeShift; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 137 | if (pointer != 0L) { |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 138 | *array = nullptr; |
| 139 | pointer += position << elementSizeShift; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 140 | return reinterpret_cast<void*>(pointer); |
| 141 | } |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 142 | |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 143 | *array = jniGetNioBufferBaseArray(_env, buffer); |
| 144 | *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); |
| 145 | return nullptr; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | static void |
| 149 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 150 | { |
| 151 | _env->ReleasePrimitiveArrayCritical(array, data, |
| 152 | commit ? 0 : JNI_ABORT); |
| 153 | } |
| 154 | |
| 155 | static void * |
| 156 | fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) { |
Orion Hodson | c240f22 | 2019-02-26 18:05:03 +0000 | [diff] [blame] | 157 | if (obj == NULL) { |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 158 | jniThrowException(_env, "java/lang/IllegalArgumentException", |
| 159 | "Object is set to null."); |
John Reck | 003fda0 | 2019-02-07 13:51:30 -0800 | [diff] [blame] | 160 | return nullptr; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | jlong handle = _env->CallLongMethod(obj, mid); |
| 164 | return reinterpret_cast<void*>(handle); |
| 165 | } |
| 166 | |
| 167 | static jobject |
Orion Hodson | c240f22 | 2019-02-26 18:05:03 +0000 | [diff] [blame] | 168 | toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void *handle) { |
| 169 | if (cls == eglimageClass && (EGLImage)handle == EGL_NO_IMAGE) { |
| 170 | return eglNoImageObject; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle)); |
| 174 | } |
| 175 | |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 176 | struct WrappedEGLAttribs { |
| 177 | private: |
| 178 | std::vector<EGLAttrib> backing; // only for 32-bit |
| 179 | public: |
| 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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 194 | // -------------------------------------------------------------------------- |
| 195 | /* EGLSync eglCreateSync ( EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list ) */ |
| 196 | static jobject |
| 197 | android_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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 204 | jlong *attrib_list_base = (jlong *) 0; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 205 | jint _remaining; |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 206 | WrappedEGLAttribs attrib_list; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 207 | |
| 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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 221 | attrib_list_base = (jlong *) |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 222 | _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0); |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 223 | attrib_list.init(attrib_list_base + offset, _remaining); |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 224 | |
| 225 | _returnValue = eglCreateSync( |
| 226 | (EGLDisplay)dpy_native, |
| 227 | (EGLenum)type, |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 228 | attrib_list.attribs |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 229 | ); |
| 230 | |
| 231 | exit: |
| 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 Reck | 003fda0 | 2019-02-07 13:51:30 -0800 | [diff] [blame] | 238 | return nullptr; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 239 | } |
| 240 | return toEGLHandle(_env, eglsyncClass, eglsyncConstructor, _returnValue); |
| 241 | } |
| 242 | |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 243 | /* EGLBoolean eglGetSyncAttrib ( EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value ) */ |
| 244 | static jboolean |
| 245 | android_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 | |
| 284 | exit: |
| 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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 296 | /* EGLBoolean eglDestroySync ( EGLDisplay dpy, EGLSync sync ) */ |
| 297 | static jboolean |
| 298 | android_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 ) */ |
| 312 | static jint |
| 313 | android_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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 328 | /* EGLDisplay eglGetPlatformDisplay ( EGLenum platform, EGLAttrib native_display, const EGLAttrib *attrib_list ) */ |
| 329 | static jobject |
| 330 | android_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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 336 | jlong *attrib_list_base = (jlong *) 0; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 337 | jint _remaining; |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 338 | WrappedEGLAttribs attrib_list; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 339 | |
| 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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 353 | attrib_list_base = (jlong *) |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 354 | _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0); |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 355 | attrib_list.init(attrib_list_base + offset, _remaining); |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 356 | |
| 357 | _returnValue = eglGetPlatformDisplay( |
| 358 | (EGLenum)platform, |
| 359 | (void *)native_display, |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 360 | attrib_list.attribs |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 361 | ); |
| 362 | |
| 363 | exit: |
| 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 Reck | 003fda0 | 2019-02-07 13:51:30 -0800 | [diff] [blame] | 370 | return nullptr; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 371 | } |
| 372 | return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue); |
| 373 | } |
| 374 | |
| 375 | /* EGLSurface eglCreatePlatformWindowSurface ( EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list ) */ |
| 376 | static jobject |
| 377 | android_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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 389 | jlong *attrib_list_base = (jlong *) 0; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 390 | jint _attrib_listRemaining; |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 391 | WrappedEGLAttribs attrib_list; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 392 | |
| 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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 413 | attrib_list_base = (jlong *) |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 414 | _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0); |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 415 | attrib_list.init(attrib_list_base + offset, _attrib_listRemaining); |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 416 | |
| 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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 425 | attrib_list.attribs |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 426 | ); |
| 427 | |
| 428 | exit: |
| 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 Reck | 003fda0 | 2019-02-07 13:51:30 -0800 | [diff] [blame] | 438 | return nullptr; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 439 | } |
| 440 | return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); |
| 441 | } |
| 442 | |
| 443 | /* EGLSurface eglCreatePlatformPixmapSurface ( EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list ) */ |
| 444 | static jobject |
| 445 | android_eglCreatePlatformPixmapSurface |
| 446 | (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject native_pixmap_buf, jlongArray attrib_list_ref, jint offset) { |
Orion Hodson | c240f22 | 2019-02-26 18:05:03 +0000 | [diff] [blame] | 447 | jniThrowException(_env, "java/lang/UnsupportedOperationException", |
| 448 | "eglCreatePlatformPixmapSurface"); |
John Reck | 003fda0 | 2019-02-07 13:51:30 -0800 | [diff] [blame] | 449 | return nullptr; |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /* EGLBoolean eglWaitSync ( EGLDisplay dpy, EGLSync sync, EGLint flags ) */ |
| 453 | static jboolean |
| 454 | android_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 Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 468 | /* EGLImage eglCreateImage ( EGLDisplay dpy, EGLContext context, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list ) */ |
| 469 | static jobject |
| 470 | android_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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 478 | jlong *attrib_list_base = (jlong *) 0; |
Courtney Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 479 | jint _remaining; |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 480 | WrappedEGLAttribs attrib_list; |
Courtney Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 481 | |
| 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 Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 495 | attrib_list_base = (jlong *) |
Courtney Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 496 | _env->GetLongArrayElements(attrib_list_ref, (jboolean *)0); |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 497 | attrib_list.init(attrib_list_base + offset, _remaining); |
Courtney Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 498 | |
| 499 | _returnValue = eglCreateImage( |
| 500 | (EGLDisplay)dpy_native, |
| 501 | (EGLContext)context_native, |
| 502 | (EGLenum)target, |
| 503 | (EGLClientBuffer)buffer, |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 504 | attrib_list.attribs |
Courtney Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 505 | ); |
| 506 | |
| 507 | exit: |
| 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 Reck | 003fda0 | 2019-02-07 13:51:30 -0800 | [diff] [blame] | 514 | return nullptr; |
Courtney Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 515 | } |
| 516 | return toEGLHandle(_env, eglimageClass, eglimageConstructor, _returnValue); |
| 517 | } |
Courtney Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 518 | /* EGLBoolean eglDestroyImage ( EGLDisplay dpy, EGLImage image ) */ |
| 519 | static jboolean |
| 520 | android_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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 533 | static const char *classPathName = "android/opengl/EGL15"; |
| 534 | |
| 535 | static const JNINativeMethod methods[] = { |
| 536 | {"_nativeClassInit", "()V", (void*)nativeClassInit }, |
| 537 | {"eglCreateSync", "(Landroid/opengl/EGLDisplay;I[JI)Landroid/opengl/EGLSync;", (void *) android_eglCreateSync }, |
Courtney Goeltzenleuchter | 43ef0c3 | 2019-04-03 17:30:40 -0600 | [diff] [blame] | 538 | {"eglGetSyncAttrib", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSync;I[JI)Z", (void *) android_eglGetSyncAttrib }, |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 539 | {"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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 541 | {"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 Goeltzenleuchter | 6e8c60c | 2018-10-19 11:19:53 -0600 | [diff] [blame] | 545 | {"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 Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | int 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 | } |