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 19 #pragma GCC diagnostic ignored "-Wunused-variable" 20 #pragma GCC diagnostic ignored "-Wunused-function" 21 22 #include "jni.h" 23 #include <nativehelper/JNIPlatformHelp.h> 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 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 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"); 78 79 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"); 84 85 86 jclass eglClass = _env->FindClass("android/opengl/EGL14"); 87 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;"); 88 jobject localeglNoContextObject = _env->GetStaticObjectField(eglClass, noContextFieldID); 89 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); 90 91 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;"); 92 jobject localeglNoDisplayObject = _env->GetStaticObjectField(eglClass, noDisplayFieldID); 93 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); 94 95 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;"); 96 jobject localeglNoSurfaceObject = _env->GetStaticObjectField(eglClass, noSurfaceFieldID); 97 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); 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."); 105 return nullptr; 106 } 107 108 return reinterpret_cast<void*>(_env->CallLongMethod(obj, mid)); 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 128 return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle)); 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 150 static const JNINativeMethod methods[] = { 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 } 161