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 #include "jni.h"
20 #include "JNIHelp.h"
21 #include <android_runtime/AndroidRuntime.h>
22 #include <android_runtime/android_view_Surface.h>
23 #include <android_runtime/android_graphics_SurfaceTexture.h>
24 #include <utils/misc.h>
25
26 #include <assert.h>
27 #include <EGL/egl.h>
28
29 #include <gui/Surface.h>
30 #include <gui/GLConsumer.h>
31 #include <gui/Surface.h>
32
33 #include <ui/ANativeObjectBase.h>
34
35 static int initialized = 0;
36
37 static jclass egldisplayClass;
38 static jclass eglcontextClass;
39 static jclass eglsurfaceClass;
40 static jclass eglconfigClass;
41
42 static jmethodID egldisplayGetHandleID;
43 static jmethodID eglcontextGetHandleID;
44 static jmethodID eglsurfaceGetHandleID;
45 static jmethodID eglconfigGetHandleID;
46
47 static jmethodID egldisplayConstructor;
48 static jmethodID eglcontextConstructor;
49 static jmethodID eglsurfaceConstructor;
50 static jmethodID eglconfigConstructor;
51
52 static jobject eglNoContextObject;
53 static jobject eglNoDisplayObject;
54 static jobject eglNoSurfaceObject;
55
56
57
58 /* Cache method IDs each time the class is loaded. */
59
60 static void
nativeClassInit(JNIEnv * _env,jclass glImplClass)61 nativeClassInit(JNIEnv *_env, jclass glImplClass)
62 {
63 jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
64 egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
65 jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
66 eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
67 jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
68 eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
69 jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
70 eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
71
72 egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
73 eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
74 eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
75 eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
76
77
78 egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
79 eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
80 eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
81 eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
82
83 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
84 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
85 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
86 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
87 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
88 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
89
90
91 jclass eglClass = _env->FindClass("android/opengl/EGL14");
92 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
93 _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
94
95 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
96 _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
97
98 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
99 _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
100 }
101
102 static void *
fromEGLHandle(JNIEnv * _env,jmethodID mid,jobject obj)103 fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
104 if (obj == NULL){
105 jniThrowException(_env, "java/lang/IllegalArgumentException",
106 "Object is set to null.");
107 }
108
109 jlong handle = _env->CallLongMethod(obj, mid);
110 return reinterpret_cast<void*>(handle);
111 }
112
113 static jobject
toEGLHandle(JNIEnv * _env,jclass cls,jmethodID con,void * handle)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
130 return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
131 }
132
133 // --------------------------------------------------------------------------
134