• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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 #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 int initialized = 0;
40 
41 static jclass egldisplayClass;
42 static jclass eglcontextClass;
43 static jclass eglsurfaceClass;
44 static jclass eglconfigClass;
45 
46 static jmethodID egldisplayGetHandleID;
47 static jmethodID eglcontextGetHandleID;
48 static jmethodID eglsurfaceGetHandleID;
49 static jmethodID eglconfigGetHandleID;
50 
51 static jmethodID egldisplayConstructor;
52 static jmethodID eglcontextConstructor;
53 static jmethodID eglsurfaceConstructor;
54 static jmethodID eglconfigConstructor;
55 
56 static jobject eglNoContextObject;
57 static jobject eglNoDisplayObject;
58 static jobject eglNoSurfaceObject;
59 
60 
61 
62 /* Cache method IDs each time the class is loaded. */
63 
64 static void
nativeClassInit(JNIEnv * _env,jclass glImplClass)65 nativeClassInit(JNIEnv *_env, jclass glImplClass)
66 {
67     jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
68     egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
69     jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
70     eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
71     jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
72     eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
73     jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
74     eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
75 
76     egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
77     eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
78     eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
79     eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
80 
81 
82     egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
83     eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
84     eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
85     eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
86 
87 
88     jclass eglClass = _env->FindClass("android/opengl/EGL14");
89     jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
90     jobject localeglNoContextObject = _env->GetStaticObjectField(eglClass, noContextFieldID);
91     eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
92 
93     jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
94     jobject localeglNoDisplayObject = _env->GetStaticObjectField(eglClass, noDisplayFieldID);
95     eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
96 
97     jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
98     jobject localeglNoSurfaceObject = _env->GetStaticObjectField(eglClass, noSurfaceFieldID);
99     eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
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     return reinterpret_cast<void*>(_env->CallLongMethod(obj, mid));
110 }
111 
112 static jobject
toEGLHandle(JNIEnv * _env,jclass cls,jmethodID con,void * handle)113 toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) {
114     if (cls == eglcontextClass &&
115        (EGLContext)handle == EGL_NO_CONTEXT) {
116            return eglNoContextObject;
117     }
118 
119     if (cls == egldisplayClass &&
120        (EGLDisplay)handle == EGL_NO_DISPLAY) {
121            return eglNoDisplayObject;
122     }
123 
124     if (cls == eglsurfaceClass &&
125        (EGLSurface)handle == EGL_NO_SURFACE) {
126            return eglNoSurfaceObject;
127     }
128 
129     return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
130 }
131 
132 // --------------------------------------------------------------------------
133 /* EGLBoolean eglPresentationTimeANDROID ( EGLDisplay dpy, EGLSurface sur, EGLnsecsANDROID time ) */
134 static jboolean
android_eglPresentationTimeANDROID(JNIEnv * _env,jobject _this,jobject dpy,jobject sur,jlong time)135 android_eglPresentationTimeANDROID
136   (JNIEnv *_env, jobject _this, jobject dpy, jobject sur, jlong time) {
137     EGLBoolean _returnValue = (EGLBoolean) 0;
138     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
139     EGLSurface sur_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, sur);
140 
141     _returnValue = eglPresentationTimeANDROID(
142         (EGLDisplay)dpy_native,
143         (EGLSurface)sur_native,
144         (EGLnsecsANDROID)time
145     );
146     return (jboolean)_returnValue;
147 }
148 
149 static const char *classPathName = "android/opengl/EGLExt";
150 
151 static const JNINativeMethod methods[] = {
152 {"_nativeClassInit", "()V", (void*)nativeClassInit },
153 {"eglPresentationTimeANDROID", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;J)Z", (void *) android_eglPresentationTimeANDROID },
154 };
155 
register_android_opengl_jni_EGLExt(JNIEnv * _env)156 int register_android_opengl_jni_EGLExt(JNIEnv *_env)
157 {
158     int err;
159     err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
160     return err;
161 }
162