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