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-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 #include <EGL/eglext.h>
33 
34 #include <gui/Surface.h>
35 #include <gui/GLConsumer.h>
36 #include <gui/Surface.h>
37 
38 #include <ui/ANativeObjectBase.h>
39 
40 static jclass egldisplayClass;
41 static jclass eglsurfaceClass;
42 static jclass eglsyncClass;
43 
44 static jmethodID egldisplayGetHandleID;
45 static jmethodID eglsurfaceGetHandleID;
46 static jmethodID eglsyncGetHandleID;
47 
48 /* Cache method IDs each time the class is loaded. */
49 
50 static void
nativeClassInit(JNIEnv * _env,jclass glImplClass)51 nativeClassInit(JNIEnv *_env, jclass glImplClass)
52 {
53     jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
54     egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
55     jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
56     eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
57     jclass eglsyncClassLocal = _env->FindClass("android/opengl/EGLSync");
58     eglsyncClass = (jclass) _env->NewGlobalRef(eglsyncClassLocal);
59 
60     egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
61     eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
62     eglsyncGetHandleID = _env->GetMethodID(eglsyncClass, "getNativeHandle", "()J");
63 }
64 
65 static void *
fromEGLHandle(JNIEnv * _env,jmethodID mid,jobject obj)66 fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
67     if (obj == NULL){
68         jniThrowException(_env, "java/lang/IllegalArgumentException",
69                           "Object is set to null.");
70         return nullptr;
71     }
72 
73     return reinterpret_cast<void*>(_env->CallLongMethod(obj, mid));
74 }
75 
76 // TODO: this should be generated from the .spec file, but needs to be renamed and made private
android_eglDupNativeFenceFDANDROID(JNIEnv * env,jobject,jobject dpy,jobject sync)77 static jint android_eglDupNativeFenceFDANDROID(JNIEnv *env, jobject, jobject dpy, jobject sync) {
78     EGLDisplay dpy_native = (EGLDisplay)fromEGLHandle(env, egldisplayGetHandleID, dpy);
79     EGLSync sync_native = (EGLSync)fromEGLHandle(env, eglsyncGetHandleID, sync);
80 
81     return eglDupNativeFenceFDANDROID(dpy_native, sync_native);
82 }
83 
84 // --------------------------------------------------------------------------
85 /* EGLBoolean eglPresentationTimeANDROID ( EGLDisplay dpy, EGLSurface sur, EGLnsecsANDROID time ) */
86 static jboolean
android_eglPresentationTimeANDROID(JNIEnv * _env,jobject _this,jobject dpy,jobject sur,jlong time)87 android_eglPresentationTimeANDROID
88   (JNIEnv *_env, jobject _this, jobject dpy, jobject sur, jlong time) {
89     EGLBoolean _returnValue = (EGLBoolean) 0;
90     EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
91     EGLSurface sur_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, sur);
92 
93     _returnValue = eglPresentationTimeANDROID(
94         (EGLDisplay)dpy_native,
95         (EGLSurface)sur_native,
96         (EGLnsecsANDROID)time
97     );
98     return (jboolean)_returnValue;
99 }
100 
101 static const char *classPathName = "android/opengl/EGLExt";
102 
103 static const JNINativeMethod methods[] = {
104 {"_nativeClassInit", "()V", (void*)nativeClassInit },
105 {"eglPresentationTimeANDROID", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;J)Z", (void *) android_eglPresentationTimeANDROID },
106 {"eglDupNativeFenceFDANDROIDImpl", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSync;)I", (void *)android_eglDupNativeFenceFDANDROID },
107 };
108 
register_android_opengl_jni_EGLExt(JNIEnv * _env)109 int register_android_opengl_jni_EGLExt(JNIEnv *_env)
110 {
111     int err;
112     err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
113     return err;
114 }
115