EGLExtcHeader.cpp revision b5da0d78d2fde6abbfd387db4a3b218a5c301c20
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 "JNIHelp.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
40static int initialized = 0;
41
42static jclass egldisplayClass;
43static jclass eglcontextClass;
44static jclass eglsurfaceClass;
45static jclass eglconfigClass;
46
47static jmethodID egldisplayGetHandleID;
48static jmethodID eglcontextGetHandleID;
49static jmethodID eglsurfaceGetHandleID;
50static jmethodID eglconfigGetHandleID;
51
52static jmethodID egldisplayConstructor;
53static jmethodID eglcontextConstructor;
54static jmethodID eglsurfaceConstructor;
55static jmethodID eglconfigConstructor;
56
57static jobject eglNoContextObject;
58static jobject eglNoDisplayObject;
59static jobject eglNoSurfaceObject;
60
61
62
63/* Cache method IDs each time the class is loaded. */
64
65static void
66nativeClassInit(JNIEnv *_env, jclass glImplClass)
67{
68    jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
69    egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
70    jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
71    eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
72    jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
73    eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
74    jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
75    eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
76
77    egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
78    eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
79    eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
80    eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
81
82
83    egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
84    eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
85    eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
86    eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
87
88    jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
89    eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
90    jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
91    eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
92    jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
93    eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
94
95
96    jclass eglClass = _env->FindClass("android/opengl/EGL14");
97    jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
98    _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
99
100    jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
101    _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
102
103    jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
104    _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
105}
106
107static void *
108fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
109    if (obj == NULL){
110        jniThrowException(_env, "java/lang/IllegalArgumentException",
111                          "Object is set to null.");
112    }
113
114    return reinterpret_cast<void*>(_env->CallLongMethod(obj, mid));
115}
116
117static jobject
118toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) {
119    if (cls == eglcontextClass &&
120       (EGLContext)handle == EGL_NO_CONTEXT) {
121           return eglNoContextObject;
122    }
123
124    if (cls == egldisplayClass &&
125       (EGLDisplay)handle == EGL_NO_DISPLAY) {
126           return eglNoDisplayObject;
127    }
128
129    if (cls == eglsurfaceClass &&
130       (EGLSurface)handle == EGL_NO_SURFACE) {
131           return eglNoSurfaceObject;
132    }
133
134    return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
135}
136
137// --------------------------------------------------------------------------
138