1 /* 2 ** Copyright 2012, 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/JNIHelp.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 32 #include <gui/Surface.h> 33 #include <gui/GLConsumer.h> 34 #include <gui/Surface.h> 35 36 #include <ui/ANativeObjectBase.h> 37 38 static jclass egldisplayClass; 39 static jclass eglcontextClass; 40 static jclass eglsurfaceClass; 41 static jclass eglconfigClass; 42 43 static jmethodID egldisplayGetHandleID; 44 static jmethodID eglcontextGetHandleID; 45 static jmethodID eglsurfaceGetHandleID; 46 static jmethodID eglconfigGetHandleID; 47 48 static jmethodID egldisplayConstructor; 49 static jmethodID eglcontextConstructor; 50 static jmethodID eglsurfaceConstructor; 51 static jmethodID eglconfigConstructor; 52 53 static jobject eglNoContextObject; 54 static jobject eglNoDisplayObject; 55 static jobject eglNoSurfaceObject; 56 57 58 59 /* Cache method IDs each time the class is loaded. */ 60 61 static void 62 nativeClassInit(JNIEnv *_env, jclass glImplClass) 63 { 64 jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay"); 65 egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal); 66 jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext"); 67 eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal); 68 jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface"); 69 eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal); 70 jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig"); 71 eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal); 72 73 egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J"); 74 eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J"); 75 eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J"); 76 eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J"); 77 78 79 egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V"); 80 eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V"); 81 eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V"); 82 eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V"); 83 84 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT)); 85 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); 86 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY)); 87 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); 88 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE)); 89 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); 90 91 92 jclass eglClass = _env->FindClass("android/opengl/EGL14"); 93 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;"); 94 _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject); 95 96 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;"); 97 _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject); 98 99 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;"); 100 _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject); 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 return nullptr; 109 } 110 111 jlong handle = _env->CallLongMethod(obj, mid); 112 return reinterpret_cast<void*>(handle); 113 } 114 115 static jobject 116 toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) { 117 if (cls == eglcontextClass && 118 (EGLContext)handle == EGL_NO_CONTEXT) { 119 return eglNoContextObject; 120 } 121 122 if (cls == egldisplayClass && 123 (EGLDisplay)handle == EGL_NO_DISPLAY) { 124 return eglNoDisplayObject; 125 } 126 127 if (cls == eglsurfaceClass && 128 (EGLSurface)handle == EGL_NO_SURFACE) { 129 return eglNoSurfaceObject; 130 } 131 132 return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle)); 133 } 134 135 // -------------------------------------------------------------------------- 136