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 * |
| 66 | getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) |
| 67 | { |
| 68 | jint position; |
| 69 | jint limit; |
| 70 | jint elementSizeShift; |
| 71 | jlong pointer; |
| 72 | jint offset; |
| 73 | void *data; |
| 74 | |
| 75 | position = _env->GetIntField(buffer, positionID); |
| 76 | limit = _env->GetIntField(buffer, limitID); |
| 77 | elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 78 | *remaining = (limit - position) << elementSizeShift; |
| 79 | pointer = _env->CallStaticLongMethod(nioAccessClass, |
| 80 | getBasePointerID, buffer); |
| 81 | if (pointer != 0L) { |
| 82 | *array = NULL; |
| 83 | return (void *) (jint) pointer; |
| 84 | } |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 85 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 86 | *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, |
| 87 | getBaseArrayID, buffer); |
| 88 | offset = _env->CallStaticIntMethod(nioAccessClass, |
| 89 | getBaseArrayOffsetID, buffer); |
| 90 | data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 91 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 92 | return (void *) ((char *) data + offset); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | static void |
| 97 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 98 | { |
| 99 | _env->ReleasePrimitiveArrayCritical(array, data, |
| 100 | commit ? 0 : JNI_ABORT); |
| 101 | } |
| 102 | |
| 103 | // -------------------------------------------------------------------------- |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 104 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 105 | static jint |
| 106 | android_glQueryMatrixxOES___3II_3II |
| 107 | (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) { |
| 108 | jint _exception = 0; |
| 109 | GLbitfield _returnValue = -1; |
| 110 | GLfixed *mantissa_base = (GLfixed *) 0; |
| 111 | jint _mantissaRemaining; |
| 112 | GLfixed *mantissa = (GLfixed *) 0; |
| 113 | GLint *exponent_base = (GLint *) 0; |
| 114 | jint _exponentRemaining; |
| 115 | GLint *exponent = (GLint *) 0; |
| 116 | |
| 117 | if (!mantissa_ref) { |
| 118 | _exception = 1; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 119 | jniThrowException(_env, "java/lang/IllegalArgumentException", "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; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 124 | jniThrowException(_env, "java/lang/IllegalArgumentException", "mantissaOffset < 0"); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 125 | goto exit; |
| 126 | } |
| 127 | _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset; |
| 128 | if (_mantissaRemaining < 16) { |
| 129 | _exception = 1; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 130 | jniThrowException(_env, "java/lang/IllegalArgumentException", "length - mantissaOffset < 16"); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 131 | goto exit; |
| 132 | } |
| 133 | mantissa_base = (GLfixed *) |
| 134 | _env->GetPrimitiveArrayCritical(mantissa_ref, (jboolean *)0); |
| 135 | mantissa = mantissa_base + mantissaOffset; |
| 136 | |
| 137 | if (!exponent_ref) { |
| 138 | _exception = 1; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 139 | jniThrowException(_env, "java/lang/IllegalArgumentException", "exponent == null"); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 140 | goto exit; |
| 141 | } |
| 142 | if (exponentOffset < 0) { |
| 143 | _exception = 1; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 144 | jniThrowException(_env, "java/lang/IllegalArgumentException", "exponentOffset < 0"); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 145 | goto exit; |
| 146 | } |
| 147 | _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset; |
| 148 | if (_exponentRemaining < 16) { |
| 149 | _exception = 1; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 150 | jniThrowException(_env, "java/lang/IllegalArgumentException", "length - exponentOffset < 16"); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 151 | goto exit; |
| 152 | } |
| 153 | exponent_base = (GLint *) |
| 154 | _env->GetPrimitiveArrayCritical(exponent_ref, (jboolean *)0); |
| 155 | exponent = exponent_base + exponentOffset; |
| 156 | |
| 157 | _returnValue = glQueryMatrixxOES( |
| 158 | (GLfixed *)mantissa, |
| 159 | (GLint *)exponent |
| 160 | ); |
| 161 | |
| 162 | exit: |
| 163 | if (exponent_base) { |
| 164 | _env->ReleasePrimitiveArrayCritical(exponent_ref, exponent_base, |
| 165 | _exception ? JNI_ABORT: 0); |
| 166 | } |
| 167 | if (mantissa_base) { |
| 168 | _env->ReleasePrimitiveArrayCritical(mantissa_ref, mantissa_base, |
| 169 | _exception ? JNI_ABORT: 0); |
| 170 | } |
| 171 | return _returnValue; |
| 172 | } |
| 173 | |
| 174 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 175 | static jint |
| 176 | android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 |
| 177 | (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) { |
| 178 | jint _exception = 0; |
| 179 | jarray _mantissaArray = (jarray) 0; |
| 180 | jarray _exponentArray = (jarray) 0; |
| 181 | GLbitfield _returnValue = -1; |
| 182 | jint _mantissaRemaining; |
| 183 | GLfixed *mantissa = (GLfixed *) 0; |
| 184 | jint _exponentRemaining; |
| 185 | GLint *exponent = (GLint *) 0; |
| 186 | |
| 187 | mantissa = (GLfixed *)getPointer(_env, mantissa_buf, &_mantissaArray, &_mantissaRemaining); |
| 188 | if (_mantissaRemaining < 16) { |
| 189 | _exception = 1; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 190 | jniThrowException(_env, "java/lang/IllegalArgumentException", "remaining() < 16"); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 191 | goto exit; |
| 192 | } |
| 193 | exponent = (GLint *)getPointer(_env, exponent_buf, &_exponentArray, &_exponentRemaining); |
| 194 | if (_exponentRemaining < 16) { |
| 195 | _exception = 1; |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 196 | jniThrowException(_env, "java/lang/IllegalArgumentException", "remaining() < 16"); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 197 | goto exit; |
| 198 | } |
| 199 | _returnValue = glQueryMatrixxOES( |
| 200 | (GLfixed *)mantissa, |
| 201 | (GLint *)exponent |
| 202 | ); |
| 203 | |
| 204 | exit: |
| 205 | if (_mantissaArray) { |
| 206 | releasePointer(_env, _mantissaArray, exponent, _exception ? JNI_FALSE : JNI_TRUE); |
| 207 | } |
| 208 | if (_exponentArray) { |
| 209 | releasePointer(_env, _exponentArray, mantissa, _exception ? JNI_FALSE : JNI_TRUE); |
| 210 | } |
| 211 | return _returnValue; |
| 212 | } |
| 213 | |
| 214 | static const char *classPathName = "android/opengl/GLES10Ext"; |
| 215 | |
| 216 | static JNINativeMethod methods[] = { |
| 217 | {"_nativeClassInit", "()V", (void*)nativeClassInit }, |
| 218 | {"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II }, |
| 219 | {"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 }, |
| 220 | }; |
| 221 | |
| 222 | int register_android_opengl_jni_GLES10Ext(JNIEnv *_env) |
| 223 | { |
| 224 | int err; |
| 225 | err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods)); |
| 226 | return err; |
| 227 | } |