The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 18 | #include <nativehelper/JNIHelp.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <android_runtime/AndroidRuntime.h> |
Dianne Hackborn | 289b9b6 | 2010-07-09 11:44:11 -0700 | [diff] [blame] | 20 | #include <android_runtime/android_view_Surface.h> |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 21 | #include <android_runtime/android_graphics_SurfaceTexture.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <utils/misc.h> |
| 23 | |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 24 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <EGL/egl.h> |
| 26 | #include <GLES/gl.h> |
Mathias Agopian | 04d0461 | 2017-03-08 23:21:54 -0800 | [diff] [blame] | 27 | #include <private/EGL/display.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 29 | #include <gui/Surface.h> |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 30 | #include <gui/GLConsumer.h> |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 31 | #include <gui/Surface.h> |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 32 | |
John Reck | f4faeac | 2015-03-05 13:50:31 -0800 | [diff] [blame] | 33 | #include <GraphicsJNI.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <SkBitmap.h> |
| 35 | #include <SkPixelRef.h> |
| 36 | |
Mathias Agopian | af01feaf | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 37 | #include <ui/ANativeObjectBase.h> |
| 38 | |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 39 | namespace android { |
Mathias Agopian | 8b73ae4 | 2010-06-10 17:02:51 -0700 | [diff] [blame] | 40 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | static jfieldID gConfig_EGLConfigFieldID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | static inline EGLDisplay getDisplay(JNIEnv* env, jobject o) { |
| 51 | if (!o) return EGL_NO_DISPLAY; |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 52 | return (EGLDisplay)env->GetLongField(o, gDisplay_EGLDisplayFieldID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | } |
| 54 | static inline EGLSurface getSurface(JNIEnv* env, jobject o) { |
| 55 | if (!o) return EGL_NO_SURFACE; |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 56 | return (EGLSurface)env->GetLongField(o, gSurface_EGLSurfaceFieldID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | } |
| 58 | static inline EGLContext getContext(JNIEnv* env, jobject o) { |
| 59 | if (!o) return EGL_NO_CONTEXT; |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 60 | return (EGLContext)env->GetLongField(o, gContext_EGLContextFieldID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | } |
| 62 | static inline EGLConfig getConfig(JNIEnv* env, jobject o) { |
| 63 | if (!o) return 0; |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 64 | return (EGLConfig)env->GetLongField(o, gConfig_EGLConfigFieldID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 66 | |
| 67 | static inline jboolean EglBoolToJBool(EGLBoolean eglBool) { |
| 68 | return eglBool == EGL_TRUE ? JNI_TRUE : JNI_FALSE; |
| 69 | } |
| 70 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | static void nativeClassInit(JNIEnv *_env, jclass eglImplClass) |
| 72 | { |
Elliott Hughes | dd66bcb | 2011-04-12 11:28:59 -0700 | [diff] [blame] | 73 | jclass config_class = _env->FindClass("com/google/android/gles_jni/EGLConfigImpl"); |
| 74 | gConfig_class = (jclass) _env->NewGlobalRef(config_class); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 75 | gConfig_ctorID = _env->GetMethodID(gConfig_class, "<init>", "(J)V"); |
| 76 | gConfig_EGLConfigFieldID = _env->GetFieldID(gConfig_class, "mEGLConfig", "J"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | |
Elliott Hughes | dd66bcb | 2011-04-12 11:28:59 -0700 | [diff] [blame] | 78 | jclass display_class = _env->FindClass("com/google/android/gles_jni/EGLDisplayImpl"); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 79 | gDisplay_EGLDisplayFieldID = _env->GetFieldID(display_class, "mEGLDisplay", "J"); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 80 | |
Elliott Hughes | dd66bcb | 2011-04-12 11:28:59 -0700 | [diff] [blame] | 81 | jclass context_class = _env->FindClass("com/google/android/gles_jni/EGLContextImpl"); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 82 | gContext_EGLContextFieldID = _env->GetFieldID(context_class, "mEGLContext", "J"); |
Elliott Hughes | dd66bcb | 2011-04-12 11:28:59 -0700 | [diff] [blame] | 83 | |
| 84 | jclass surface_class = _env->FindClass("com/google/android/gles_jni/EGLSurfaceImpl"); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 85 | gSurface_EGLSurfaceFieldID = _env->GetFieldID(surface_class, "mEGLSurface", "J"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 88 | static const jint gNull_attrib_base[] = {EGL_NONE}; |
| 89 | |
| 90 | static bool validAttribList(JNIEnv *_env, jintArray attrib_list) { |
| 91 | if (attrib_list == NULL) { |
| 92 | return true; |
| 93 | } |
| 94 | jsize len = _env->GetArrayLength(attrib_list); |
| 95 | if (len < 1) { |
| 96 | return false; |
| 97 | } |
| 98 | jint item = 0; |
| 99 | _env->GetIntArrayRegion(attrib_list, len-1, 1, &item); |
| 100 | return item == EGL_NONE; |
| 101 | } |
| 102 | |
| 103 | static jint* beginNativeAttribList(JNIEnv *_env, jintArray attrib_list) { |
| 104 | if (attrib_list != NULL) { |
Michael Chock | b5066245 | 2013-08-06 15:21:10 -0700 | [diff] [blame] | 105 | return _env->GetIntArrayElements(attrib_list, (jboolean *)0); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 106 | } else { |
| 107 | return(jint*) gNull_attrib_base; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | static void endNativeAttributeList(JNIEnv *_env, jintArray attrib_list, jint* attrib_base) { |
| 112 | if (attrib_list != NULL) { |
Mathieu Chartier | 6a5e6df | 2014-10-06 12:42:00 -0700 | [diff] [blame] | 113 | _env->ReleaseIntArrayElements(attrib_list, attrib_base, 0); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
| 117 | static jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | jintArray major_minor) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 119 | if (display == NULL || (major_minor != NULL && |
| 120 | _env->GetArrayLength(major_minor) < 2)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 121 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 122 | return JNI_FALSE; |
| 123 | } |
| 124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | EGLDisplay dpy = getDisplay(_env, display); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 126 | EGLBoolean success = eglInitialize(dpy, NULL, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | if (success && major_minor) { |
| 128 | int len = _env->GetArrayLength(major_minor); |
| 129 | if (len) { |
| 130 | // we're exposing only EGL 1.0 |
| 131 | jint* base = (jint *)_env->GetPrimitiveArrayCritical(major_minor, (jboolean *)0); |
| 132 | if (len >= 1) base[0] = 1; |
| 133 | if (len >= 2) base[1] = 0; |
Mathieu Chartier | 6a5e6df | 2014-10-06 12:42:00 -0700 | [diff] [blame] | 134 | _env->ReleasePrimitiveArrayCritical(major_minor, base, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 137 | return EglBoolToJBool(success); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 140 | static jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | jobject context, jint attribute, jintArray value) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 142 | if (display == NULL || context == NULL || value == NULL |
| 143 | || _env->GetArrayLength(value) < 1) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 144 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | return JNI_FALSE; |
| 146 | } |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 147 | EGLDisplay dpy = getDisplay(_env, display); |
| 148 | EGLContext ctx = getContext(_env, context); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 149 | EGLBoolean success = EGL_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | int len = _env->GetArrayLength(value); |
| 151 | if (len) { |
Michael Chock | b5066245 | 2013-08-06 15:21:10 -0700 | [diff] [blame] | 152 | jint* base = _env->GetIntArrayElements(value, (jboolean *)0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | success = eglQueryContext(dpy, ctx, attribute, base); |
Mathieu Chartier | 6a5e6df | 2014-10-06 12:42:00 -0700 | [diff] [blame] | 154 | _env->ReleaseIntArrayElements(value, base, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 156 | return EglBoolToJBool(success); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | } |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 158 | |
| 159 | static jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | jobject surface, jint attribute, jintArray value) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 161 | if (display == NULL || surface == NULL || value == NULL |
| 162 | || _env->GetArrayLength(value) < 1) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 163 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | return JNI_FALSE; |
| 165 | } |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 166 | EGLDisplay dpy = getDisplay(_env, display); |
| 167 | EGLContext sur = getSurface(_env, surface); |
| 168 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 169 | EGLBoolean success = EGL_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | int len = _env->GetArrayLength(value); |
| 171 | if (len) { |
Michael Chock | b5066245 | 2013-08-06 15:21:10 -0700 | [diff] [blame] | 172 | jint* base = _env->GetIntArrayElements(value, (jboolean *)0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | success = eglQuerySurface(dpy, sur, attribute, base); |
Mathieu Chartier | 6a5e6df | 2014-10-06 12:42:00 -0700 | [diff] [blame] | 174 | _env->ReleaseIntArrayElements(value, base, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 176 | return EglBoolToJBool(success); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 179 | static jint jni_getInitCount(JNIEnv *_env, jobject _clazz, jobject display) { |
| 180 | EGLDisplay dpy = getDisplay(_env, display); |
Mathias Agopian | 04d0461 | 2017-03-08 23:21:54 -0800 | [diff] [blame] | 181 | return android::egl_get_init_count(dpy); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static jboolean jni_eglReleaseThread(JNIEnv *_env, jobject _this) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 185 | return EglBoolToJBool(eglReleaseThread()); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 188 | static jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display, |
| 189 | jintArray attrib_list, jobjectArray configs, jint config_size, jintArray num_config) { |
| 190 | if (display == NULL |
| 191 | || !validAttribList(_env, attrib_list) |
| 192 | || (configs != NULL && _env->GetArrayLength(configs) < config_size) |
| 193 | || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 194 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | return JNI_FALSE; |
| 196 | } |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 197 | EGLDisplay dpy = getDisplay(_env, display); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 198 | EGLBoolean success = EGL_FALSE; |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 199 | |
| 200 | if (configs == NULL) { |
| 201 | config_size = 0; |
| 202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | EGLConfig nativeConfigs[config_size]; |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 204 | |
| 205 | int num = 0; |
| 206 | jint* attrib_base = beginNativeAttribList(_env, attrib_list); |
| 207 | success = eglChooseConfig(dpy, attrib_base, configs ? nativeConfigs : 0, config_size, &num); |
| 208 | endNativeAttributeList(_env, attrib_list, attrib_base); |
| 209 | |
| 210 | if (num_config != NULL) { |
| 211 | _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num); |
| 212 | } |
| 213 | |
| 214 | if (success && configs!=NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | for (int i=0 ; i<num ; i++) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 216 | jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i])); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | _env->SetObjectArrayElement(configs, i, obj); |
| 218 | } |
| 219 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 220 | return EglBoolToJBool(success); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 221 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 223 | static jlong jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | jobject config, jobject share_context, jintArray attrib_list) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 225 | if (display == NULL || config == NULL || share_context == NULL |
| 226 | || !validAttribList(_env, attrib_list)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 227 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 228 | return JNI_FALSE; |
| 229 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | EGLDisplay dpy = getDisplay(_env, display); |
| 231 | EGLConfig cnf = getConfig(_env, config); |
| 232 | EGLContext shr = getContext(_env, share_context); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 233 | jint* base = beginNativeAttribList(_env, attrib_list); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | EGLContext ctx = eglCreateContext(dpy, cnf, shr, base); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 235 | endNativeAttributeList(_env, attrib_list, base); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 236 | return reinterpret_cast<jlong>(ctx); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 239 | static jlong jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | jobject config, jintArray attrib_list) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 241 | if (display == NULL || config == NULL |
| 242 | || !validAttribList(_env, attrib_list)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 243 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 244 | return JNI_FALSE; |
| 245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | EGLDisplay dpy = getDisplay(_env, display); |
| 247 | EGLConfig cnf = getConfig(_env, config); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 248 | jint* base = beginNativeAttribList(_env, attrib_list); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | EGLSurface sur = eglCreatePbufferSurface(dpy, cnf, base); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 250 | endNativeAttributeList(_env, attrib_list, base); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 251 | return reinterpret_cast<jlong>(sur); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 254 | static void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | jobject display, jobject config, jobject native_pixmap, |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 256 | jintArray attrib_list) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | { |
Romain Guy | 1f071dd | 2016-11-30 10:20:29 -0800 | [diff] [blame] | 258 | jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglCreatePixmapSurface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 261 | static jlong jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | jobject config, jobject native_window, jintArray attrib_list) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 263 | if (display == NULL || config == NULL |
| 264 | || !validAttribList(_env, attrib_list)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 265 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 266 | return JNI_FALSE; |
| 267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | EGLDisplay dpy = getDisplay(_env, display); |
| 269 | EGLContext cnf = getConfig(_env, config); |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 270 | sp<ANativeWindow> window; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | if (native_window == NULL) { |
| 272 | not_valid_surface: |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 273 | jniThrowException(_env, "java/lang/IllegalArgumentException", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"); |
| 275 | return 0; |
| 276 | } |
Mathias Agopian | 8b73ae4 | 2010-06-10 17:02:51 -0700 | [diff] [blame] | 277 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 278 | window = android_view_Surface_getNativeWindow(_env, native_window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | if (window == NULL) |
| 280 | goto not_valid_surface; |
| 281 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 282 | jint* base = beginNativeAttribList(_env, attrib_list); |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 283 | EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 284 | endNativeAttributeList(_env, attrib_list, base); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 285 | return reinterpret_cast<jlong>(sur); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 288 | static jlong jni_eglCreateWindowSurfaceTexture(JNIEnv *_env, jobject _this, jobject display, |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 289 | jobject config, jobject native_window, jintArray attrib_list) { |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 290 | if (display == NULL || config == NULL |
| 291 | || !validAttribList(_env, attrib_list)) { |
| 292 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 293 | return 0; |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 294 | } |
| 295 | EGLDisplay dpy = getDisplay(_env, display); |
| 296 | EGLContext cnf = getConfig(_env, config); |
| 297 | sp<ANativeWindow> window; |
| 298 | if (native_window == 0) { |
| 299 | not_valid_surface: |
| 300 | jniThrowException(_env, "java/lang/IllegalArgumentException", |
| 301 | "Make sure the SurfaceTexture is valid"); |
| 302 | return 0; |
| 303 | } |
Jesse Hall | 0fa257f | 2013-08-30 13:49:14 -0700 | [diff] [blame] | 304 | |
Mathias Agopian | 52a9a10 | 2013-08-02 01:38:38 -0700 | [diff] [blame] | 305 | sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(_env, native_window)); |
Jesse Hall | 0fa257f | 2013-08-30 13:49:14 -0700 | [diff] [blame] | 306 | window = new Surface(producer, true); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 307 | if (window == NULL) |
| 308 | goto not_valid_surface; |
| 309 | |
| 310 | jint* base = beginNativeAttribList(_env, attrib_list); |
| 311 | EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base); |
| 312 | endNativeAttributeList(_env, attrib_list, base); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 313 | return reinterpret_cast<jlong>(sur); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 316 | static jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | jobject config, jint attribute, jintArray value) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 318 | if (display == NULL || config == NULL |
| 319 | || (value == NULL || _env->GetArrayLength(value) < 1)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 320 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | return JNI_FALSE; |
| 322 | } |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 323 | EGLDisplay dpy = getDisplay(_env, display); |
| 324 | EGLContext cnf = getConfig(_env, config); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 325 | EGLBoolean success = EGL_FALSE; |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 326 | jint localValue; |
| 327 | success = eglGetConfigAttrib(dpy, cnf, attribute, &localValue); |
| 328 | if (success) { |
| 329 | _env->SetIntArrayRegion(value, 0, 1, &localValue); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 331 | return EglBoolToJBool(success); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 334 | static jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | jobjectArray configs, jint config_size, jintArray num_config) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 336 | if (display == NULL || (configs != NULL && _env->GetArrayLength(configs) < config_size) |
| 337 | || (num_config != NULL && _env->GetArrayLength(num_config) < 1)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 338 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | return JNI_FALSE; |
| 340 | } |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 341 | EGLDisplay dpy = getDisplay(_env, display); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 342 | EGLBoolean success = EGL_FALSE; |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 343 | if (configs == NULL) { |
| 344 | config_size = 0; |
| 345 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | EGLConfig nativeConfigs[config_size]; |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 347 | int num; |
| 348 | success = eglGetConfigs(dpy, configs ? nativeConfigs : 0, config_size, &num); |
| 349 | if (num_config != NULL) { |
| 350 | _env->SetIntArrayRegion(num_config, 0, 1, (jint*) &num); |
| 351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | if (success && configs) { |
| 353 | for (int i=0 ; i<num ; i++) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 354 | jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i])); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | _env->SetObjectArrayElement(configs, i, obj); |
| 356 | } |
| 357 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 358 | return EglBoolToJBool(success); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | } |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 360 | |
| 361 | static jint jni_eglGetError(JNIEnv *_env, jobject _this) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | EGLint error = eglGetError(); |
| 363 | return error; |
| 364 | } |
| 365 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 366 | static jlong jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) { |
| 367 | return reinterpret_cast<jlong>(eglGetCurrentContext()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 370 | static jlong jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) { |
| 371 | return reinterpret_cast<jlong>(eglGetCurrentDisplay()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 374 | static jlong jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) { |
Romain Guy | 9b7146d | 2011-03-07 18:05:04 -0800 | [diff] [blame] | 375 | if ((readdraw != EGL_READ) && (readdraw != EGL_DRAW)) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 376 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 377 | return 0; |
| 378 | } |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 379 | return reinterpret_cast<jlong>(eglGetCurrentSurface(readdraw)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 382 | static jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject display, jobject context) { |
| 383 | if (display == NULL || context == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 384 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 385 | return JNI_FALSE; |
| 386 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | EGLDisplay dpy = getDisplay(_env, display); |
| 388 | EGLContext ctx = getContext(_env, context); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 389 | return EglBoolToJBool(eglDestroyContext(dpy, ctx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 392 | static jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface) { |
| 393 | if (display == NULL || surface == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 394 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 395 | return JNI_FALSE; |
| 396 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | EGLDisplay dpy = getDisplay(_env, display); |
| 398 | EGLSurface sur = getSurface(_env, surface); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 399 | return EglBoolToJBool(eglDestroySurface(dpy, sur)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | } |
| 401 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 402 | static jlong jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) { |
| 403 | return reinterpret_cast<jlong>(eglGetDisplay(EGL_DEFAULT_DISPLAY)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | } |
| 405 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 406 | static jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobject draw, jobject read, jobject context) { |
| 407 | if (display == NULL || draw == NULL || read == NULL || context == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 408 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 409 | return JNI_FALSE; |
| 410 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | EGLDisplay dpy = getDisplay(_env, display); |
| 412 | EGLSurface sdr = getSurface(_env, draw); |
| 413 | EGLSurface srd = getSurface(_env, read); |
| 414 | EGLContext ctx = getContext(_env, context); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 415 | return EglBoolToJBool(eglMakeCurrent(dpy, sdr, srd, ctx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 418 | static jstring jni_eglQueryString(JNIEnv *_env, jobject _this, jobject display, jint name) { |
| 419 | if (display == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 420 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 421 | return NULL; |
| 422 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | EGLDisplay dpy = getDisplay(_env, display); |
| 424 | const char* chars = eglQueryString(dpy, name); |
| 425 | return _env->NewStringUTF(chars); |
| 426 | } |
| 427 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 428 | static jboolean jni_eglSwapBuffers(JNIEnv *_env, jobject _this, jobject display, jobject surface) { |
| 429 | if (display == NULL || surface == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 430 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 431 | return JNI_FALSE; |
| 432 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | EGLDisplay dpy = getDisplay(_env, display); |
| 434 | EGLSurface sur = getSurface(_env, surface); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 435 | return EglBoolToJBool(eglSwapBuffers(dpy, sur)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 438 | static jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) { |
| 439 | if (display == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 440 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 441 | return JNI_FALSE; |
| 442 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | EGLDisplay dpy = getDisplay(_env, display); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 444 | return EglBoolToJBool(eglTerminate(dpy)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 447 | static jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | jobject surface, jobject native_pixmap) { |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 449 | if (display == NULL || surface == NULL || native_pixmap == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 450 | jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 451 | return JNI_FALSE; |
| 452 | } |
| 453 | // TODO: Implement this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | return JNI_FALSE; |
| 455 | } |
| 456 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 457 | static jboolean jni_eglWaitGL(JNIEnv *_env, jobject _this) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 458 | return EglBoolToJBool(eglWaitGL()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Jack Palevich | 1badb71 | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 461 | static jboolean jni_eglWaitNative(JNIEnv *_env, jobject _this, jint engine, jobject bindTarget) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 462 | return EglBoolToJBool(eglWaitNative(engine)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | |
| 466 | static const char *classPathName = "com/google/android/gles_jni/EGLImpl"; |
| 467 | |
| 468 | #define DISPLAY "Ljavax/microedition/khronos/egl/EGLDisplay;" |
| 469 | #define CONTEXT "Ljavax/microedition/khronos/egl/EGLContext;" |
| 470 | #define CONFIG "Ljavax/microedition/khronos/egl/EGLConfig;" |
| 471 | #define SURFACE "Ljavax/microedition/khronos/egl/EGLSurface;" |
| 472 | #define OBJECT "Ljava/lang/Object;" |
| 473 | #define STRING "Ljava/lang/String;" |
| 474 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 475 | static const JNINativeMethod methods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | {"_nativeClassInit","()V", (void*)nativeClassInit }, |
| 477 | {"eglWaitGL", "()Z", (void*)jni_eglWaitGL }, |
| 478 | {"eglInitialize", "(" DISPLAY "[I)Z", (void*)jni_eglInitialize }, |
| 479 | {"eglQueryContext", "(" DISPLAY CONTEXT "I[I)Z", (void*)jni_eglQueryContext }, |
| 480 | {"eglQuerySurface", "(" DISPLAY SURFACE "I[I)Z", (void*)jni_eglQuerySurface }, |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 481 | {"eglReleaseThread","()Z", (void*)jni_eglReleaseThread }, |
| 482 | {"getInitCount", "(" DISPLAY ")I", (void*)jni_getInitCount }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | {"eglChooseConfig", "(" DISPLAY "[I[" CONFIG "I[I)Z", (void*)jni_eglChooseConfig }, |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 484 | {"_eglCreateContext","(" DISPLAY CONFIG CONTEXT "[I)J", (void*)jni_eglCreateContext }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | {"eglGetConfigs", "(" DISPLAY "[" CONFIG "I[I)Z", (void*)jni_eglGetConfigs }, |
| 486 | {"eglTerminate", "(" DISPLAY ")Z", (void*)jni_eglTerminate }, |
| 487 | {"eglCopyBuffers", "(" DISPLAY SURFACE OBJECT ")Z", (void*)jni_eglCopyBuffers }, |
| 488 | {"eglWaitNative", "(I" OBJECT ")Z", (void*)jni_eglWaitNative }, |
| 489 | {"eglGetError", "()I", (void*)jni_eglGetError }, |
| 490 | {"eglGetConfigAttrib", "(" DISPLAY CONFIG "I[I)Z", (void*)jni_eglGetConfigAttrib }, |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 491 | {"_eglGetDisplay", "(" OBJECT ")J", (void*)jni_eglGetDisplay }, |
| 492 | {"_eglGetCurrentContext", "()J", (void*)jni_eglGetCurrentContext }, |
| 493 | {"_eglGetCurrentDisplay", "()J", (void*)jni_eglGetCurrentDisplay }, |
| 494 | {"_eglGetCurrentSurface", "(I)J", (void*)jni_eglGetCurrentSurface }, |
| 495 | {"_eglCreatePbufferSurface","(" DISPLAY CONFIG "[I)J", (void*)jni_eglCreatePbufferSurface }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | {"_eglCreatePixmapSurface", "(" SURFACE DISPLAY CONFIG OBJECT "[I)V", (void*)jni_eglCreatePixmapSurface }, |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 497 | {"_eglCreateWindowSurface", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurface }, |
| 498 | {"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurfaceTexture }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | {"eglDestroyContext", "(" DISPLAY CONTEXT ")Z", (void*)jni_eglDestroyContext }, |
| 500 | {"eglDestroySurface", "(" DISPLAY SURFACE ")Z", (void*)jni_eglDestroySurface }, |
| 501 | {"eglMakeCurrent", "(" DISPLAY SURFACE SURFACE CONTEXT")Z", (void*)jni_eglMakeCurrent }, |
| 502 | {"eglQueryString", "(" DISPLAY "I)" STRING, (void*)jni_eglQueryString }, |
| 503 | {"eglSwapBuffers", "(" DISPLAY SURFACE ")Z", (void*)jni_eglSwapBuffers }, |
| 504 | }; |
| 505 | |
| 506 | } // namespace android |
| 507 | |
| 508 | int register_com_google_android_gles_jni_EGLImpl(JNIEnv *_env) |
| 509 | { |
| 510 | int err; |
| 511 | err = android::AndroidRuntime::registerNativeMethods(_env, |
| 512 | android::classPathName, android::methods, NELEM(android::methods)); |
| 513 | return err; |
| 514 | } |