• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h>
26 #include <GLES/gl.h>
27 #include <private/EGL/display.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 
39 namespace android {
40 
41 static jclass gConfig_class;
42 
43 static jmethodID gConfig_ctorID;
44 
45 static jfieldID gDisplay_EGLDisplayFieldID;
46 static jfieldID gContext_EGLContextFieldID;
47 static jfieldID gSurface_EGLSurfaceFieldID;
48 static jfieldID gSurface_NativePixelRefFieldID;
49 static jfieldID gConfig_EGLConfigFieldID;
50 
getDisplay(JNIEnv * env,jobject o)51 static inline EGLDisplay getDisplay(JNIEnv* env, jobject o) {
52     if (!o) return EGL_NO_DISPLAY;
53     return (EGLDisplay)env->GetLongField(o, gDisplay_EGLDisplayFieldID);
54 }
getSurface(JNIEnv * env,jobject o)55 static inline EGLSurface getSurface(JNIEnv* env, jobject o) {
56     if (!o) return EGL_NO_SURFACE;
57     return (EGLSurface)env->GetLongField(o, gSurface_EGLSurfaceFieldID);
58 }
getContext(JNIEnv * env,jobject o)59 static inline EGLContext getContext(JNIEnv* env, jobject o) {
60     if (!o) return EGL_NO_CONTEXT;
61     return (EGLContext)env->GetLongField(o, gContext_EGLContextFieldID);
62 }
getConfig(JNIEnv * env,jobject o)63 static inline EGLConfig getConfig(JNIEnv* env, jobject o) {
64     if (!o) return 0;
65     return (EGLConfig)env->GetLongField(o, gConfig_EGLConfigFieldID);
66 }
67 
EglBoolToJBool(EGLBoolean eglBool)68 static inline jboolean EglBoolToJBool(EGLBoolean eglBool) {
69     return eglBool == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
70 }
71 
nativeClassInit(JNIEnv * _env,jclass eglImplClass)72 static 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 
90 static const jint gNull_attrib_base[] = {EGL_NONE};
91 
validAttribList(JNIEnv * _env,jintArray attrib_list)92 static 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 
beginNativeAttribList(JNIEnv * _env,jintArray attrib_list)105 static 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 
endNativeAttributeList(JNIEnv * _env,jintArray attrib_list,jint * attrib_base)113 static 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 
jni_eglInitialize(JNIEnv * _env,jobject _this,jobject display,jintArray major_minor)119 static 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 
jni_eglQueryContext(JNIEnv * _env,jobject _this,jobject display,jobject context,jint attribute,jintArray value)142 static 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 
jni_eglQuerySurface(JNIEnv * _env,jobject _this,jobject display,jobject surface,jint attribute,jintArray value)161 static 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 
jni_getInitCount(JNIEnv * _env,jobject _clazz,jobject display)181 static jint jni_getInitCount(JNIEnv *_env, jobject _clazz, jobject display) {
182     EGLDisplay dpy = getDisplay(_env, display);
183     return android::egl_get_init_count(dpy);
184 }
185 
jni_eglReleaseThread(JNIEnv * _env,jobject _this)186 static jboolean jni_eglReleaseThread(JNIEnv *_env, jobject _this) {
187     return EglBoolToJBool(eglReleaseThread());
188 }
189 
jni_eglChooseConfig(JNIEnv * _env,jobject _this,jobject display,jintArray attrib_list,jobjectArray configs,jint config_size,jintArray num_config)190 static jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display,
191         jintArray attrib_list, jobjectArray configs, jint config_size, jintArray num_config) {
192     if (display == NULL
193         || !validAttribList(_env, attrib_list)
194         || (configs != NULL && _env->GetArrayLength(configs) < config_size)
195         || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) {
196         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
197         return JNI_FALSE;
198     }
199     EGLDisplay dpy = getDisplay(_env, display);
200     EGLBoolean success = EGL_FALSE;
201 
202     if (configs == NULL) {
203         config_size = 0;
204     }
205     EGLConfig nativeConfigs[config_size];
206 
207     int num = 0;
208     jint* attrib_base = beginNativeAttribList(_env, attrib_list);
209     success = eglChooseConfig(dpy, attrib_base, configs ? nativeConfigs : 0, config_size, &num);
210     endNativeAttributeList(_env, attrib_list, attrib_base);
211 
212     if (num_config != NULL) {
213         _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num);
214     }
215 
216     if (success && configs!=NULL) {
217         for (int i=0 ; i<num ; i++) {
218             jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i]));
219             _env->SetObjectArrayElement(configs, i, obj);
220         }
221     }
222     return EglBoolToJBool(success);
223 }
224 
jni_eglCreateContext(JNIEnv * _env,jobject _this,jobject display,jobject config,jobject share_context,jintArray attrib_list)225 static jlong jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display,
226         jobject config, jobject share_context, jintArray attrib_list) {
227     if (display == NULL || config == NULL || share_context == NULL
228         || !validAttribList(_env, attrib_list)) {
229         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
230         return JNI_FALSE;
231     }
232     EGLDisplay dpy = getDisplay(_env, display);
233     EGLConfig  cnf = getConfig(_env, config);
234     EGLContext shr = getContext(_env, share_context);
235     jint* base = beginNativeAttribList(_env, attrib_list);
236     EGLContext ctx = eglCreateContext(dpy, cnf, shr, base);
237     endNativeAttributeList(_env, attrib_list, base);
238     return reinterpret_cast<jlong>(ctx);
239 }
240 
jni_eglCreatePbufferSurface(JNIEnv * _env,jobject _this,jobject display,jobject config,jintArray attrib_list)241 static jlong jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display,
242         jobject config, jintArray attrib_list) {
243     if (display == NULL || config == NULL
244         || !validAttribList(_env, attrib_list)) {
245         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
246         return JNI_FALSE;
247     }
248     EGLDisplay dpy = getDisplay(_env, display);
249     EGLConfig  cnf = getConfig(_env, config);
250     jint* base = beginNativeAttribList(_env, attrib_list);
251     EGLSurface sur = eglCreatePbufferSurface(dpy, cnf, base);
252     endNativeAttributeList(_env, attrib_list, base);
253     return reinterpret_cast<jlong>(sur);
254 }
255 
jni_eglCreatePixmapSurface(JNIEnv * _env,jobject _this,jobject out_sur,jobject display,jobject config,jobject native_pixmap,jintArray attrib_list)256 static void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur,
257         jobject display, jobject config, jobject native_pixmap,
258         jintArray attrib_list)
259 {
260     jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglCreatePixmapSurface");
261 }
262 
jni_eglCreateWindowSurface(JNIEnv * _env,jobject _this,jobject display,jobject config,jobject native_window,jintArray attrib_list)263 static jlong jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display,
264         jobject config, jobject native_window, jintArray attrib_list) {
265     if (display == NULL || config == NULL
266         || !validAttribList(_env, attrib_list)) {
267         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
268         return JNI_FALSE;
269     }
270     EGLDisplay dpy = getDisplay(_env, display);
271     EGLContext cnf = getConfig(_env, config);
272     sp<ANativeWindow> window;
273     if (native_window == NULL) {
274 not_valid_surface:
275         jniThrowException(_env, "java/lang/IllegalArgumentException",
276                 "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
277         return 0;
278     }
279 
280     window = android_view_Surface_getNativeWindow(_env, native_window);
281     if (window == NULL)
282         goto not_valid_surface;
283 
284     jint* base = beginNativeAttribList(_env, attrib_list);
285     EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base);
286     endNativeAttributeList(_env, attrib_list, base);
287     return reinterpret_cast<jlong>(sur);
288 }
289 
jni_eglCreateWindowSurfaceTexture(JNIEnv * _env,jobject _this,jobject display,jobject config,jobject native_window,jintArray attrib_list)290 static jlong jni_eglCreateWindowSurfaceTexture(JNIEnv *_env, jobject _this, jobject display,
291         jobject config, jobject native_window, jintArray attrib_list) {
292     if (display == NULL || config == NULL
293         || !validAttribList(_env, attrib_list)) {
294         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
295         return 0;
296     }
297     EGLDisplay dpy = getDisplay(_env, display);
298     EGLContext cnf = getConfig(_env, config);
299     sp<ANativeWindow> window;
300     if (native_window == 0) {
301 not_valid_surface:
302         jniThrowException(_env, "java/lang/IllegalArgumentException",
303                 "Make sure the SurfaceTexture is valid");
304         return 0;
305     }
306 
307     sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(_env, native_window));
308     window = new Surface(producer, true);
309     if (window == NULL)
310         goto not_valid_surface;
311 
312     jint* base = beginNativeAttribList(_env, attrib_list);
313     EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base);
314     endNativeAttributeList(_env, attrib_list, base);
315     return reinterpret_cast<jlong>(sur);
316 }
317 
jni_eglGetConfigAttrib(JNIEnv * _env,jobject _this,jobject display,jobject config,jint attribute,jintArray value)318 static jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject display,
319         jobject config, jint attribute, jintArray value) {
320     if (display == NULL || config == NULL
321         || (value == NULL || _env->GetArrayLength(value) < 1)) {
322         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
323         return JNI_FALSE;
324     }
325     EGLDisplay dpy = getDisplay(_env, display);
326     EGLContext cnf = getConfig(_env, config);
327     EGLBoolean success = EGL_FALSE;
328     jint localValue;
329     success = eglGetConfigAttrib(dpy, cnf, attribute, &localValue);
330     if (success) {
331         _env->SetIntArrayRegion(value, 0, 1, &localValue);
332     }
333     return EglBoolToJBool(success);
334 }
335 
jni_eglGetConfigs(JNIEnv * _env,jobject _this,jobject display,jobjectArray configs,jint config_size,jintArray num_config)336 static jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display,
337         jobjectArray configs, jint config_size, jintArray num_config) {
338     if (display == NULL || (configs != NULL && _env->GetArrayLength(configs) < config_size)
339         || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) {
340         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
341         return JNI_FALSE;
342     }
343     EGLDisplay dpy = getDisplay(_env, display);
344     EGLBoolean success = EGL_FALSE;
345     if (configs == NULL) {
346         config_size = 0;
347     }
348     EGLConfig nativeConfigs[config_size];
349     int num;
350     success = eglGetConfigs(dpy, configs ? nativeConfigs : 0, config_size, &num);
351     if (num_config != NULL) {
352         _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num);
353     }
354     if (success && configs) {
355         for (int i=0 ; i<num ; i++) {
356             jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i]));
357             _env->SetObjectArrayElement(configs, i, obj);
358         }
359     }
360     return EglBoolToJBool(success);
361 }
362 
jni_eglGetError(JNIEnv * _env,jobject _this)363 static jint jni_eglGetError(JNIEnv *_env, jobject _this) {
364     EGLint error = eglGetError();
365     return error;
366 }
367 
jni_eglGetCurrentContext(JNIEnv * _env,jobject _this)368 static jlong jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) {
369     return reinterpret_cast<jlong>(eglGetCurrentContext());
370 }
371 
jni_eglGetCurrentDisplay(JNIEnv * _env,jobject _this)372 static jlong jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) {
373     return reinterpret_cast<jlong>(eglGetCurrentDisplay());
374 }
375 
jni_eglGetCurrentSurface(JNIEnv * _env,jobject _this,jint readdraw)376 static jlong jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) {
377     if ((readdraw != EGL_READ) && (readdraw != EGL_DRAW)) {
378         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
379         return 0;
380     }
381     return reinterpret_cast<jlong>(eglGetCurrentSurface(readdraw));
382 }
383 
jni_eglDestroyContext(JNIEnv * _env,jobject _this,jobject display,jobject context)384 static jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject display, jobject context) {
385     if (display == NULL || context == NULL) {
386         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
387         return JNI_FALSE;
388     }
389     EGLDisplay dpy = getDisplay(_env, display);
390     EGLContext ctx = getContext(_env, context);
391     return EglBoolToJBool(eglDestroyContext(dpy, ctx));
392 }
393 
jni_eglDestroySurface(JNIEnv * _env,jobject _this,jobject display,jobject surface)394 static jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface) {
395     if (display == NULL || surface == NULL) {
396         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
397         return JNI_FALSE;
398     }
399     EGLDisplay dpy = getDisplay(_env, display);
400     EGLSurface sur = getSurface(_env, surface);
401 
402     if (sur) {
403         SkPixelRef* ref = (SkPixelRef*)(_env->GetLongField(surface,
404                 gSurface_NativePixelRefFieldID));
405         if (ref) {
406             ref->unlockPixels();
407             SkSafeUnref(ref);
408         }
409     }
410     return EglBoolToJBool(eglDestroySurface(dpy, sur));
411 }
412 
jni_eglGetDisplay(JNIEnv * _env,jobject _this,jobject native_display)413 static jlong jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) {
414     return reinterpret_cast<jlong>(eglGetDisplay(EGL_DEFAULT_DISPLAY));
415 }
416 
jni_eglMakeCurrent(JNIEnv * _env,jobject _this,jobject display,jobject draw,jobject read,jobject context)417 static jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobject draw, jobject read, jobject context) {
418     if (display == NULL || draw == NULL || read == NULL || context == NULL) {
419         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
420         return JNI_FALSE;
421     }
422     EGLDisplay dpy = getDisplay(_env, display);
423     EGLSurface sdr = getSurface(_env, draw);
424     EGLSurface srd = getSurface(_env, read);
425     EGLContext ctx = getContext(_env, context);
426     return EglBoolToJBool(eglMakeCurrent(dpy, sdr, srd, ctx));
427 }
428 
jni_eglQueryString(JNIEnv * _env,jobject _this,jobject display,jint name)429 static jstring jni_eglQueryString(JNIEnv *_env, jobject _this, jobject display, jint name) {
430     if (display == NULL) {
431         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
432         return NULL;
433     }
434     EGLDisplay dpy = getDisplay(_env, display);
435     const char* chars = eglQueryString(dpy, name);
436     return _env->NewStringUTF(chars);
437 }
438 
jni_eglSwapBuffers(JNIEnv * _env,jobject _this,jobject display,jobject surface)439 static jboolean jni_eglSwapBuffers(JNIEnv *_env, jobject _this, jobject display, jobject surface) {
440     if (display == NULL || surface == NULL) {
441         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
442         return JNI_FALSE;
443     }
444     EGLDisplay dpy = getDisplay(_env, display);
445     EGLSurface sur = getSurface(_env, surface);
446     return EglBoolToJBool(eglSwapBuffers(dpy, sur));
447 }
448 
jni_eglTerminate(JNIEnv * _env,jobject _this,jobject display)449 static jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) {
450     if (display == NULL) {
451         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
452         return JNI_FALSE;
453     }
454     EGLDisplay dpy = getDisplay(_env, display);
455     return EglBoolToJBool(eglTerminate(dpy));
456 }
457 
jni_eglCopyBuffers(JNIEnv * _env,jobject _this,jobject display,jobject surface,jobject native_pixmap)458 static jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display,
459         jobject surface, jobject native_pixmap) {
460     if (display == NULL || surface == NULL || native_pixmap == NULL) {
461         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
462         return JNI_FALSE;
463     }
464     // TODO: Implement this
465     return JNI_FALSE;
466 }
467 
jni_eglWaitGL(JNIEnv * _env,jobject _this)468 static jboolean jni_eglWaitGL(JNIEnv *_env, jobject _this) {
469     return EglBoolToJBool(eglWaitGL());
470 }
471 
jni_eglWaitNative(JNIEnv * _env,jobject _this,jint engine,jobject bindTarget)472 static jboolean jni_eglWaitNative(JNIEnv *_env, jobject _this, jint engine, jobject bindTarget) {
473     return EglBoolToJBool(eglWaitNative(engine));
474 }
475 
476 
477 static const char *classPathName = "com/google/android/gles_jni/EGLImpl";
478 
479 #define DISPLAY "Ljavax/microedition/khronos/egl/EGLDisplay;"
480 #define CONTEXT "Ljavax/microedition/khronos/egl/EGLContext;"
481 #define CONFIG  "Ljavax/microedition/khronos/egl/EGLConfig;"
482 #define SURFACE "Ljavax/microedition/khronos/egl/EGLSurface;"
483 #define OBJECT  "Ljava/lang/Object;"
484 #define STRING  "Ljava/lang/String;"
485 
486 static const JNINativeMethod methods[] = {
487 {"_nativeClassInit","()V", (void*)nativeClassInit },
488 {"eglWaitGL",       "()Z", (void*)jni_eglWaitGL },
489 {"eglInitialize",   "(" DISPLAY "[I)Z", (void*)jni_eglInitialize },
490 {"eglQueryContext", "(" DISPLAY CONTEXT "I[I)Z", (void*)jni_eglQueryContext },
491 {"eglQuerySurface", "(" DISPLAY SURFACE "I[I)Z", (void*)jni_eglQuerySurface },
492 {"eglReleaseThread","()Z", (void*)jni_eglReleaseThread },
493 {"getInitCount",    "(" DISPLAY ")I", (void*)jni_getInitCount },
494 {"eglChooseConfig", "(" DISPLAY "[I[" CONFIG "I[I)Z", (void*)jni_eglChooseConfig },
495 {"_eglCreateContext","(" DISPLAY CONFIG CONTEXT "[I)J", (void*)jni_eglCreateContext },
496 {"eglGetConfigs",   "(" DISPLAY "[" CONFIG "I[I)Z", (void*)jni_eglGetConfigs },
497 {"eglTerminate",    "(" DISPLAY ")Z", (void*)jni_eglTerminate },
498 {"eglCopyBuffers",  "(" DISPLAY SURFACE OBJECT ")Z", (void*)jni_eglCopyBuffers },
499 {"eglWaitNative",   "(I" OBJECT ")Z", (void*)jni_eglWaitNative },
500 {"eglGetError",     "()I", (void*)jni_eglGetError },
501 {"eglGetConfigAttrib", "(" DISPLAY CONFIG "I[I)Z", (void*)jni_eglGetConfigAttrib },
502 {"_eglGetDisplay",   "(" OBJECT ")J", (void*)jni_eglGetDisplay },
503 {"_eglGetCurrentContext",  "()J", (void*)jni_eglGetCurrentContext },
504 {"_eglGetCurrentDisplay",  "()J", (void*)jni_eglGetCurrentDisplay },
505 {"_eglGetCurrentSurface",  "(I)J", (void*)jni_eglGetCurrentSurface },
506 {"_eglCreatePbufferSurface","(" DISPLAY CONFIG "[I)J", (void*)jni_eglCreatePbufferSurface },
507 {"_eglCreatePixmapSurface", "(" SURFACE DISPLAY CONFIG OBJECT "[I)V", (void*)jni_eglCreatePixmapSurface },
508 {"_eglCreateWindowSurface", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurface },
509 {"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurfaceTexture },
510 {"eglDestroyContext",      "(" DISPLAY CONTEXT ")Z", (void*)jni_eglDestroyContext },
511 {"eglDestroySurface",      "(" DISPLAY SURFACE ")Z", (void*)jni_eglDestroySurface },
512 {"eglMakeCurrent",         "(" DISPLAY SURFACE SURFACE CONTEXT")Z", (void*)jni_eglMakeCurrent },
513 {"eglQueryString",         "(" DISPLAY "I)" STRING, (void*)jni_eglQueryString },
514 {"eglSwapBuffers",         "(" DISPLAY SURFACE ")Z", (void*)jni_eglSwapBuffers },
515 };
516 
517 } // namespace android
518 
register_com_google_android_gles_jni_EGLImpl(JNIEnv * _env)519 int register_com_google_android_gles_jni_EGLImpl(JNIEnv *_env)
520 {
521     int err;
522     err = android::AndroidRuntime::registerNativeMethods(_env,
523             android::classPathName, android::methods, NELEM(android::methods));
524     return err;
525 }
526