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-but-set-variable"
21 #pragma GCC diagnostic ignored "-Wunused-function"
22
23 #include "jni.h"
24 #include <nativehelper/JNIPlatformHelp.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
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
nativeClassInit(JNIEnv * _env,jclass glImplClass)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 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
86 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
87 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
88 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
89 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
90 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
91
92
93 jclass eglClass = _env->FindClass("android/opengl/EGL14");
94 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
95 _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
96
97 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
98 _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
99
100 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
101 _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
102 }
103
104 static void *
fromEGLHandle(JNIEnv * _env,jmethodID mid,jobject obj)105 fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
106 if (obj == NULL){
107 jniThrowException(_env, "java/lang/IllegalArgumentException",
108 "Object is set to null.");
109 return nullptr;
110 }
111
112 jlong handle = _env->CallLongMethod(obj, mid);
113 return reinterpret_cast<void*>(handle);
114 }
115
116 static jobject
toEGLHandle(JNIEnv * _env,jclass cls,jmethodID con,void * handle)117 toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) {
118 if (cls == eglcontextClass &&
119 (EGLContext)handle == EGL_NO_CONTEXT) {
120 return eglNoContextObject;
121 }
122
123 if (cls == egldisplayClass &&
124 (EGLDisplay)handle == EGL_NO_DISPLAY) {
125 return eglNoDisplayObject;
126 }
127
128 if (cls == eglsurfaceClass &&
129 (EGLSurface)handle == EGL_NO_SURFACE) {
130 return eglNoSurfaceObject;
131 }
132
133 return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
134 }
135
136 // --------------------------------------------------------------------------
137