19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** Copyright 2006, The Android Open Source Project
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
51badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich** Licensed under the Apache License, Version 2.0 (the "License");
61badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich** you may not use this file except in compliance with the License.
71badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich** You may obtain a copy of the License at
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
91badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich**     http://www.apache.org/licenses/LICENSE-2.0
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
111badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich** Unless required by applicable law or agreed to in writing, software
121badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich** distributed under the License is distributed on an "AS IS" BASIS,
131badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich** See the License for the specific language governing permissions and
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** limitations under the License.
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project*/
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
188451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes#include "JNIHelp.h"
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <android_runtime/AndroidRuntime.h>
20289b9b62372ef52a06113b83dfb870e2c2fb325aDianne Hackborn#include <android_runtime/android_view_Surface.h>
21e5e0c50f7dfaccc220725c5595080e921ffda1e4Romain Guy#include <android_runtime/android_graphics_SurfaceTexture.h>
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <utils/misc.h>
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
248335f1ccccedb6655d96d9d5b697a7f0938235ddMathias Agopian
258335f1ccccedb6655d96d9d5b697a7f0938235ddMathias Agopian#include <EGL/egl_display.h>
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <EGL/egl.h>
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <GLES/gl.h>
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
298335f1ccccedb6655d96d9d5b697a7f0938235ddMathias Agopian#include <gui/Surface.h>
308335f1ccccedb6655d96d9d5b697a7f0938235ddMathias Agopian#include <gui/SurfaceTexture.h>
318335f1ccccedb6655d96d9d5b697a7f0938235ddMathias Agopian#include <gui/SurfaceTextureClient.h>
328ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <SkBitmap.h>
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <SkPixelRef.h>
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
36af01feafc30152baf8e0a5cfddbf02bd14731fd2Mathias Agopian#include <ui/ANativeObjectBase.h>
37af01feafc30152baf8e0a5cfddbf02bd14731fd2Mathias Agopian
3854a181b1a2b1517a9479b21fbf7705a688232fafDianne Hackbornnamespace android {
398b73ae4a1e5321753e54354e5202a38c5560fea9Mathias Agopian
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jclass gConfig_class;
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jmethodID gConfig_ctorID;
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jfieldID gDisplay_EGLDisplayFieldID;
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jfieldID gContext_EGLContextFieldID;
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jfieldID gSurface_EGLSurfaceFieldID;
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jfieldID gSurface_NativePixelRefFieldID;
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jfieldID gConfig_EGLConfigFieldID;
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jfieldID gBitmap_NativeBitmapFieldID;
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic inline EGLDisplay getDisplay(JNIEnv* env, jobject o) {
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (!o) return EGL_NO_DISPLAY;
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (EGLDisplay)env->GetIntField(o, gDisplay_EGLDisplayFieldID);
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic inline EGLSurface getSurface(JNIEnv* env, jobject o) {
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (!o) return EGL_NO_SURFACE;
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (EGLSurface)env->GetIntField(o, gSurface_EGLSurfaceFieldID);
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic inline EGLContext getContext(JNIEnv* env, jobject o) {
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (!o) return EGL_NO_CONTEXT;
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (EGLContext)env->GetIntField(o, gContext_EGLContextFieldID);
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic inline EGLConfig getConfig(JNIEnv* env, jobject o) {
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (!o) return 0;
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (EGLConfig)env->GetIntField(o, gConfig_EGLConfigFieldID);
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic void nativeClassInit(JNIEnv *_env, jclass eglImplClass)
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
69dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    jclass config_class = _env->FindClass("com/google/android/gles_jni/EGLConfigImpl");
70dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    gConfig_class = (jclass) _env->NewGlobalRef(config_class);
71dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    gConfig_ctorID = _env->GetMethodID(gConfig_class,  "<init>", "(I)V");
72dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    gConfig_EGLConfigFieldID = _env->GetFieldID(gConfig_class,  "mEGLConfig",  "I");
73dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes
74dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    jclass display_class = _env->FindClass("com/google/android/gles_jni/EGLDisplayImpl");
75dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    gDisplay_EGLDisplayFieldID = _env->GetFieldID(display_class, "mEGLDisplay", "I");
769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
77dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    jclass context_class = _env->FindClass("com/google/android/gles_jni/EGLContextImpl");
78dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    gContext_EGLContextFieldID = _env->GetFieldID(context_class, "mEGLContext", "I");
791badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
80dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    jclass surface_class = _env->FindClass("com/google/android/gles_jni/EGLSurfaceImpl");
81dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    gSurface_EGLSurfaceFieldID = _env->GetFieldID(surface_class, "mEGLSurface", "I");
82dd66bcbf9d6ef0c50a18d9c4b1b39ce7ef7afcc4Elliott Hughes    gSurface_NativePixelRefFieldID = _env->GetFieldID(surface_class, "mNativePixelRef", "I");
839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jclass bitmap_class = _env->FindClass("android/graphics/Bitmap");
851badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    gBitmap_NativeBitmapFieldID = _env->GetFieldID(bitmap_class, "mNativeBitmap", "I");
861badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich}
871badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
881badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic const jint gNull_attrib_base[] = {EGL_NONE};
891badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
901badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic bool validAttribList(JNIEnv *_env, jintArray attrib_list) {
911badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (attrib_list == NULL) {
921badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return true;
931badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
941badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    jsize len = _env->GetArrayLength(attrib_list);
951badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (len < 1) {
961badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return false;
971badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
981badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    jint item = 0;
991badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    _env->GetIntArrayRegion(attrib_list, len-1, 1, &item);
1001badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    return item == EGL_NONE;
1011badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich}
1021badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
1031badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint* beginNativeAttribList(JNIEnv *_env, jintArray attrib_list) {
1041badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (attrib_list != NULL) {
1051badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return (jint *)_env->GetPrimitiveArrayCritical(attrib_list, (jboolean *)0);
1061badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    } else {
1071badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return(jint*) gNull_attrib_base;
1081badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1111badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic void endNativeAttributeList(JNIEnv *_env, jintArray attrib_list, jint* attrib_base) {
1121badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (attrib_list != NULL) {
1131badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        _env->ReleasePrimitiveArrayCritical(attrib_list, attrib_base, JNI_ABORT);
1141badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
1151badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich}
1161badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
1171badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display,
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jintArray major_minor) {
1191badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || (major_minor != NULL &&
1201badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich            _env->GetArrayLength(major_minor) < 2)) {
1218451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
1221badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
1231badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
1241badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jboolean success = eglInitialize(dpy, NULL, NULL);
1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (success && major_minor) {
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int len = _env->GetArrayLength(major_minor);
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (len) {
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            // we're exposing only EGL 1.0
1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            jint* base = (jint *)_env->GetPrimitiveArrayCritical(major_minor, (jboolean *)0);
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (len >= 1) base[0] = 1;
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (len >= 2) base[1] = 0;
1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            _env->ReleasePrimitiveArrayCritical(major_minor, base, JNI_ABORT);
1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return success;
1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1401badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display,
1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject context, jint attribute, jintArray value) {
1421badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || context == NULL || value == NULL
1431badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || _env->GetArrayLength(value) < 1) {
1448451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return JNI_FALSE;
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1471badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    EGLDisplay dpy = getDisplay(_env, display);
1481badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    EGLContext ctx = getContext(_env, context);
1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jboolean success = JNI_FALSE;
1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    int len = _env->GetArrayLength(value);
1519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (len) {
1529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jint* base = (jint *)_env->GetPrimitiveArrayCritical(value, (jboolean *)0);
1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        success = eglQueryContext(dpy, ctx, attribute, base);
1549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        _env->ReleasePrimitiveArrayCritical(value, base, JNI_ABORT);
1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return success;
1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1581badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
1591badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display,
1609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject surface, jint attribute, jintArray value) {
1611badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || surface == NULL || value == NULL
1621badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || _env->GetArrayLength(value) < 1) {
1638451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return JNI_FALSE;
1659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1661badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    EGLDisplay dpy = getDisplay(_env, display);
1671badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    EGLContext sur = getSurface(_env, surface);
1681badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jboolean success = JNI_FALSE;
1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    int len = _env->GetArrayLength(value);
1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (len) {
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jint* base = (jint *)_env->GetPrimitiveArrayCritical(value, (jboolean *)0);
1739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        success = eglQuerySurface(dpy, sur, attribute, base);
1749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        _env->ReleasePrimitiveArrayCritical(value, base, JNI_ABORT);
1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return success;
1779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1798ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guystatic jint jni_getInitCount(JNIEnv *_env, jobject _clazz, jobject display) {
1808ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    EGLDisplay dpy = getDisplay(_env, display);
1819847f311f63301ca7d9553abcb0aec56b47cd60cJesse Hall    egl_display_t* eglDisplay = get_display_nowake(dpy);
1828ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    return eglDisplay ? eglDisplay->getRefsCount() : 0;
1838ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy}
1848ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
1858ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guystatic jboolean jni_eglReleaseThread(JNIEnv *_env, jobject _this) {
1868ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    return eglReleaseThread();
1878ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy}
1888ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
1891badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display,
1901badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        jintArray attrib_list, jobjectArray configs, jint config_size, jintArray num_config) {
1911badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL
1921badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || !validAttribList(_env, attrib_list)
1931badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || (configs != NULL && _env->GetArrayLength(configs) < config_size)
1941badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) {
1958451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return JNI_FALSE;
1979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1981badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    EGLDisplay dpy = getDisplay(_env, display);
1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jboolean success = JNI_FALSE;
2001badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
2011badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (configs == NULL) {
2021badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        config_size = 0;
2031badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLConfig nativeConfigs[config_size];
2051badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
2061badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    int num = 0;
2071badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    jint* attrib_base = beginNativeAttribList(_env, attrib_list);
2081badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    success = eglChooseConfig(dpy, attrib_base, configs ? nativeConfigs : 0, config_size, &num);
2091badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    endNativeAttributeList(_env, attrib_list, attrib_base);
2101badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
2111badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (num_config != NULL) {
2121badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num);
2131badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
2141badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
2151badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (success && configs!=NULL) {
2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        for (int i=0 ; i<num ; i++) {
2179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, (jint)nativeConfigs[i]);
2189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            _env->SetObjectArrayElement(configs, i, obj);
2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return success;
2221badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich}
2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2241badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display,
2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject config, jobject share_context, jintArray attrib_list) {
2261badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || config == NULL || share_context == NULL
2271badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || !validAttribList(_env, attrib_list)) {
2288451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
2291badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
2301badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
2319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLConfig  cnf = getConfig(_env, config);
2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLContext shr = getContext(_env, share_context);
2341badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    jint* base = beginNativeAttribList(_env, attrib_list);
2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLContext ctx = eglCreateContext(dpy, cnf, shr, base);
2361badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    endNativeAttributeList(_env, attrib_list, base);
2379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (jint)ctx;
2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2401badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display,
2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject config, jintArray attrib_list) {
2421badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || config == NULL
2431badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || !validAttribList(_env, attrib_list)) {
2448451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
2451badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
2461badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
2489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLConfig  cnf = getConfig(_env, config);
2491badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    jint* base = beginNativeAttribList(_env, attrib_list);
2509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLSurface sur = eglCreatePbufferSurface(dpy, cnf, base);
2511badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    endNativeAttributeList(_env, attrib_list, base);
2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (jint)sur;
2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic PixelFormat convertPixelFormat(SkBitmap::Config format)
2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    switch (format) {
2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    case SkBitmap::kARGB_8888_Config:   return PIXEL_FORMAT_RGBA_8888;
2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    case SkBitmap::kARGB_4444_Config:   return PIXEL_FORMAT_RGBA_4444;
2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    case SkBitmap::kRGB_565_Config:     return PIXEL_FORMAT_RGB_565;
2619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    case SkBitmap::kA8_Config:          return PIXEL_FORMAT_A_8;
2629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    default:                            return PIXEL_FORMAT_NONE;
2639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2661badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur,
2679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject display, jobject config, jobject native_pixmap,
2681badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        jintArray attrib_list)
2699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2701badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || config == NULL || native_pixmap == NULL
2711badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || !validAttribList(_env, attrib_list)) {
2728451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
2731badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return;
2741badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
2759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
2769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLConfig  cnf = getConfig(_env, config);
2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jint* base = 0;
2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    SkBitmap const * nativeBitmap =
2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            (SkBitmap const *)_env->GetIntField(native_pixmap,
2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    gBitmap_NativeBitmapFieldID);
2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    SkPixelRef* ref = nativeBitmap ? nativeBitmap->pixelRef() : 0;
2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (ref == NULL) {
2848451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", "Bitmap has no PixelRef");
2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return;
2869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2871badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
2886062c5912dc79704b489fc8c289b78a400ed05eeDerek Sollenberger    SkSafeRef(ref);
2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    ref->lockPixels();
2901badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    egl_native_pixmap_t pixmap;
2929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    pixmap.version = sizeof(pixmap);
2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    pixmap.width  = nativeBitmap->width();
2949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    pixmap.height = nativeBitmap->height();
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    pixmap.stride = nativeBitmap->rowBytes() / nativeBitmap->bytesPerPixel();
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    pixmap.format = convertPixelFormat(nativeBitmap->config());
2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    pixmap.data   = (uint8_t*)ref->pixels();
2981badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
2991badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    base = beginNativeAttribList(_env, attrib_list);
3009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLSurface sur = eglCreatePixmapSurface(dpy, cnf, &pixmap, base);
3011badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    endNativeAttributeList(_env, attrib_list, base);
3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (sur != EGL_NO_SURFACE) {
3049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        _env->SetIntField(out_sur, gSurface_EGLSurfaceFieldID, (int)sur);
3059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        _env->SetIntField(out_sur, gSurface_NativePixelRefFieldID, (int)ref);
3069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    } else {
3079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        ref->unlockPixels();
3086062c5912dc79704b489fc8c289b78a400ed05eeDerek Sollenberger        SkSafeUnref(ref);
3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3121badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display,
3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject config, jobject native_window, jintArray attrib_list) {
3141badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || config == NULL
3151badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || !validAttribList(_env, attrib_list)) {
3168451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
3171badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
3181badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLContext cnf = getConfig(_env, config);
32154a181b1a2b1517a9479b21fbf7705a688232fafDianne Hackborn    sp<ANativeWindow> window;
3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (native_window == NULL) {
3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectnot_valid_surface:
3248451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException",
3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return 0;
3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3288b73ae4a1e5321753e54354e5202a38c5560fea9Mathias Agopian
32964a55af0ac700baecb0877235eb42caac59a3560Jeff Brown    window = android_view_Surface_getNativeWindow(_env, native_window);
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (window == NULL)
3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        goto not_valid_surface;
3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3331badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    jint* base = beginNativeAttribList(_env, attrib_list);
33454a181b1a2b1517a9479b21fbf7705a688232fafDianne Hackborn    EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base);
3351badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    endNativeAttributeList(_env, attrib_list, base);
3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (jint)sur;
3379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3398f0095cd33558e9cc8a440047908e53b68906f5fRomain Guystatic jint jni_eglCreateWindowSurfaceTexture(JNIEnv *_env, jobject _this, jobject display,
340e5e0c50f7dfaccc220725c5595080e921ffda1e4Romain Guy        jobject config, jobject native_window, jintArray attrib_list) {
3418f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    if (display == NULL || config == NULL
3428f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        || !validAttribList(_env, attrib_list)) {
3438f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
3448f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        return JNI_FALSE;
3458f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    }
3468f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    EGLDisplay dpy = getDisplay(_env, display);
3478f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    EGLContext cnf = getConfig(_env, config);
3488f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    sp<ANativeWindow> window;
3498f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    if (native_window == 0) {
3508f0095cd33558e9cc8a440047908e53b68906f5fRomain Guynot_valid_surface:
3518f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        jniThrowException(_env, "java/lang/IllegalArgumentException",
3528f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy                "Make sure the SurfaceTexture is valid");
3538f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        return 0;
3548f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    }
3558f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
356e5e0c50f7dfaccc220725c5595080e921ffda1e4Romain Guy    sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(_env, native_window));
3578f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
3588f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    window = new SurfaceTextureClient(surfaceTexture);
3598f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    if (window == NULL)
3608f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        goto not_valid_surface;
3618f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
3628f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    jint* base = beginNativeAttribList(_env, attrib_list);
3638f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base);
3648f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    endNativeAttributeList(_env, attrib_list, base);
3658f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    return (jint)sur;
3668f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy}
3678f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
3681badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject display,
3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject config, jint attribute, jintArray value) {
3701badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || config == NULL
3711badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || (value == NULL || _env->GetArrayLength(value) < 1)) {
3728451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
3739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return JNI_FALSE;
3749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3751badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    EGLDisplay dpy = getDisplay(_env, display);
3761badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    EGLContext cnf = getConfig(_env, config);
3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jboolean success = JNI_FALSE;
3781badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    jint localValue;
3791badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    success = eglGetConfigAttrib(dpy, cnf, attribute, &localValue);
3801badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (success) {
3811badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        _env->SetIntArrayRegion(value, 0, 1, &localValue);
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return success;
3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3861badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display,
3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobjectArray configs, jint config_size, jintArray num_config) {
3881badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || (configs != NULL && _env->GetArrayLength(configs) < config_size)
3891badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) {
3908451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
3911badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
3921badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jboolean success = JNI_FALSE;
3951badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (configs == NULL) {
3961badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        config_size = 0;
3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLConfig nativeConfigs[config_size];
3991badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    int num;
4001badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    success = eglGetConfigs(dpy, configs ? nativeConfigs : 0, config_size, &num);
4011badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (num_config != NULL) {
4021badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num);
4031badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (success && configs) {
4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        for (int i=0 ; i<num ; i++) {
4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, (jint)nativeConfigs[i]);
4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            _env->SetObjectArrayElement(configs, i, obj);
4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return success;
4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4121badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich
4131badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglGetError(JNIEnv *_env, jobject _this) {
4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLint error = eglGetError();
4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return error;
4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4181badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) {
4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (jint)eglGetCurrentContext();
4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4221badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) {
4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (jint)eglGetCurrentDisplay();
4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4261badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) {
4279b7146db6d9c0586b98b062fbcdb3fac6cc54d19Romain Guy    if ((readdraw != EGL_READ) && (readdraw != EGL_DRAW)) {
4288451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
4291badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return 0;
4301badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
4319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (jint)eglGetCurrentSurface(readdraw);
4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4341badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject display, jobject context) {
4351badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || context == NULL) {
4368451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
4371badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
4381badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
4409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLContext ctx = getContext(_env, context);
4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return eglDestroyContext(dpy, ctx);
4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4441badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface) {
4451badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || surface == NULL) {
4468451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
4471badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
4481badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLSurface sur = getSurface(_env, surface);
4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (sur) {
4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        SkPixelRef* ref = (SkPixelRef*)(_env->GetIntField(surface,
4549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                gSurface_NativePixelRefFieldID));
4559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (ref) {
4569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            ref->unlockPixels();
4576062c5912dc79704b489fc8c289b78a400ed05eeDerek Sollenberger            SkSafeUnref(ref);
4589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
4599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return eglDestroySurface(dpy, sur);
4619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4631badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jint jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) {
4649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return (jint)eglGetDisplay(EGL_DEFAULT_DISPLAY);
4659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4671badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobject draw, jobject read, jobject context) {
4681badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || draw == NULL || read == NULL || context == NULL) {
4698451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
4701badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
4711badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
4729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
4739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLSurface sdr = getSurface(_env, draw);
4749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLSurface srd = getSurface(_env, read);
4759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLContext ctx = getContext(_env, context);
4769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return eglMakeCurrent(dpy, sdr, srd, ctx);
4779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4791badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jstring jni_eglQueryString(JNIEnv *_env, jobject _this, jobject display, jint name) {
4801badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL) {
4818451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
4821badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return NULL;
4831badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
4849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
4859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    const char* chars = eglQueryString(dpy, name);
4869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return _env->NewStringUTF(chars);
4879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4891badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglSwapBuffers(JNIEnv *_env, jobject _this, jobject display, jobject surface) {
4901badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || surface == NULL) {
4918451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
4921badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
4931badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
4949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLSurface sur = getSurface(_env, surface);
4969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return eglSwapBuffers(dpy, sur);
4979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4991badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) {
5001badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL) {
5018451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
5021badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
5031badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
5049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    EGLDisplay dpy = getDisplay(_env, display);
5059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return eglTerminate(dpy);
5069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
5079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5081badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display,
5099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        jobject surface, jobject native_pixmap) {
5101badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    if (display == NULL || surface == NULL || native_pixmap == NULL) {
5118451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
5121badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich        return JNI_FALSE;
5131badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    }
5141badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevich    // TODO: Implement this
5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return JNI_FALSE;
5169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
5179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5181badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglWaitGL(JNIEnv *_env, jobject _this) {
5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return eglWaitGL();
5209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
5219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5221badb712b94f5d4a14ca8c3bdb55c215a4915000Jack Palevichstatic jboolean jni_eglWaitNative(JNIEnv *_env, jobject _this, jint engine, jobject bindTarget) {
5239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return eglWaitNative(engine);
5249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
5259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic const char *classPathName = "com/google/android/gles_jni/EGLImpl";
5289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define DISPLAY "Ljavax/microedition/khronos/egl/EGLDisplay;"
5309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define CONTEXT "Ljavax/microedition/khronos/egl/EGLContext;"
5319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define CONFIG  "Ljavax/microedition/khronos/egl/EGLConfig;"
5329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define SURFACE "Ljavax/microedition/khronos/egl/EGLSurface;"
5339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define OBJECT  "Ljava/lang/Object;"
5349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define STRING  "Ljava/lang/String;"
5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic JNINativeMethod methods[] = {
5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_nativeClassInit","()V", (void*)nativeClassInit },
5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglWaitGL",       "()Z", (void*)jni_eglWaitGL },
5399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglInitialize",   "(" DISPLAY "[I)Z", (void*)jni_eglInitialize },
5409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglQueryContext", "(" DISPLAY CONTEXT "I[I)Z", (void*)jni_eglQueryContext },
5419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglQuerySurface", "(" DISPLAY SURFACE "I[I)Z", (void*)jni_eglQuerySurface },
5428ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy{"eglReleaseThread","()Z", (void*)jni_eglReleaseThread },
5438ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy{"getInitCount",    "(" DISPLAY ")I", (void*)jni_getInitCount },
5449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglChooseConfig", "(" DISPLAY "[I[" CONFIG "I[I)Z", (void*)jni_eglChooseConfig },
5459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglCreateContext","(" DISPLAY CONFIG CONTEXT "[I)I", (void*)jni_eglCreateContext },
5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglGetConfigs",   "(" DISPLAY "[" CONFIG "I[I)Z", (void*)jni_eglGetConfigs },
5479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglTerminate",    "(" DISPLAY ")Z", (void*)jni_eglTerminate },
5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglCopyBuffers",  "(" DISPLAY SURFACE OBJECT ")Z", (void*)jni_eglCopyBuffers },
5499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglWaitNative",   "(I" OBJECT ")Z", (void*)jni_eglWaitNative },
5509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglGetError",     "()I", (void*)jni_eglGetError },
5519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglGetConfigAttrib", "(" DISPLAY CONFIG "I[I)Z", (void*)jni_eglGetConfigAttrib },
5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglGetDisplay",   "(" OBJECT ")I", (void*)jni_eglGetDisplay },
5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglGetCurrentContext",  "()I", (void*)jni_eglGetCurrentContext },
5549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglGetCurrentDisplay",  "()I", (void*)jni_eglGetCurrentDisplay },
5559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglGetCurrentSurface",  "(I)I", (void*)jni_eglGetCurrentSurface },
5569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglCreatePbufferSurface","(" DISPLAY CONFIG "[I)I", (void*)jni_eglCreatePbufferSurface },
5579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglCreatePixmapSurface", "(" SURFACE DISPLAY CONFIG OBJECT "[I)V", (void*)jni_eglCreatePixmapSurface },
5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"_eglCreateWindowSurface", "(" DISPLAY CONFIG OBJECT "[I)I", (void*)jni_eglCreateWindowSurface },
559b38484ccb9386780c1d192c552da30b680539952Romain Guy{"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG OBJECT "[I)I", (void*)jni_eglCreateWindowSurfaceTexture },
5609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglDestroyContext",      "(" DISPLAY CONTEXT ")Z", (void*)jni_eglDestroyContext },
5619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglDestroySurface",      "(" DISPLAY SURFACE ")Z", (void*)jni_eglDestroySurface },
5629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglMakeCurrent",         "(" DISPLAY SURFACE SURFACE CONTEXT")Z", (void*)jni_eglMakeCurrent },
5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglQueryString",         "(" DISPLAY "I)" STRING, (void*)jni_eglQueryString },
5649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{"eglSwapBuffers",         "(" DISPLAY SURFACE ")Z", (void*)jni_eglSwapBuffers },
5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project};
5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} // namespace android
5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectint register_com_google_android_gles_jni_EGLImpl(JNIEnv *_env)
5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    int err;
5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    err = android::AndroidRuntime::registerNativeMethods(_env,
5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            android::classPathName, android::methods, NELEM(android::methods));
5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return err;
5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
576