1/*
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9**     http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "JNIHelp.h"
19#include <android_runtime/AndroidRuntime.h>
20#include <android_runtime/android_view_Surface.h>
21#include <android_runtime/android_graphics_SurfaceTexture.h>
22#include <utils/misc.h>
23
24
25#include <EGL/egl_display.h>
26#include <EGL/egl.h>
27#include <GLES/gl.h>
28
29#include <gui/Surface.h>
30#include <gui/GLConsumer.h>
31#include <gui/Surface.h>
32
33#include <GraphicsJNI.h>
34#include <SkBitmap.h>
35#include <SkPixelRef.h>
36
37#include <ui/ANativeObjectBase.h>
38
39namespace android {
40
41static jclass gConfig_class;
42
43static jmethodID gConfig_ctorID;
44
45static jfieldID gDisplay_EGLDisplayFieldID;
46static jfieldID gContext_EGLContextFieldID;
47static jfieldID gSurface_EGLSurfaceFieldID;
48static jfieldID gSurface_NativePixelRefFieldID;
49static jfieldID gConfig_EGLConfigFieldID;
50
51static inline EGLDisplay getDisplay(JNIEnv* env, jobject o) {
52    if (!o) return EGL_NO_DISPLAY;
53    return (EGLDisplay)env->GetLongField(o, gDisplay_EGLDisplayFieldID);
54}
55static inline EGLSurface getSurface(JNIEnv* env, jobject o) {
56    if (!o) return EGL_NO_SURFACE;
57    return (EGLSurface)env->GetLongField(o, gSurface_EGLSurfaceFieldID);
58}
59static inline EGLContext getContext(JNIEnv* env, jobject o) {
60    if (!o) return EGL_NO_CONTEXT;
61    return (EGLContext)env->GetLongField(o, gContext_EGLContextFieldID);
62}
63static inline EGLConfig getConfig(JNIEnv* env, jobject o) {
64    if (!o) return 0;
65    return (EGLConfig)env->GetLongField(o, gConfig_EGLConfigFieldID);
66}
67
68static inline jboolean EglBoolToJBool(EGLBoolean eglBool) {
69    return eglBool == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
70}
71
72static void nativeClassInit(JNIEnv *_env, jclass eglImplClass)
73{
74    jclass config_class = _env->FindClass("com/google/android/gles_jni/EGLConfigImpl");
75    gConfig_class = (jclass) _env->NewGlobalRef(config_class);
76    gConfig_ctorID = _env->GetMethodID(gConfig_class,  "<init>", "(J)V");
77    gConfig_EGLConfigFieldID = _env->GetFieldID(gConfig_class,  "mEGLConfig",  "J");
78
79    jclass display_class = _env->FindClass("com/google/android/gles_jni/EGLDisplayImpl");
80    gDisplay_EGLDisplayFieldID = _env->GetFieldID(display_class, "mEGLDisplay", "J");
81
82    jclass context_class = _env->FindClass("com/google/android/gles_jni/EGLContextImpl");
83    gContext_EGLContextFieldID = _env->GetFieldID(context_class, "mEGLContext", "J");
84
85    jclass surface_class = _env->FindClass("com/google/android/gles_jni/EGLSurfaceImpl");
86    gSurface_EGLSurfaceFieldID = _env->GetFieldID(surface_class, "mEGLSurface", "J");
87    gSurface_NativePixelRefFieldID = _env->GetFieldID(surface_class, "mNativePixelRef", "J");
88}
89
90static const jint gNull_attrib_base[] = {EGL_NONE};
91
92static bool validAttribList(JNIEnv *_env, jintArray attrib_list) {
93    if (attrib_list == NULL) {
94        return true;
95    }
96    jsize len = _env->GetArrayLength(attrib_list);
97    if (len < 1) {
98        return false;
99    }
100    jint item = 0;
101    _env->GetIntArrayRegion(attrib_list, len-1, 1, &item);
102    return item == EGL_NONE;
103}
104
105static jint* beginNativeAttribList(JNIEnv *_env, jintArray attrib_list) {
106    if (attrib_list != NULL) {
107        return _env->GetIntArrayElements(attrib_list, (jboolean *)0);
108    } else {
109        return(jint*) gNull_attrib_base;
110    }
111}
112
113static void endNativeAttributeList(JNIEnv *_env, jintArray attrib_list, jint* attrib_base) {
114    if (attrib_list != NULL) {
115        _env->ReleaseIntArrayElements(attrib_list, attrib_base, 0);
116    }
117}
118
119static jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display,
120        jintArray major_minor) {
121    if (display == NULL || (major_minor != NULL &&
122            _env->GetArrayLength(major_minor) < 2)) {
123        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
124        return JNI_FALSE;
125    }
126
127    EGLDisplay dpy = getDisplay(_env, display);
128    EGLBoolean success = eglInitialize(dpy, NULL, NULL);
129    if (success && major_minor) {
130        int len = _env->GetArrayLength(major_minor);
131        if (len) {
132            // we're exposing only EGL 1.0
133            jint* base = (jint *)_env->GetPrimitiveArrayCritical(major_minor, (jboolean *)0);
134            if (len >= 1) base[0] = 1;
135            if (len >= 2) base[1] = 0;
136            _env->ReleasePrimitiveArrayCritical(major_minor, base, 0);
137        }
138    }
139    return EglBoolToJBool(success);
140}
141
142static jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display,
143        jobject context, jint attribute, jintArray value) {
144    if (display == NULL || context == NULL || value == NULL
145        || _env->GetArrayLength(value) < 1) {
146        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
147        return JNI_FALSE;
148    }
149    EGLDisplay dpy = getDisplay(_env, display);
150    EGLContext ctx = getContext(_env, context);
151    EGLBoolean success = EGL_FALSE;
152    int len = _env->GetArrayLength(value);
153    if (len) {
154        jint* base = _env->GetIntArrayElements(value, (jboolean *)0);
155        success = eglQueryContext(dpy, ctx, attribute, base);
156        _env->ReleaseIntArrayElements(value, base, 0);
157    }
158    return EglBoolToJBool(success);
159}
160
161static jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display,
162        jobject surface, jint attribute, jintArray value) {
163    if (display == NULL || surface == NULL || value == NULL
164        || _env->GetArrayLength(value) < 1) {
165        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
166        return JNI_FALSE;
167    }
168    EGLDisplay dpy = getDisplay(_env, display);
169    EGLContext sur = getSurface(_env, surface);
170
171    EGLBoolean success = EGL_FALSE;
172    int len = _env->GetArrayLength(value);
173    if (len) {
174        jint* base = _env->GetIntArrayElements(value, (jboolean *)0);
175        success = eglQuerySurface(dpy, sur, attribute, base);
176        _env->ReleaseIntArrayElements(value, base, 0);
177    }
178    return EglBoolToJBool(success);
179}
180
181static jint jni_getInitCount(JNIEnv *_env, jobject _clazz, jobject display) {
182    EGLDisplay dpy = getDisplay(_env, display);
183    egl_display_t* eglDisplay = get_display_nowake(dpy);
184    return eglDisplay ? eglDisplay->getRefsCount() : 0;
185}
186
187static jboolean jni_eglReleaseThread(JNIEnv *_env, jobject _this) {
188    return EglBoolToJBool(eglReleaseThread());
189}
190
191static jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display,
192        jintArray attrib_list, jobjectArray configs, jint config_size, jintArray num_config) {
193    if (display == NULL
194        || !validAttribList(_env, attrib_list)
195        || (configs != NULL && _env->GetArrayLength(configs) < config_size)
196        || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) {
197        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
198        return JNI_FALSE;
199    }
200    EGLDisplay dpy = getDisplay(_env, display);
201    EGLBoolean success = EGL_FALSE;
202
203    if (configs == NULL) {
204        config_size = 0;
205    }
206    EGLConfig nativeConfigs[config_size];
207
208    int num = 0;
209    jint* attrib_base = beginNativeAttribList(_env, attrib_list);
210    success = eglChooseConfig(dpy, attrib_base, configs ? nativeConfigs : 0, config_size, &num);
211    endNativeAttributeList(_env, attrib_list, attrib_base);
212
213    if (num_config != NULL) {
214        _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num);
215    }
216
217    if (success && configs!=NULL) {
218        for (int i=0 ; i<num ; i++) {
219            jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i]));
220            _env->SetObjectArrayElement(configs, i, obj);
221        }
222    }
223    return EglBoolToJBool(success);
224}
225
226static jlong jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display,
227        jobject config, jobject share_context, jintArray attrib_list) {
228    if (display == NULL || config == NULL || share_context == NULL
229        || !validAttribList(_env, attrib_list)) {
230        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
231        return JNI_FALSE;
232    }
233    EGLDisplay dpy = getDisplay(_env, display);
234    EGLConfig  cnf = getConfig(_env, config);
235    EGLContext shr = getContext(_env, share_context);
236    jint* base = beginNativeAttribList(_env, attrib_list);
237    EGLContext ctx = eglCreateContext(dpy, cnf, shr, base);
238    endNativeAttributeList(_env, attrib_list, base);
239    return reinterpret_cast<jlong>(ctx);
240}
241
242static jlong jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display,
243        jobject config, jintArray attrib_list) {
244    if (display == NULL || config == NULL
245        || !validAttribList(_env, attrib_list)) {
246        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
247        return JNI_FALSE;
248    }
249    EGLDisplay dpy = getDisplay(_env, display);
250    EGLConfig  cnf = getConfig(_env, config);
251    jint* base = beginNativeAttribList(_env, attrib_list);
252    EGLSurface sur = eglCreatePbufferSurface(dpy, cnf, base);
253    endNativeAttributeList(_env, attrib_list, base);
254    return reinterpret_cast<jlong>(sur);
255}
256
257static PixelFormat convertPixelFormat(SkColorType format)
258{
259    switch (format) {
260    case kN32_SkColorType:         return PIXEL_FORMAT_RGBA_8888;
261    case kARGB_4444_SkColorType:   return PIXEL_FORMAT_RGBA_4444;
262    case kRGB_565_SkColorType:     return PIXEL_FORMAT_RGB_565;
263    default:                       return PIXEL_FORMAT_NONE;
264    }
265}
266
267static void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur,
268        jobject display, jobject config, jobject native_pixmap,
269        jintArray attrib_list)
270{
271    if (display == NULL || config == NULL || native_pixmap == NULL
272        || !validAttribList(_env, attrib_list)) {
273        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
274        return;
275    }
276    EGLDisplay dpy = getDisplay(_env, display);
277    EGLConfig  cnf = getConfig(_env, config);
278    jint* base = 0;
279
280    SkBitmap nativeBitmap;
281    GraphicsJNI::getSkBitmap(_env, native_pixmap, &nativeBitmap);
282    SkPixelRef* ref = nativeBitmap.pixelRef();
283    if (ref == NULL) {
284        jniThrowException(_env, "java/lang/IllegalArgumentException", "Bitmap has no PixelRef");
285        return;
286    }
287
288    SkSafeRef(ref);
289    ref->lockPixels();
290
291    egl_native_pixmap_t pixmap;
292    pixmap.version = sizeof(pixmap);
293    pixmap.width  = nativeBitmap.width();
294    pixmap.height = nativeBitmap.height();
295    pixmap.stride = nativeBitmap.rowBytes() / nativeBitmap.bytesPerPixel();
296    pixmap.format = convertPixelFormat(nativeBitmap.colorType());
297    pixmap.data   = (uint8_t*)ref->pixels();
298
299    base = beginNativeAttribList(_env, attrib_list);
300    EGLSurface sur = eglCreatePixmapSurface(dpy, cnf, &pixmap, base);
301    endNativeAttributeList(_env, attrib_list, base);
302
303    if (sur != EGL_NO_SURFACE) {
304        _env->SetLongField(out_sur, gSurface_EGLSurfaceFieldID, reinterpret_cast<jlong>(sur));
305        _env->SetLongField(out_sur, gSurface_NativePixelRefFieldID, reinterpret_cast<jlong>(ref));
306    } else {
307        ref->unlockPixels();
308        SkSafeUnref(ref);
309    }
310}
311
312static jlong jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display,
313        jobject config, jobject native_window, jintArray attrib_list) {
314    if (display == NULL || config == NULL
315        || !validAttribList(_env, attrib_list)) {
316        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
317        return JNI_FALSE;
318    }
319    EGLDisplay dpy = getDisplay(_env, display);
320    EGLContext cnf = getConfig(_env, config);
321    sp<ANativeWindow> window;
322    if (native_window == NULL) {
323not_valid_surface:
324        jniThrowException(_env, "java/lang/IllegalArgumentException",
325                "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
326        return 0;
327    }
328
329    window = android_view_Surface_getNativeWindow(_env, native_window);
330    if (window == NULL)
331        goto not_valid_surface;
332
333    jint* base = beginNativeAttribList(_env, attrib_list);
334    EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base);
335    endNativeAttributeList(_env, attrib_list, base);
336    return reinterpret_cast<jlong>(sur);
337}
338
339static jlong jni_eglCreateWindowSurfaceTexture(JNIEnv *_env, jobject _this, jobject display,
340        jobject config, jobject native_window, jintArray attrib_list) {
341    if (display == NULL || config == NULL
342        || !validAttribList(_env, attrib_list)) {
343        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
344        return 0;
345    }
346    EGLDisplay dpy = getDisplay(_env, display);
347    EGLContext cnf = getConfig(_env, config);
348    sp<ANativeWindow> window;
349    if (native_window == 0) {
350not_valid_surface:
351        jniThrowException(_env, "java/lang/IllegalArgumentException",
352                "Make sure the SurfaceTexture is valid");
353        return 0;
354    }
355
356    sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(_env, native_window));
357    window = new Surface(producer, true);
358    if (window == NULL)
359        goto not_valid_surface;
360
361    jint* base = beginNativeAttribList(_env, attrib_list);
362    EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base);
363    endNativeAttributeList(_env, attrib_list, base);
364    return reinterpret_cast<jlong>(sur);
365}
366
367static jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject display,
368        jobject config, jint attribute, jintArray value) {
369    if (display == NULL || config == NULL
370        || (value == NULL || _env->GetArrayLength(value) < 1)) {
371        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
372        return JNI_FALSE;
373    }
374    EGLDisplay dpy = getDisplay(_env, display);
375    EGLContext cnf = getConfig(_env, config);
376    EGLBoolean success = EGL_FALSE;
377    jint localValue;
378    success = eglGetConfigAttrib(dpy, cnf, attribute, &localValue);
379    if (success) {
380        _env->SetIntArrayRegion(value, 0, 1, &localValue);
381    }
382    return EglBoolToJBool(success);
383}
384
385static jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display,
386        jobjectArray configs, jint config_size, jintArray num_config) {
387    if (display == NULL || (configs != NULL && _env->GetArrayLength(configs) < config_size)
388        || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) {
389        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
390        return JNI_FALSE;
391    }
392    EGLDisplay dpy = getDisplay(_env, display);
393    EGLBoolean success = EGL_FALSE;
394    if (configs == NULL) {
395        config_size = 0;
396    }
397    EGLConfig nativeConfigs[config_size];
398    int num;
399    success = eglGetConfigs(dpy, configs ? nativeConfigs : 0, config_size, &num);
400    if (num_config != NULL) {
401        _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num);
402    }
403    if (success && configs) {
404        for (int i=0 ; i<num ; i++) {
405            jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i]));
406            _env->SetObjectArrayElement(configs, i, obj);
407        }
408    }
409    return EglBoolToJBool(success);
410}
411
412static jint jni_eglGetError(JNIEnv *_env, jobject _this) {
413    EGLint error = eglGetError();
414    return error;
415}
416
417static jlong jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) {
418    return reinterpret_cast<jlong>(eglGetCurrentContext());
419}
420
421static jlong jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) {
422    return reinterpret_cast<jlong>(eglGetCurrentDisplay());
423}
424
425static jlong jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) {
426    if ((readdraw != EGL_READ) && (readdraw != EGL_DRAW)) {
427        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
428        return 0;
429    }
430    return reinterpret_cast<jlong>(eglGetCurrentSurface(readdraw));
431}
432
433static jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject display, jobject context) {
434    if (display == NULL || context == NULL) {
435        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
436        return JNI_FALSE;
437    }
438    EGLDisplay dpy = getDisplay(_env, display);
439    EGLContext ctx = getContext(_env, context);
440    return EglBoolToJBool(eglDestroyContext(dpy, ctx));
441}
442
443static jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface) {
444    if (display == NULL || surface == NULL) {
445        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
446        return JNI_FALSE;
447    }
448    EGLDisplay dpy = getDisplay(_env, display);
449    EGLSurface sur = getSurface(_env, surface);
450
451    if (sur) {
452        SkPixelRef* ref = (SkPixelRef*)(_env->GetLongField(surface,
453                gSurface_NativePixelRefFieldID));
454        if (ref) {
455            ref->unlockPixels();
456            SkSafeUnref(ref);
457        }
458    }
459    return EglBoolToJBool(eglDestroySurface(dpy, sur));
460}
461
462static jlong jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) {
463    return reinterpret_cast<jlong>(eglGetDisplay(EGL_DEFAULT_DISPLAY));
464}
465
466static jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobject draw, jobject read, jobject context) {
467    if (display == NULL || draw == NULL || read == NULL || context == NULL) {
468        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
469        return JNI_FALSE;
470    }
471    EGLDisplay dpy = getDisplay(_env, display);
472    EGLSurface sdr = getSurface(_env, draw);
473    EGLSurface srd = getSurface(_env, read);
474    EGLContext ctx = getContext(_env, context);
475    return EglBoolToJBool(eglMakeCurrent(dpy, sdr, srd, ctx));
476}
477
478static jstring jni_eglQueryString(JNIEnv *_env, jobject _this, jobject display, jint name) {
479    if (display == NULL) {
480        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
481        return NULL;
482    }
483    EGLDisplay dpy = getDisplay(_env, display);
484    const char* chars = eglQueryString(dpy, name);
485    return _env->NewStringUTF(chars);
486}
487
488static jboolean jni_eglSwapBuffers(JNIEnv *_env, jobject _this, jobject display, jobject surface) {
489    if (display == NULL || surface == NULL) {
490        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
491        return JNI_FALSE;
492    }
493    EGLDisplay dpy = getDisplay(_env, display);
494    EGLSurface sur = getSurface(_env, surface);
495    return EglBoolToJBool(eglSwapBuffers(dpy, sur));
496}
497
498static jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) {
499    if (display == NULL) {
500        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
501        return JNI_FALSE;
502    }
503    EGLDisplay dpy = getDisplay(_env, display);
504    return EglBoolToJBool(eglTerminate(dpy));
505}
506
507static jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display,
508        jobject surface, jobject native_pixmap) {
509    if (display == NULL || surface == NULL || native_pixmap == NULL) {
510        jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
511        return JNI_FALSE;
512    }
513    // TODO: Implement this
514    return JNI_FALSE;
515}
516
517static jboolean jni_eglWaitGL(JNIEnv *_env, jobject _this) {
518    return EglBoolToJBool(eglWaitGL());
519}
520
521static jboolean jni_eglWaitNative(JNIEnv *_env, jobject _this, jint engine, jobject bindTarget) {
522    return EglBoolToJBool(eglWaitNative(engine));
523}
524
525
526static const char *classPathName = "com/google/android/gles_jni/EGLImpl";
527
528#define DISPLAY "Ljavax/microedition/khronos/egl/EGLDisplay;"
529#define CONTEXT "Ljavax/microedition/khronos/egl/EGLContext;"
530#define CONFIG  "Ljavax/microedition/khronos/egl/EGLConfig;"
531#define SURFACE "Ljavax/microedition/khronos/egl/EGLSurface;"
532#define OBJECT  "Ljava/lang/Object;"
533#define STRING  "Ljava/lang/String;"
534
535static const JNINativeMethod methods[] = {
536{"_nativeClassInit","()V", (void*)nativeClassInit },
537{"eglWaitGL",       "()Z", (void*)jni_eglWaitGL },
538{"eglInitialize",   "(" DISPLAY "[I)Z", (void*)jni_eglInitialize },
539{"eglQueryContext", "(" DISPLAY CONTEXT "I[I)Z", (void*)jni_eglQueryContext },
540{"eglQuerySurface", "(" DISPLAY SURFACE "I[I)Z", (void*)jni_eglQuerySurface },
541{"eglReleaseThread","()Z", (void*)jni_eglReleaseThread },
542{"getInitCount",    "(" DISPLAY ")I", (void*)jni_getInitCount },
543{"eglChooseConfig", "(" DISPLAY "[I[" CONFIG "I[I)Z", (void*)jni_eglChooseConfig },
544{"_eglCreateContext","(" DISPLAY CONFIG CONTEXT "[I)J", (void*)jni_eglCreateContext },
545{"eglGetConfigs",   "(" DISPLAY "[" CONFIG "I[I)Z", (void*)jni_eglGetConfigs },
546{"eglTerminate",    "(" DISPLAY ")Z", (void*)jni_eglTerminate },
547{"eglCopyBuffers",  "(" DISPLAY SURFACE OBJECT ")Z", (void*)jni_eglCopyBuffers },
548{"eglWaitNative",   "(I" OBJECT ")Z", (void*)jni_eglWaitNative },
549{"eglGetError",     "()I", (void*)jni_eglGetError },
550{"eglGetConfigAttrib", "(" DISPLAY CONFIG "I[I)Z", (void*)jni_eglGetConfigAttrib },
551{"_eglGetDisplay",   "(" OBJECT ")J", (void*)jni_eglGetDisplay },
552{"_eglGetCurrentContext",  "()J", (void*)jni_eglGetCurrentContext },
553{"_eglGetCurrentDisplay",  "()J", (void*)jni_eglGetCurrentDisplay },
554{"_eglGetCurrentSurface",  "(I)J", (void*)jni_eglGetCurrentSurface },
555{"_eglCreatePbufferSurface","(" DISPLAY CONFIG "[I)J", (void*)jni_eglCreatePbufferSurface },
556{"_eglCreatePixmapSurface", "(" SURFACE DISPLAY CONFIG OBJECT "[I)V", (void*)jni_eglCreatePixmapSurface },
557{"_eglCreateWindowSurface", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurface },
558{"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurfaceTexture },
559{"eglDestroyContext",      "(" DISPLAY CONTEXT ")Z", (void*)jni_eglDestroyContext },
560{"eglDestroySurface",      "(" DISPLAY SURFACE ")Z", (void*)jni_eglDestroySurface },
561{"eglMakeCurrent",         "(" DISPLAY SURFACE SURFACE CONTEXT")Z", (void*)jni_eglMakeCurrent },
562{"eglQueryString",         "(" DISPLAY "I)" STRING, (void*)jni_eglQueryString },
563{"eglSwapBuffers",         "(" DISPLAY SURFACE ")Z", (void*)jni_eglSwapBuffers },
564};
565
566} // namespace android
567
568int register_com_google_android_gles_jni_EGLImpl(JNIEnv *_env)
569{
570    int err;
571    err = android::AndroidRuntime::registerNativeMethods(_env,
572            android::classPathName, android::methods, NELEM(android::methods));
573    return err;
574}
575