Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2009, The Android Open Source Project |
| 4 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -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 |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 8 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 10 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -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 |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | // This source file is automatically generated |
| 19 | |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 20 | #include "jni.h" |
| 21 | #include "JNIHelp.h" |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 22 | #include <android_runtime/AndroidRuntime.h> |
| 23 | #include <utils/misc.h> |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <GLES/gl.h> |
Jack Palevich | be509c9 | 2009-05-07 09:52:14 -0700 | [diff] [blame] | 27 | #include <GLES/glext.h> |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 28 | |
| 29 | static int initialized = 0; |
| 30 | |
| 31 | static jclass nioAccessClass; |
| 32 | static jclass bufferClass; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 33 | static jmethodID getBasePointerID; |
| 34 | static jmethodID getBaseArrayID; |
| 35 | static jmethodID getBaseArrayOffsetID; |
| 36 | static jfieldID positionID; |
| 37 | static jfieldID limitID; |
| 38 | static jfieldID elementSizeShiftID; |
| 39 | |
| 40 | /* Cache method IDs each time the class is loaded. */ |
| 41 | |
| 42 | static void |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 43 | nativeClassInit(JNIEnv *_env, jclass glImplClass) |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 44 | { |
| 45 | jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); |
| 46 | nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); |
| 47 | |
| 48 | jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); |
| 49 | bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); |
| 50 | |
| 51 | getBasePointerID = _env->GetStaticMethodID(nioAccessClass, |
| 52 | "getBasePointer", "(Ljava/nio/Buffer;)J"); |
| 53 | getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, |
| 54 | "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); |
| 55 | getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, |
| 56 | "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); |
| 57 | |
| 58 | positionID = _env->GetFieldID(bufferClass, "position", "I"); |
| 59 | limitID = _env->GetFieldID(bufferClass, "limit", "I"); |
| 60 | elementSizeShiftID = |
| 61 | _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); |
| 62 | } |
| 63 | |
| 64 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 65 | static void * |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 66 | getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 67 | { |
| 68 | jint position; |
| 69 | jint limit; |
| 70 | jint elementSizeShift; |
| 71 | jlong pointer; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 72 | |
| 73 | position = _env->GetIntField(buffer, positionID); |
| 74 | limit = _env->GetIntField(buffer, limitID); |
| 75 | elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 76 | *remaining = (limit - position) << elementSizeShift; |
| 77 | pointer = _env->CallStaticLongMethod(nioAccessClass, |
| 78 | getBasePointerID, buffer); |
| 79 | if (pointer != 0L) { |
| 80 | *array = NULL; |
| 81 | return (void *) (jint) pointer; |
| 82 | } |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 83 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 84 | *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, |
| 85 | getBaseArrayID, buffer); |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 86 | *offset = _env->CallStaticIntMethod(nioAccessClass, |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 87 | getBaseArrayOffsetID, buffer); |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 88 | |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 89 | return NULL; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
| 93 | static void |
| 94 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 95 | { |
| 96 | _env->ReleasePrimitiveArrayCritical(array, data, |
| 97 | commit ? 0 : JNI_ABORT); |
| 98 | } |
| 99 | |
| 100 | // -------------------------------------------------------------------------- |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 101 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 102 | static jint |
| 103 | android_glQueryMatrixxOES___3II_3II |
| 104 | (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) { |
| 105 | jint _exception = 0; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 106 | const char * _exceptionType; |
| 107 | const char * _exceptionMessage; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 108 | GLbitfield _returnValue = -1; |
| 109 | GLfixed *mantissa_base = (GLfixed *) 0; |
| 110 | jint _mantissaRemaining; |
| 111 | GLfixed *mantissa = (GLfixed *) 0; |
| 112 | GLint *exponent_base = (GLint *) 0; |
| 113 | jint _exponentRemaining; |
| 114 | GLint *exponent = (GLint *) 0; |
| 115 | |
| 116 | if (!mantissa_ref) { |
| 117 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 118 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 119 | _exceptionMessage = "mantissa == null"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 120 | goto exit; |
| 121 | } |
| 122 | if (mantissaOffset < 0) { |
| 123 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 124 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 125 | _exceptionMessage = "mantissaOffset < 0"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 126 | goto exit; |
| 127 | } |
| 128 | _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset; |
| 129 | if (_mantissaRemaining < 16) { |
| 130 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 131 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 132 | _exceptionMessage = "length - mantissaOffset < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 133 | goto exit; |
| 134 | } |
| 135 | mantissa_base = (GLfixed *) |
| 136 | _env->GetPrimitiveArrayCritical(mantissa_ref, (jboolean *)0); |
| 137 | mantissa = mantissa_base + mantissaOffset; |
| 138 | |
| 139 | if (!exponent_ref) { |
| 140 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 141 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 142 | _exceptionMessage = "exponent == null"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 143 | goto exit; |
| 144 | } |
| 145 | if (exponentOffset < 0) { |
| 146 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 147 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 148 | _exceptionMessage = "exponentOffset < 0"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 149 | goto exit; |
| 150 | } |
| 151 | _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset; |
| 152 | if (_exponentRemaining < 16) { |
| 153 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 154 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 155 | _exceptionMessage = "length - exponentOffset < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 156 | goto exit; |
| 157 | } |
| 158 | exponent_base = (GLint *) |
| 159 | _env->GetPrimitiveArrayCritical(exponent_ref, (jboolean *)0); |
| 160 | exponent = exponent_base + exponentOffset; |
| 161 | |
| 162 | _returnValue = glQueryMatrixxOES( |
| 163 | (GLfixed *)mantissa, |
| 164 | (GLint *)exponent |
| 165 | ); |
| 166 | |
| 167 | exit: |
| 168 | if (exponent_base) { |
| 169 | _env->ReleasePrimitiveArrayCritical(exponent_ref, exponent_base, |
| 170 | _exception ? JNI_ABORT: 0); |
| 171 | } |
| 172 | if (mantissa_base) { |
| 173 | _env->ReleasePrimitiveArrayCritical(mantissa_ref, mantissa_base, |
| 174 | _exception ? JNI_ABORT: 0); |
| 175 | } |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 176 | if (_exception) { |
| 177 | jniThrowException(_env, _exceptionType, _exceptionMessage); |
| 178 | } |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 179 | return _returnValue; |
| 180 | } |
| 181 | |
| 182 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 183 | static jint |
| 184 | android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 |
| 185 | (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) { |
| 186 | jint _exception = 0; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 187 | const char * _exceptionType; |
| 188 | const char * _exceptionMessage; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 189 | jarray _mantissaArray = (jarray) 0; |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 190 | jint _mantissaBufferOffset = (jint) 0; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 191 | jarray _exponentArray = (jarray) 0; |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 192 | jint _exponentBufferOffset = (jint) 0; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 193 | GLbitfield _returnValue = -1; |
| 194 | jint _mantissaRemaining; |
| 195 | GLfixed *mantissa = (GLfixed *) 0; |
| 196 | jint _exponentRemaining; |
| 197 | GLint *exponent = (GLint *) 0; |
| 198 | |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 199 | mantissa = (GLfixed *)getPointer(_env, mantissa_buf, &_mantissaArray, &_mantissaRemaining, &_mantissaBufferOffset); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 200 | if (_mantissaRemaining < 16) { |
| 201 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 202 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 203 | _exceptionMessage = "remaining() < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 204 | goto exit; |
| 205 | } |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 206 | exponent = (GLint *)getPointer(_env, exponent_buf, &_exponentArray, &_exponentRemaining, &_exponentBufferOffset); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 207 | if (_exponentRemaining < 16) { |
| 208 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 209 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 210 | _exceptionMessage = "remaining() < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 211 | goto exit; |
| 212 | } |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 213 | if (mantissa == NULL) { |
| 214 | char * _mantissaBase = (char *)_env->GetPrimitiveArrayCritical(_mantissaArray, (jboolean *) 0); |
| 215 | mantissa = (GLfixed *) (_mantissaBase + _mantissaBufferOffset); |
| 216 | } |
| 217 | if (exponent == NULL) { |
| 218 | char * _exponentBase = (char *)_env->GetPrimitiveArrayCritical(_exponentArray, (jboolean *) 0); |
| 219 | exponent = (GLint *) (_exponentBase + _exponentBufferOffset); |
| 220 | } |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 221 | _returnValue = glQueryMatrixxOES( |
| 222 | (GLfixed *)mantissa, |
| 223 | (GLint *)exponent |
| 224 | ); |
| 225 | |
| 226 | exit: |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 227 | if (_exponentArray) { |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 228 | releasePointer(_env, _exponentArray, exponent, _exception ? JNI_FALSE : JNI_TRUE); |
| 229 | } |
| 230 | if (_mantissaArray) { |
| 231 | releasePointer(_env, _mantissaArray, mantissa, _exception ? JNI_FALSE : JNI_TRUE); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 232 | } |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 233 | if (_exception) { |
| 234 | jniThrowException(_env, _exceptionType, _exceptionMessage); |
| 235 | } |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 236 | return _returnValue; |
| 237 | } |
| 238 | |
| 239 | static const char *classPathName = "android/opengl/GLES10Ext"; |
| 240 | |
| 241 | static JNINativeMethod methods[] = { |
| 242 | {"_nativeClassInit", "()V", (void*)nativeClassInit }, |
| 243 | {"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II }, |
| 244 | {"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 }, |
| 245 | }; |
| 246 | |
| 247 | int register_android_opengl_jni_GLES10Ext(JNIEnv *_env) |
| 248 | { |
| 249 | int err; |
| 250 | err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods)); |
| 251 | return err; |
| 252 | } |