EGL14cHeader.cpp revision 54c2818abe6d366815aec67dfcede1b1e008a52e
1** Copyright 2012, The Android Open Source Project 2** 3** Licensed under the Apache License, Version 2.0 (the "License"); 4** you may not use this file except in compliance with the License. 5** You may obtain a copy of the License at 6** 7** http://www.apache.org/licenses/LICENSE-2.0 8** 9** Unless required by applicable law or agreed to in writing, software 10** distributed under the License is distributed on an "AS IS" BASIS, 11** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12** See the License for the specific language governing permissions and 13** limitations under the License. 14*/ 15 16// This source file is automatically generated 17 18#include "jni.h" 19#include "JNIHelp.h" 20#include <android_runtime/AndroidRuntime.h> 21#include <android_runtime/android_view_Surface.h> 22#include <android_runtime/android_graphics_SurfaceTexture.h> 23#include <utils/misc.h> 24 25#include <assert.h> 26#include <EGL/egl.h> 27 28#include <gui/Surface.h> 29#include <gui/GLConsumer.h> 30#include <gui/Surface.h> 31 32#include <ui/ANativeObjectBase.h> 33 34static int initialized = 0; 35 36static jclass egldisplayClass; 37static jclass eglcontextClass; 38static jclass eglsurfaceClass; 39static jclass eglconfigClass; 40 41static jmethodID egldisplayGetHandleID; 42static jmethodID eglcontextGetHandleID; 43static jmethodID eglsurfaceGetHandleID; 44static jmethodID eglconfigGetHandleID; 45 46static jmethodID egldisplayConstructor; 47static jmethodID eglcontextConstructor; 48static jmethodID eglsurfaceConstructor; 49static jmethodID eglconfigConstructor; 50 51static jobject eglNoContextObject; 52static jobject eglNoDisplayObject; 53static jobject eglNoSurfaceObject; 54 55 56 57/* Cache method IDs each time the class is loaded. */ 58 59static void 60nativeClassInit(JNIEnv *_env, jclass glImplClass) 61{ 62 jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay"); 63 egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal); 64 jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext"); 65 eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal); 66 jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface"); 67 eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal); 68 jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig"); 69 eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal); 70 71 egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getHandle", "()I"); 72 eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getHandle", "()I"); 73 eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getHandle", "()I"); 74 eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getHandle", "()I"); 75 76 77 egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(I)V"); 78 eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(I)V"); 79 eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(I)V"); 80 eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(I)V"); 81 82 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, (jint)EGL_NO_CONTEXT); 83 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); 84 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, (jint)EGL_NO_DISPLAY); 85 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); 86 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, (jint)EGL_NO_SURFACE); 87 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); 88 89 90 jclass eglClass = _env->FindClass("android/opengl/EGL14"); 91 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;"); 92 _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject); 93 94 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;"); 95 _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject); 96 97 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;"); 98 _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject); 99} 100 101static void * 102fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) { 103 if (obj == NULL){ 104 jniThrowException(_env, "java/lang/IllegalArgumentException", 105 "Object is set to null."); 106 } 107 108 return (void*) (_env->CallIntMethod(obj, mid)); 109} 110 111static jobject 112toEGLHandle(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, (jint)handle); 129} 130 131// -------------------------------------------------------------------------- 132