16b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/*
26b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** Copyright 2012, The Android Open Source Project
36b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**
46b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** Licensed under the Apache License, Version 2.0 (the "License");
56b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** you may not use this file except in compliance with the License.
66b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** You may obtain a copy of the License at
76b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**
86b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**     http://www.apache.org/licenses/LICENSE-2.0
96b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**
106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** Unless required by applicable law or agreed to in writing, software
116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** distributed under the License is distributed on an "AS IS" BASIS,
126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** See the License for the specific language governing permissions and
146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** limitations under the License.
156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer*/
166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer// This source file is automatically generated
186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include "jni.h"
206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include "JNIHelp.h"
216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <android_runtime/AndroidRuntime.h>
226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <android_runtime/android_view_Surface.h>
236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <android_runtime/android_graphics_SurfaceTexture.h>
246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <utils/misc.h>
256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <assert.h>
276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <EGL/egl.h>
286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <gui/Surface.h>
30d47f7d8b5fe3a3861d7cbdc5f912235407823c8eAndy McFadden#include <gui/GLConsumer.h>
3152800617946c456e78ed010c82d0ec4358368164Mathias Agopian#include <gui/Surface.h>
326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer#include <ui/ANativeObjectBase.h>
346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic int initialized = 0;
366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jclass egldisplayClass;
386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jclass eglcontextClass;
396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jclass eglsurfaceClass;
406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jclass eglconfigClass;
416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID egldisplayGetHandleID;
436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID eglcontextGetHandleID;
446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID eglsurfaceGetHandleID;
456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID eglconfigGetHandleID;
466b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID egldisplayConstructor;
486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID eglcontextConstructor;
496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID eglsurfaceConstructor;
506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jmethodID eglconfigConstructor;
516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject eglNoContextObject;
536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject eglNoDisplayObject;
546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject eglNoSurfaceObject;
556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* Cache method IDs each time the class is loaded. */
596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic void
616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas TafertshofernativeClassInit(JNIEnv *_env, jclass glImplClass)
626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer{
636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7284bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
7384bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
7484bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
7584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7884bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
7984bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
8084bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
8184bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8384bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
8584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
8784bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jclass eglClass = _env->FindClass("android/opengl/EGL14");
926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
1006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
1016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
1026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic void *
1036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas TafertshoferfromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
1046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (obj == NULL){
1056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, "java/lang/IllegalArgumentException",
1066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer                          "Object is set to null.");
1076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
1086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
10984bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    jlong handle = _env->CallLongMethod(obj, mid);
11084bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    return reinterpret_cast<void*>(handle);
1116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
1126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
1136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
1146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas TafertshofertoEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) {
1156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (cls == eglcontextClass &&
1166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer       (EGLContext)handle == EGL_NO_CONTEXT) {
1176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer           return eglNoContextObject;
1186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
1196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
1206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (cls == egldisplayClass &&
1216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer       (EGLDisplay)handle == EGL_NO_DISPLAY) {
1226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer           return eglNoDisplayObject;
1236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
1246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
1256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (cls == eglsurfaceClass &&
1266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer       (EGLSurface)handle == EGL_NO_SURFACE) {
1276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer           return eglNoSurfaceObject;
1286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
1296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
13084bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
1316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
1326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
1336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer// --------------------------------------------------------------------------
1346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLint eglGetError ( void ) */
1356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jint
1366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglGetError
1376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this) {
1386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint _returnValue = (EGLint) 0;
1396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglGetError();
140cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jint)_returnValue;
1416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
1426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
1436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */
1446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
1456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglGetDisplay
14684bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat  (JNIEnv *_env, jobject _this, jlong display_id) {
1476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay _returnValue = (EGLDisplay) 0;
1486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglGetDisplay(
14984bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        reinterpret_cast<EGLNativeDisplayType>(display_id)
1506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
1516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue);
1526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
1536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
15484bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat/* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */
15584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhatstatic jobject
15684bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhatandroid_eglGetDisplayInt
15784bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat  (JNIEnv *_env, jobject _this, jint display_id) {
15884bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat
15964d38d9f4863f6e9434e6820b924eb958e8a2230Ashok Bhat    if ((EGLNativeDisplayType)display_id != EGL_DEFAULT_DISPLAY) {
16084bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglGetDisplay");
16184bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        return 0;
16284bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    }
16384bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    return android_eglGetDisplay(_env, _this, display_id);
16484bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat}
16584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat
1666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglInitialize ( EGLDisplay dpy, EGLint *major, EGLint *minor ) */
1676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
1686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglInitialize
1696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jintArray major_ref, jint majorOffset, jintArray minor_ref, jint minorOffset) {
1706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
17115284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionType = NULL;
17215284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionMessage = NULL;
1736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
1746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
1756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *major_base = (EGLint *) 0;
1766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _majorRemaining;
1776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *major = (EGLint *) 0;
1786b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *minor_base = (EGLint *) 0;
1796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _minorRemaining;
1806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *minor = (EGLint *) 0;
1816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
1826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!major_ref) {
1836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
1846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
1856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "major == null";
1866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
1876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
1886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (majorOffset < 0) {
1896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
1906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
1916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "majorOffset < 0";
1926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
1936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
1946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _majorRemaining = _env->GetArrayLength(major_ref) - majorOffset;
1956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_majorRemaining < 1) {
1966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
1976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
1986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "length - majorOffset < 1 < needed";
1996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
2006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    major_base = (EGLint *)
2026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(major_ref, (jboolean *)0);
2036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    major = major_base + majorOffset;
2046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
2056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!minor_ref) {
2066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
2076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
2086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "minor == null";
2096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
2106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (minorOffset < 0) {
2126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
2136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
2146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "minorOffset < 0";
2156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
2166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _minorRemaining = _env->GetArrayLength(minor_ref) - minorOffset;
2186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_minorRemaining < 1) {
2196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
2206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
2216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "length - minorOffset < 1 < needed";
2226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
2236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    minor_base = (EGLint *)
2256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(minor_ref, (jboolean *)0);
2266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    minor = minor_base + minorOffset;
2276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
2286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglInitialize(
2296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
2306b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)major,
2316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)minor
2326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
2336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
2346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
2356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (minor_base) {
2366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(minor_ref, minor_base,
2376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _exception ? JNI_ABORT: 0);
2386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (major_base) {
2406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(major_ref, major_base,
2416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _exception ? JNI_ABORT: 0);
2426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
2446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
2456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
246cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
2476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
2486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
2496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglTerminate ( EGLDisplay dpy ) */
2506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
2516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglTerminate
2526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy) {
2536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
2546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
2556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
2566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglTerminate(
2576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native
2586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
259cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
2606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
2616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
2626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* const char * eglQueryString ( EGLDisplay dpy, EGLint name ) */
2636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jstring
2646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglQueryString__Landroind_opengl_EGLDisplay_2I
2656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jint name) {
2666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    const char* chars = (const char*) eglQueryString(
2676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)fromEGLHandle(_env, egldisplayGetHandleID, dpy),
2686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)name
2696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
2706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    return _env->NewStringUTF(chars);
2716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
2726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglGetConfigs ( EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */
2736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
2746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglGetConfigs
2756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) {
2766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
27715284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionType = NULL;
27815284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionMessage = NULL;
2796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
2806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
2816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _configsRemaining;
2826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLConfig *configs = (EGLConfig *) 0;
2836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *num_config_base = (EGLint *) 0;
2846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _num_configRemaining;
2856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *num_config = (EGLint *) 0;
2866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
2876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!configs_ref) {
2886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
2896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
2906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "configs == null";
2916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
2926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (configsOffset < 0) {
2946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
2956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
2966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "configsOffset < 0";
2976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
2986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
2996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset;
3006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_configsRemaining < config_size) {
3016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
3026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
3036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "length - configsOffset < config_size < needed";
3046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
3056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    configs = new EGLConfig[_configsRemaining];
3076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
3086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!num_config_ref) {
3096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
3106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
3116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "num_config == null";
3126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
3136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (num_configOffset < 0) {
3156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
3166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
3176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "num_configOffset < 0";
3186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
3196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset;
3216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    num_config_base = (EGLint *)
3226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0);
3236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    num_config = num_config_base + num_configOffset;
3246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
3256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglGetConfigs(
3266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
3276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLConfig *)configs,
3286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)config_size,
3296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)num_config
3306b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
3316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
3326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
3336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (num_config_base) {
3346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base,
3356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _exception ? JNI_ABORT: 0);
3366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (configs) {
3386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        for (int i = 0; i < _configsRemaining; i++) {
3396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]);
3406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new);
3416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        }
3426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        delete[] configs;
3436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
3456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
3466b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
347cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
3486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
3496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
3506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglChooseConfig ( EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */
3516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
3526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglChooseConfig
3536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jintArray attrib_list_ref, jint attrib_listOffset, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) {
3546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
35515284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionType = NULL;
35615284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionMessage = NULL;
3576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
3586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
3596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    bool attrib_list_sentinel = false;
3606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list_base = (EGLint *) 0;
3616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _attrib_listRemaining;
3626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list = (EGLint *) 0;
3636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _configsRemaining;
3646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLConfig *configs = (EGLConfig *) 0;
3656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *num_config_base = (EGLint *) 0;
3666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _num_configRemaining;
3676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *num_config = (EGLint *) 0;
3686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
3696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!attrib_list_ref) {
3706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
3716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
3726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list == null";
3736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
3746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_listOffset < 0) {
3766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
3776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
3786b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_listOffset < 0";
3796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
3806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _attrib_listRemaining = _env->GetArrayLength(attrib_list_ref) - attrib_listOffset;
3826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_base = (EGLint *)
3836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
3846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list = attrib_list_base + attrib_listOffset;
3856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_sentinel = false;
3866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    for (int i = _attrib_listRemaining - 1; i >= 0; i--)  {
3876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        if (attrib_list[i] == EGL_NONE){
3886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            attrib_list_sentinel = true;
3896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            break;
3906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        }
3916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_sentinel == false) {
3936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
3946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
3956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list must contain EGL_NONE!";
3966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
3976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
3996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!configs_ref) {
4006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "configs == null";
4036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (configsOffset < 0) {
4066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "configsOffset < 0";
4096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset;
4126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_configsRemaining < config_size) {
4136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "length - configsOffset < config_size < needed";
4166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    configs = new EGLConfig[_configsRemaining];
4196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
4206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!num_config_ref) {
4216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "num_config == null";
4246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (num_configOffset < 0) {
4276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "num_configOffset < 0";
4306b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset;
4336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_num_configRemaining < 1) {
4346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "length - num_configOffset < 1 < needed";
4376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    num_config_base = (EGLint *)
4406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0);
4416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    num_config = num_config_base + num_configOffset;
4426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
4436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglChooseConfig(
4446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
4456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)attrib_list,
4466b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLConfig *)configs,
4476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)config_size,
4486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)num_config
4496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
4506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
4516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
4526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (num_config_base) {
4536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base,
4546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _exception ? JNI_ABORT: 0);
4556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_base) {
4576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
4586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            JNI_ABORT);
4596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (configs) {
4616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        for (int i = 0; i < _configsRemaining; i++) {
4626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]);
4636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new);
4646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        }
4656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        delete[] configs;
4666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
4686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
4696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
470cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
4716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
4726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
4736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglGetConfigAttrib ( EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value ) */
4746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
4756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglGetConfigAttrib
4766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint attribute, jintArray value_ref, jint offset) {
4776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
47815284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionType = NULL;
47915284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionMessage = NULL;
4806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
4816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
4826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
4836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *value_base = (EGLint *) 0;
4846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _remaining;
4856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *value = (EGLint *) 0;
4866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
4876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!value_ref) {
4886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "value == null";
4916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (offset < 0) {
4946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
4956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
4966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "offset < 0";
4976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
4986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _remaining = _env->GetArrayLength(value_ref) - offset;
5006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_remaining < 1) {
5016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
5026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
5036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "length - offset < 1 < needed";
5046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
5056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    value_base = (EGLint *)
5076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0);
5086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    value = value_base + offset;
5096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglGetConfigAttrib(
5116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
5126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLConfig)config_native,
5136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)attribute,
5146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)value
5156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
5166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
5186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (value_base) {
5196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(value_ref, value_base,
5206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _exception ? JNI_ABORT: 0);
5216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
5236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
5246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
525cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
5266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
5276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */
5296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
5306b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglCreateWindowSurface
5316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) {
5326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
5336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    const char * _exceptionType = "";
5346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    const char * _exceptionMessage = "";
5356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface _returnValue = (EGLSurface) 0;
5366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
5376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
5386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    int attrib_list_sentinel = 0;
5396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list_base = (EGLint *) 0;
5406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _remaining;
5416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list = (EGLint *) 0;
5426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    android::sp<ANativeWindow> window;
5436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!attrib_list_ref) {
5456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
5466b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
5476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list == null";
5486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
5496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (offset < 0) {
5516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
5526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
5536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "offset < 0";
5546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
5556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (win == NULL) {
5576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofernot_valid_surface:
5586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
5596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
5606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface";
5616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
5626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
56464a55af0ac700baecb0877235eb42caac59a3560Jeff Brown    window = android::android_view_Surface_getNativeWindow(_env, win);
5656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (window == NULL)
5676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto not_valid_surface;
5686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
5706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_base = (EGLint *)
5716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
5726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list = attrib_list_base + offset;
5736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_sentinel = 0;
5746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    for (int i = _remaining - 1; i >= 0; i--)  {
5756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        if (*((EGLint*)(attrib_list + i)) == EGL_NONE){
5766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            attrib_list_sentinel = 1;
5776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            break;
5786b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        }
5796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_sentinel == 0) {
5816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
5826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
5836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list must contain EGL_NONE!";
5846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
5856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglCreateWindowSurface(
5886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
5896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLConfig)config_native,
5906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLNativeWindowType)window.get(),
5916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)attrib_list
5926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
5936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
5946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
5956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_base) {
5966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
5976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            JNI_ABORT);
5986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
5996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
6006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
6016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
6026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
6036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
6046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
6056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */
6066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
6076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglCreateWindowSurfaceTexture
6086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) {
6096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
6106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    const char * _exceptionType = "";
6116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    const char * _exceptionMessage = "";
6126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface _returnValue = (EGLSurface) 0;
6136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
6146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
6156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    int attrib_list_sentinel = 0;
6166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list_base = (EGLint *) 0;
6176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _remaining;
6186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list = (EGLint *) 0;
6196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    android::sp<ANativeWindow> window;
62052a9a10b6b8c7b7a9f97777541841b94d4fd9754Mathias Agopian    android::sp<android::IGraphicBufferProducer> producer;
6216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
6226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!attrib_list_ref) {
6236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
6246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
6256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list == null";
6266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
6276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
6286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (offset < 0) {
6296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
6306b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
6316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "offset < 0";
6326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
6336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
6346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (win == NULL) {
6356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofernot_valid_surface:
6366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
6376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
6386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface";
6396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
6406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
64152a9a10b6b8c7b7a9f97777541841b94d4fd9754Mathias Agopian    producer = android::SurfaceTexture_getProducer(_env, win);
64282bb813f112d9565faa990e32dbe833f96461892Jamie Gennis
64352a9a10b6b8c7b7a9f97777541841b94d4fd9754Mathias Agopian    if (producer == NULL)
64482bb813f112d9565faa990e32dbe833f96461892Jamie Gennis        goto not_valid_surface;
64582bb813f112d9565faa990e32dbe833f96461892Jamie Gennis
646f933737784bea4e27b70522cfd34ddaa45481d12Takahiro Aizawa    window = new android::Surface(producer, true);
6476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
6486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (window == NULL)
6496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto not_valid_surface;
6506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
6516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
6526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_base = (EGLint *)
6536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
6546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list = attrib_list_base + offset;
6556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_sentinel = 0;
6566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    for (int i = _remaining - 1; i >= 0; i--)  {
6576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        if (*((EGLint*)(attrib_list + i)) == EGL_NONE){
6586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            attrib_list_sentinel = 1;
6596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            break;
6606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        }
6616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
6626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_sentinel == 0) {
6636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
6646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
6656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list must contain EGL_NONE!";
6666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
6676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
6686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
6696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglCreateWindowSurface(
6706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
6716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLConfig)config_native,
6726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLNativeWindowType)window.get(),
6736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)attrib_list
6746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
6756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
6766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
6776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_base) {
6786b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
6796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            JNI_ABORT);
6806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
6816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
6826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
6836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
6846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
6856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
6866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLSurface eglCreatePbufferSurface ( EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list ) */
6876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
6886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglCreatePbufferSurface
6896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jintArray attrib_list_ref, jint offset) {
6906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
69115284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionType = NULL;
69215284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionMessage = NULL;
6936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface _returnValue = (EGLSurface) 0;
6946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
6956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
6966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    bool attrib_list_sentinel = false;
6976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list_base = (EGLint *) 0;
6986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _remaining;
6996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list = (EGLint *) 0;
7006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!attrib_list_ref) {
7026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
7036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
7046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list == null";
7056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
7066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (offset < 0) {
7086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
7096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
7106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "offset < 0";
7116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
7126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
7146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_base = (EGLint *)
7156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
7166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list = attrib_list_base + offset;
7176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_sentinel = false;
7186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    for (int i = _remaining - 1; i >= 0; i--)  {
7196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        if (attrib_list[i] == EGL_NONE){
7206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            attrib_list_sentinel = true;
7216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            break;
7226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        }
7236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_sentinel == false) {
7256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
7266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
7276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list must contain EGL_NONE!";
7286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
7296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7306b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglCreatePbufferSurface(
7326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
7336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLConfig)config_native,
7346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)attrib_list
7356b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
7366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
7386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_base) {
7396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
7406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            JNI_ABORT);
7416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
7436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
7446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
7466b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
7476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLSurface eglCreatePixmapSurface ( EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list ) */
7496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
7506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglCreatePixmapSurface
7516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint pixmap, jintArray attrib_list_ref, jint offset) {
7526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jniThrowException(_env, "java/lang/UnsupportedOperationException",
7536b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        "eglCreatePixmapSurface");
7546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, (EGLSurface) 0);
7556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
7566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglDestroySurface ( EGLDisplay dpy, EGLSurface surface ) */
7586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
7596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglDestroySurface
7606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject surface) {
7616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
7626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
7636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
7646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglDestroySurface(
7666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
7676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLSurface)surface_native
7686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
769cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
7706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
7716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglQuerySurface ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value ) */
7736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
7746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglQuerySurface
7756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jintArray value_ref, jint offset) {
7766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
77715284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionType = NULL;
77815284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionMessage = NULL;
7796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
7806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
7816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
7826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *value_base = (EGLint *) 0;
7836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _remaining;
7846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *value = (EGLint *) 0;
7856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
7866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!value_ref) {
7876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
7886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
7896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "value == null";
7906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
7916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (offset < 0) {
7936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
7946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
7956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "offset < 0";
7966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
7976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
7986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _remaining = _env->GetArrayLength(value_ref) - offset;
7996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_remaining < 1) {
8006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
8016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
8026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "length - offset < 1 < needed";
8036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
8046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
8056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    value_base = (EGLint *)
8066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0);
8076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    value = value_base + offset;
8086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglQuerySurface(
8106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
8116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLSurface)surface_native,
8126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)attribute,
8136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)value
8146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
8156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
8176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (value_base) {
8186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(value_ref, value_base,
8196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            _exception ? JNI_ABORT: 0);
8206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
8216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
8226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
8236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
824cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
8256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
8266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglBindAPI ( EGLenum api ) */
8286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
8296b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglBindAPI
8306b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jint api) {
8316b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
8326b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglBindAPI(
8336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLenum)api
8346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
835cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
8366b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
8376b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8386b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLenum eglQueryAPI ( void ) */
8396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jint
8406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglQueryAPI
8416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this) {
8426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLenum _returnValue = (EGLenum) 0;
8436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglQueryAPI();
844cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jint)_returnValue;
8456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
8466b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglWaitClient ( void ) */
8486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
8496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglWaitClient
8506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this) {
8516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
8526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglWaitClient();
853cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
8546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
8556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglReleaseThread ( void ) */
8576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
8586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglReleaseThread
8596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this) {
8606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
8616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglReleaseThread();
862cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
8636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
8646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLSurface eglCreatePbufferFromClientBuffer ( EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list ) */
8666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
8676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglCreatePbufferFromClientBuffer
86884bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat  (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jlong buffer, jobject config, jintArray attrib_list_ref, jint offset) {
8696b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
87015284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionType = NULL;
87115284dee8efe6b4d1441ab040962077614b5061aMathias Agopian    const char * _exceptionMessage = NULL;
8726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface _returnValue = (EGLSurface) 0;
8736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
8746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
8756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    bool attrib_list_sentinel = false;
8766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list_base = (EGLint *) 0;
8776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _remaining;
8786b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLint *attrib_list = (EGLint *) 0;
8796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
8806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (!attrib_list_ref) {
8816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
8826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
8836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list == null";
8846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
8856b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
8866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (offset < 0) {
8876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
8886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
8896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "offset < 0";
8906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
8916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
8926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
8936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_base = (EGLint *)
8946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
8956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list = attrib_list_base + offset;
8966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    attrib_list_sentinel = false;
8976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    for (int i = _remaining - 1; i >= 0; i--)  {
8986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        if (attrib_list[i] == EGL_NONE){
8996b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            attrib_list_sentinel = true;
9006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            break;
9016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        }
9026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
9036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_sentinel == false) {
9046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exception = 1;
9056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
9066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _exceptionMessage = "attrib_list must contain EGL_NONE!";
9076b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        goto exit;
9086b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
9096b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglCreatePbufferFromClientBuffer(
9116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
9126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLenum)buftype,
91384bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        reinterpret_cast<EGLClientBuffer>(buffer),
9146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLConfig)config_native,
9156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint *)attrib_list
9166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
9176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferexit:
9196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (attrib_list_base) {
9206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
9216b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer            JNI_ABORT);
9226b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
9236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    if (_exception) {
9246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
9256b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
9266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
9276b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
9286b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
92984bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhatstatic jobject
93084bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhatandroid_eglCreatePbufferFromClientBufferInt
93184bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat  (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jint buffer, jobject config, jintArray attrib_list_ref, jint offset) {
93284bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    if(sizeof(void*) != sizeof(uint32_t)) {
93384bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglCreatePbufferFromClientBuffer");
93484bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        return 0;
93584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    }
93684bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    return android_eglCreatePbufferFromClientBuffer(_env, _this, dpy, buftype, buffer, config, attrib_list_ref, offset);
93784bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat}
93884bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat
9396b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglSurfaceAttrib ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value ) */
9406b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
9416b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglSurfaceAttrib
9426b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jint value) {
9436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
9446b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
9456b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
9466b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9476b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglSurfaceAttrib(
9486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
9496b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLSurface)surface_native,
9506b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)attribute,
9516b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)value
9526b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
953cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
9546b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
9556b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9566b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglBindTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */
9576b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
9586b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglBindTexImage
9596b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint buffer) {
9606b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
9616b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
9626b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
9636b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9646b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglBindTexImage(
9656b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
9666b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLSurface)surface_native,
9676b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)buffer
9686b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
969cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
9706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
9716b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9726b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglReleaseTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */
9736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
9746b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglReleaseTexImage
9756b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint buffer) {
9766b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
9776b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
9786b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
9796b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9806b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglReleaseTexImage(
9816b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
9826b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLSurface)surface_native,
9836b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)buffer
9846b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
985cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
9866b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
9876b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9886b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLBoolean eglSwapInterval ( EGLDisplay dpy, EGLint interval ) */
9896b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jboolean
9906b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglSwapInterval
9916b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jint interval) {
9926b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLBoolean _returnValue = (EGLBoolean) 0;
9936b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
9946b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
9956b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    _returnValue = eglSwapInterval(
9966b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLDisplay)dpy_native,
9976b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        (EGLint)interval
9986b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    );
999cee5198e7199fcbb131ff0d30165fb1d5c0107cfAndy McFadden    return (jboolean)_returnValue;
10006b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
10016b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
10026b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/* EGLContext eglCreateContext ( EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list ) */
10036b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferstatic jobject
10046b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferandroid_eglCreateContext
10056b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer  (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject share_context, jintArray attrib_list_ref, jint offset) {
10066b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    jint _exception = 0;
1007