Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2013, 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 Gampe | bfe6333 | 2014-11-12 14:12:45 -0800 | [diff] [blame] | 19 | #pragma GCC diagnostic ignored "-Wunused-variable" |
Andreas Gampe | bfe6333 | 2014-11-12 14:12:45 -0800 | [diff] [blame] | 20 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 21 | |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 22 | #include "jni.h" |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 23 | #include <nativehelper/JNIHelp.h> |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 24 | #include <android_runtime/AndroidRuntime.h> |
| 25 | #include <android_runtime/android_view_Surface.h> |
| 26 | #include <android_runtime/android_graphics_SurfaceTexture.h> |
| 27 | #include <utils/misc.h> |
| 28 | |
| 29 | #include <assert.h> |
| 30 | #include <EGL/egl.h> |
| 31 | #include <EGL/eglext.h> |
| 32 | |
| 33 | #include <gui/Surface.h> |
| 34 | #include <gui/GLConsumer.h> |
| 35 | #include <gui/Surface.h> |
| 36 | |
| 37 | #include <ui/ANativeObjectBase.h> |
| 38 | |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 39 | static jclass egldisplayClass; |
| 40 | static jclass eglcontextClass; |
| 41 | static jclass eglsurfaceClass; |
| 42 | static jclass eglconfigClass; |
| 43 | |
| 44 | static jmethodID egldisplayGetHandleID; |
| 45 | static jmethodID eglcontextGetHandleID; |
| 46 | static jmethodID eglsurfaceGetHandleID; |
| 47 | static jmethodID eglconfigGetHandleID; |
| 48 | |
| 49 | static jmethodID egldisplayConstructor; |
| 50 | static jmethodID eglcontextConstructor; |
| 51 | static jmethodID eglsurfaceConstructor; |
| 52 | static jmethodID eglconfigConstructor; |
| 53 | |
| 54 | static jobject eglNoContextObject; |
| 55 | static jobject eglNoDisplayObject; |
| 56 | static jobject eglNoSurfaceObject; |
| 57 | |
| 58 | |
| 59 | |
| 60 | /* Cache method IDs each time the class is loaded. */ |
| 61 | |
| 62 | static void |
| 63 | nativeClassInit(JNIEnv *_env, jclass glImplClass) |
| 64 | { |
| 65 | jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay"); |
| 66 | egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal); |
| 67 | jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext"); |
| 68 | eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal); |
| 69 | jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface"); |
| 70 | eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal); |
| 71 | jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig"); |
| 72 | eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal); |
| 73 | |
Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 74 | egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J"); |
| 75 | eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J"); |
| 76 | eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J"); |
| 77 | eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J"); |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 78 | |
| 79 | |
Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 80 | egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V"); |
| 81 | eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V"); |
| 82 | eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V"); |
| 83 | eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V"); |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 84 | |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 85 | |
| 86 | jclass eglClass = _env->FindClass("android/opengl/EGL14"); |
| 87 | jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;"); |
Sangkyu Lee | c56c701 | 2014-11-07 18:54:59 +0900 | [diff] [blame] | 88 | jobject localeglNoContextObject = _env->GetStaticObjectField(eglClass, noContextFieldID); |
| 89 | eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 90 | |
| 91 | jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;"); |
Sangkyu Lee | c56c701 | 2014-11-07 18:54:59 +0900 | [diff] [blame] | 92 | jobject localeglNoDisplayObject = _env->GetStaticObjectField(eglClass, noDisplayFieldID); |
| 93 | eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 94 | |
| 95 | jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;"); |
Sangkyu Lee | c56c701 | 2014-11-07 18:54:59 +0900 | [diff] [blame] | 96 | jobject localeglNoSurfaceObject = _env->GetStaticObjectField(eglClass, noSurfaceFieldID); |
| 97 | eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void * |
| 101 | fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) { |
| 102 | if (obj == NULL){ |
| 103 | jniThrowException(_env, "java/lang/IllegalArgumentException", |
| 104 | "Object is set to null."); |
Orion Hodson | c240f22 | 2019-02-26 18:05:03 +0000 | [diff] [blame] | 105 | return nullptr; |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 108 | return reinterpret_cast<void*>(_env->CallLongMethod(obj, mid)); |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static jobject |
| 112 | toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) { |
| 113 | if (cls == eglcontextClass && |
| 114 | (EGLContext)handle == EGL_NO_CONTEXT) { |
| 115 | return eglNoContextObject; |
| 116 | } |
| 117 | |
| 118 | if (cls == egldisplayClass && |
| 119 | (EGLDisplay)handle == EGL_NO_DISPLAY) { |
| 120 | return eglNoDisplayObject; |
| 121 | } |
| 122 | |
| 123 | if (cls == eglsurfaceClass && |
| 124 | (EGLSurface)handle == EGL_NO_SURFACE) { |
| 125 | return eglNoSurfaceObject; |
| 126 | } |
| 127 | |
Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 128 | return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle)); |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | // -------------------------------------------------------------------------- |
| 132 | /* EGLBoolean eglPresentationTimeANDROID ( EGLDisplay dpy, EGLSurface sur, EGLnsecsANDROID time ) */ |
| 133 | static jboolean |
| 134 | android_eglPresentationTimeANDROID |
| 135 | (JNIEnv *_env, jobject _this, jobject dpy, jobject sur, jlong time) { |
| 136 | EGLBoolean _returnValue = (EGLBoolean) 0; |
| 137 | EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); |
| 138 | EGLSurface sur_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, sur); |
| 139 | |
| 140 | _returnValue = eglPresentationTimeANDROID( |
| 141 | (EGLDisplay)dpy_native, |
| 142 | (EGLSurface)sur_native, |
| 143 | (EGLnsecsANDROID)time |
| 144 | ); |
| 145 | return (jboolean)_returnValue; |
| 146 | } |
| 147 | |
| 148 | static const char *classPathName = "android/opengl/EGLExt"; |
| 149 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 150 | static const JNINativeMethod methods[] = { |
Jesse Hall | 0c79d80 | 2013-04-30 13:46:28 -0700 | [diff] [blame] | 151 | {"_nativeClassInit", "()V", (void*)nativeClassInit }, |
| 152 | {"eglPresentationTimeANDROID", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;J)Z", (void *) android_eglPresentationTimeANDROID }, |
| 153 | }; |
| 154 | |
| 155 | int register_android_opengl_jni_EGLExt(JNIEnv *_env) |
| 156 | { |
| 157 | int err; |
| 158 | err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods)); |
| 159 | return err; |
| 160 | } |