blob: 15899f50a9fe5c49143dd5bf9bcaf55b56c5a628 [file] [log] [blame]
Jesse Hall0c79d802013-04-30 13:46:28 -07001/*
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#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#include <EGL/eglext.h>
29
30#include <gui/Surface.h>
31#include <gui/GLConsumer.h>
32#include <gui/Surface.h>
33
34#include <ui/ANativeObjectBase.h>
35
36static int initialized = 0;
37
38static jclass egldisplayClass;
39static jclass eglcontextClass;
40static jclass eglsurfaceClass;
41static jclass eglconfigClass;
42
43static jmethodID egldisplayGetHandleID;
44static jmethodID eglcontextGetHandleID;
45static jmethodID eglsurfaceGetHandleID;
46static jmethodID eglconfigGetHandleID;
47
48static jmethodID egldisplayConstructor;
49static jmethodID eglcontextConstructor;
50static jmethodID eglsurfaceConstructor;
51static jmethodID eglconfigConstructor;
52
53static jobject eglNoContextObject;
54static jobject eglNoDisplayObject;
55static jobject eglNoSurfaceObject;
56
57
58
59/* Cache method IDs each time the class is loaded. */
60
61static void
62nativeClassInit(JNIEnv *_env, jclass glImplClass)
63{
64 jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
65 egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
66 jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
67 eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
68 jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
69 eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
70 jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
71 eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
72
Ashok Bhat84bbeb92014-02-24 10:06:55 +000073 egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
74 eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
75 eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
76 eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
Jesse Hall0c79d802013-04-30 13:46:28 -070077
78
Ashok Bhat84bbeb92014-02-24 10:06:55 +000079 egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
80 eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
81 eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
82 eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
Jesse Hall0c79d802013-04-30 13:46:28 -070083
Ashok Bhat84bbeb92014-02-24 10:06:55 +000084 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
Jesse Hall0c79d802013-04-30 13:46:28 -070085 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
Ashok Bhat84bbeb92014-02-24 10:06:55 +000086 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
Jesse Hall0c79d802013-04-30 13:46:28 -070087 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
Ashok Bhat84bbeb92014-02-24 10:06:55 +000088 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
Jesse Hall0c79d802013-04-30 13:46:28 -070089 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
90
91
92 jclass eglClass = _env->FindClass("android/opengl/EGL14");
93 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
94 _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
95
96 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
97 _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
98
99 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
100 _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
101}
102
103static void *
104fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
105 if (obj == NULL){
106 jniThrowException(_env, "java/lang/IllegalArgumentException",
107 "Object is set to null.");
108 }
109
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000110 return reinterpret_cast<void*>(_env->CallLongMethod(obj, mid));
Jesse Hall0c79d802013-04-30 13:46:28 -0700111}
112
113static jobject
114toEGLHandle(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
Ashok Bhat84bbeb92014-02-24 10:06:55 +0000130 return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
Jesse Hall0c79d802013-04-30 13:46:28 -0700131}
132
133// --------------------------------------------------------------------------
134/* EGLBoolean eglPresentationTimeANDROID ( EGLDisplay dpy, EGLSurface sur, EGLnsecsANDROID time ) */
135static jboolean
136android_eglPresentationTimeANDROID
137 (JNIEnv *_env, jobject _this, jobject dpy, jobject sur, jlong time) {
138 EGLBoolean _returnValue = (EGLBoolean) 0;
139 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
140 EGLSurface sur_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, sur);
141
142 _returnValue = eglPresentationTimeANDROID(
143 (EGLDisplay)dpy_native,
144 (EGLSurface)sur_native,
145 (EGLnsecsANDROID)time
146 );
147 return (jboolean)_returnValue;
148}
149
150static const char *classPathName = "android/opengl/EGLExt";
151
152static JNINativeMethod methods[] = {
153{"_nativeClassInit", "()V", (void*)nativeClassInit },
154{"eglPresentationTimeANDROID", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;J)Z", (void *) android_eglPresentationTimeANDROID },
155};
156
157int register_android_opengl_jni_EGLExt(JNIEnv *_env)
158{
159 int err;
160 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
161 return err;
162}