1c86393510c8747519fe34e5aa38ce5218593c19cJesse Hall/*
266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** Copyright 2012, The Android Open Source Project
366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**
466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** Licensed under the Apache License, Version 2.0 (the "License");
566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** you may not use this file except in compliance with the License.
666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** You may obtain a copy of the License at
766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**
866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**     http://www.apache.org/licenses/LICENSE-2.0
966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**
1066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** Unless required by applicable law or agreed to in writing, software
1166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** distributed under the License is distributed on an "AS IS" BASIS,
1266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** See the License for the specific language governing permissions and
1466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** limitations under the License.
1566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer*/
1666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
1766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer// This source file is automatically generated
1866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
1966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include "jni.h"
2066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include "JNIHelp.h"
2166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <android_runtime/AndroidRuntime.h>
2266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <android_runtime/android_view_Surface.h>
2366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <android_runtime/android_graphics_SurfaceTexture.h>
2466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <utils/misc.h>
2566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
2666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <assert.h>
2766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <EGL/egl.h>
2866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
2966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <gui/Surface.h>
302adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden#include <gui/GLConsumer.h>
31e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <gui/Surface.h>
3266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
3366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer#include <ui/ANativeObjectBase.h>
3466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
3566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic int initialized = 0;
3666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
3766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jclass egldisplayClass;
3866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jclass eglcontextClass;
3966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jclass eglsurfaceClass;
4066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jclass eglconfigClass;
4166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
4266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID egldisplayGetHandleID;
4366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID eglcontextGetHandleID;
4466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID eglsurfaceGetHandleID;
4566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID eglconfigGetHandleID;
4666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
4766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID egldisplayConstructor;
4866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID eglcontextConstructor;
4966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID eglsurfaceConstructor;
5066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jmethodID eglconfigConstructor;
5166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
5266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jobject eglNoContextObject;
5366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jobject eglNoDisplayObject;
5466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jobject eglNoSurfaceObject;
5566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
5666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
5766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
5866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer/* Cache method IDs each time the class is loaded. */
5966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
6066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic void
6166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas TafertshofernativeClassInit(JNIEnv *_env, jclass glImplClass)
6266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer{
6366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
6466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
6566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
6666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
6766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
6866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
6966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
7066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
7166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
72ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
73ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
74ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
75ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
7666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
7766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
78ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
79ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
80ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
81ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
8266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
83ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
8466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
85ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
8666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
87ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
8866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
8966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
9066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
9166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jclass eglClass = _env->FindClass("android/opengl/EGL14");
9266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
9366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
9466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
9566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
9666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
9766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
9866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
9966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
10066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer}
10166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
10266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic void *
10366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas TafertshoferfromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
10466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (obj == NULL){
10566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        jniThrowException(_env, "java/lang/IllegalArgumentException",
10666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer                          "Object is set to null.");
10766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
10866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
109ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    jlong handle = _env->CallLongMethod(obj, mid);
110ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    return reinterpret_cast<void*>(handle);
11166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer}
11266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
11366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jobject
11466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas TafertshofertoEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) {
11566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (cls == eglcontextClass &&
11666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer       (EGLContext)handle == EGL_NO_CONTEXT) {
11766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer           return eglNoContextObject;
11866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
11966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
12066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (cls == egldisplayClass &&
12166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer       (EGLDisplay)handle == EGL_NO_DISPLAY) {
12266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer           return eglNoDisplayObject;
12366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
12466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
12566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (cls == eglsurfaceClass &&
12666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer       (EGLSurface)handle == EGL_NO_SURFACE) {
12766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer           return eglNoSurfaceObject;
12866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
12966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
130ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
13166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer}
13266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
13366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer// --------------------------------------------------------------------------
134