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