Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame^] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2009, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | // This source file is automatically generated |
| 19 | |
| 20 | #include <android_runtime/AndroidRuntime.h> |
| 21 | #include <utils/misc.h> |
| 22 | |
| 23 | #include <assert.h> |
| 24 | #include <GLES/gl.h> |
| 25 | |
| 26 | #include <private/opengles/gl_context.h> |
| 27 | |
| 28 | #define _NUM_COMPRESSED_TEXTURE_FORMATS \ |
| 29 | (::android::OGLES_NUM_COMPRESSED_TEXTURE_FORMATS) |
| 30 | |
| 31 | static int initialized = 0; |
| 32 | |
| 33 | static jclass nioAccessClass; |
| 34 | static jclass bufferClass; |
| 35 | static jclass OOMEClass; |
| 36 | static jclass UOEClass; |
| 37 | static jclass IAEClass; |
| 38 | static jclass AIOOBEClass; |
| 39 | static jmethodID getBasePointerID; |
| 40 | static jmethodID getBaseArrayID; |
| 41 | static jmethodID getBaseArrayOffsetID; |
| 42 | static jfieldID positionID; |
| 43 | static jfieldID limitID; |
| 44 | static jfieldID elementSizeShiftID; |
| 45 | |
| 46 | /* Cache method IDs each time the class is loaded. */ |
| 47 | |
| 48 | static void |
| 49 | nativeClassInitBuffer(JNIEnv *_env) |
| 50 | { |
| 51 | jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); |
| 52 | nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); |
| 53 | |
| 54 | jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); |
| 55 | bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); |
| 56 | |
| 57 | getBasePointerID = _env->GetStaticMethodID(nioAccessClass, |
| 58 | "getBasePointer", "(Ljava/nio/Buffer;)J"); |
| 59 | getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, |
| 60 | "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); |
| 61 | getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, |
| 62 | "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); |
| 63 | |
| 64 | positionID = _env->GetFieldID(bufferClass, "position", "I"); |
| 65 | limitID = _env->GetFieldID(bufferClass, "limit", "I"); |
| 66 | elementSizeShiftID = |
| 67 | _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | static void |
| 72 | nativeClassInit(JNIEnv *_env, jclass glImplClass) |
| 73 | { |
| 74 | nativeClassInitBuffer(_env); |
| 75 | |
| 76 | jclass IAEClassLocal = |
| 77 | _env->FindClass("java/lang/IllegalArgumentException"); |
| 78 | jclass OOMEClassLocal = |
| 79 | _env->FindClass("java/lang/OutOfMemoryError"); |
| 80 | jclass UOEClassLocal = |
| 81 | _env->FindClass("java/lang/UnsupportedOperationException"); |
| 82 | jclass AIOOBEClassLocal = |
| 83 | _env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); |
| 84 | |
| 85 | IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal); |
| 86 | OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal); |
| 87 | UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal); |
| 88 | AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal); |
| 89 | } |
| 90 | |
| 91 | static void * |
| 92 | getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) |
| 93 | { |
| 94 | jint position; |
| 95 | jint limit; |
| 96 | jint elementSizeShift; |
| 97 | jlong pointer; |
| 98 | jint offset; |
| 99 | void *data; |
| 100 | |
| 101 | position = _env->GetIntField(buffer, positionID); |
| 102 | limit = _env->GetIntField(buffer, limitID); |
| 103 | elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 104 | *remaining = (limit - position) << elementSizeShift; |
| 105 | pointer = _env->CallStaticLongMethod(nioAccessClass, |
| 106 | getBasePointerID, buffer); |
| 107 | if (pointer != 0L) { |
| 108 | *array = NULL; |
| 109 | return (void *) (jint) pointer; |
| 110 | } |
| 111 | |
| 112 | *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, |
| 113 | getBaseArrayID, buffer); |
| 114 | offset = _env->CallStaticIntMethod(nioAccessClass, |
| 115 | getBaseArrayOffsetID, buffer); |
| 116 | data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); |
| 117 | |
| 118 | return (void *) ((char *) data + offset); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | static void |
| 123 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 124 | { |
| 125 | _env->ReleasePrimitiveArrayCritical(array, data, |
| 126 | commit ? 0 : JNI_ABORT); |
| 127 | } |
| 128 | |
| 129 | // -------------------------------------------------------------------------- |
| 130 | |
| 131 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 132 | static jint |
| 133 | android_glQueryMatrixxOES___3II_3II |
| 134 | (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) { |
| 135 | jint _exception = 0; |
| 136 | GLbitfield _returnValue = -1; |
| 137 | GLfixed *mantissa_base = (GLfixed *) 0; |
| 138 | jint _mantissaRemaining; |
| 139 | GLfixed *mantissa = (GLfixed *) 0; |
| 140 | GLint *exponent_base = (GLint *) 0; |
| 141 | jint _exponentRemaining; |
| 142 | GLint *exponent = (GLint *) 0; |
| 143 | |
| 144 | if (!mantissa_ref) { |
| 145 | _exception = 1; |
| 146 | _env->ThrowNew(IAEClass, "mantissa == null"); |
| 147 | goto exit; |
| 148 | } |
| 149 | if (mantissaOffset < 0) { |
| 150 | _exception = 1; |
| 151 | _env->ThrowNew(IAEClass, "mantissaOffset < 0"); |
| 152 | goto exit; |
| 153 | } |
| 154 | _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset; |
| 155 | if (_mantissaRemaining < 16) { |
| 156 | _exception = 1; |
| 157 | _env->ThrowNew(IAEClass, "length - mantissaOffset < 16"); |
| 158 | goto exit; |
| 159 | } |
| 160 | mantissa_base = (GLfixed *) |
| 161 | _env->GetPrimitiveArrayCritical(mantissa_ref, (jboolean *)0); |
| 162 | mantissa = mantissa_base + mantissaOffset; |
| 163 | |
| 164 | if (!exponent_ref) { |
| 165 | _exception = 1; |
| 166 | _env->ThrowNew(IAEClass, "exponent == null"); |
| 167 | goto exit; |
| 168 | } |
| 169 | if (exponentOffset < 0) { |
| 170 | _exception = 1; |
| 171 | _env->ThrowNew(IAEClass, "exponentOffset < 0"); |
| 172 | goto exit; |
| 173 | } |
| 174 | _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset; |
| 175 | if (_exponentRemaining < 16) { |
| 176 | _exception = 1; |
| 177 | _env->ThrowNew(IAEClass, "length - exponentOffset < 16"); |
| 178 | goto exit; |
| 179 | } |
| 180 | exponent_base = (GLint *) |
| 181 | _env->GetPrimitiveArrayCritical(exponent_ref, (jboolean *)0); |
| 182 | exponent = exponent_base + exponentOffset; |
| 183 | |
| 184 | _returnValue = glQueryMatrixxOES( |
| 185 | (GLfixed *)mantissa, |
| 186 | (GLint *)exponent |
| 187 | ); |
| 188 | |
| 189 | exit: |
| 190 | if (exponent_base) { |
| 191 | _env->ReleasePrimitiveArrayCritical(exponent_ref, exponent_base, |
| 192 | _exception ? JNI_ABORT: 0); |
| 193 | } |
| 194 | if (mantissa_base) { |
| 195 | _env->ReleasePrimitiveArrayCritical(mantissa_ref, mantissa_base, |
| 196 | _exception ? JNI_ABORT: 0); |
| 197 | } |
| 198 | return _returnValue; |
| 199 | } |
| 200 | |
| 201 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 202 | static jint |
| 203 | android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 |
| 204 | (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) { |
| 205 | jint _exception = 0; |
| 206 | jarray _mantissaArray = (jarray) 0; |
| 207 | jarray _exponentArray = (jarray) 0; |
| 208 | GLbitfield _returnValue = -1; |
| 209 | jint _mantissaRemaining; |
| 210 | GLfixed *mantissa = (GLfixed *) 0; |
| 211 | jint _exponentRemaining; |
| 212 | GLint *exponent = (GLint *) 0; |
| 213 | |
| 214 | mantissa = (GLfixed *)getPointer(_env, mantissa_buf, &_mantissaArray, &_mantissaRemaining); |
| 215 | if (_mantissaRemaining < 16) { |
| 216 | _exception = 1; |
| 217 | _env->ThrowNew(IAEClass, "remaining() < 16"); |
| 218 | goto exit; |
| 219 | } |
| 220 | exponent = (GLint *)getPointer(_env, exponent_buf, &_exponentArray, &_exponentRemaining); |
| 221 | if (_exponentRemaining < 16) { |
| 222 | _exception = 1; |
| 223 | _env->ThrowNew(IAEClass, "remaining() < 16"); |
| 224 | goto exit; |
| 225 | } |
| 226 | _returnValue = glQueryMatrixxOES( |
| 227 | (GLfixed *)mantissa, |
| 228 | (GLint *)exponent |
| 229 | ); |
| 230 | |
| 231 | exit: |
| 232 | if (_mantissaArray) { |
| 233 | releasePointer(_env, _mantissaArray, exponent, _exception ? JNI_FALSE : JNI_TRUE); |
| 234 | } |
| 235 | if (_exponentArray) { |
| 236 | releasePointer(_env, _exponentArray, mantissa, _exception ? JNI_FALSE : JNI_TRUE); |
| 237 | } |
| 238 | return _returnValue; |
| 239 | } |
| 240 | |
| 241 | static const char *classPathName = "android/opengl/GLES10Ext"; |
| 242 | |
| 243 | static JNINativeMethod methods[] = { |
| 244 | {"_nativeClassInit", "()V", (void*)nativeClassInit }, |
| 245 | {"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II }, |
| 246 | {"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 }, |
| 247 | }; |
| 248 | |
| 249 | int register_android_opengl_jni_GLES10Ext(JNIEnv *_env) |
| 250 | { |
| 251 | int err; |
| 252 | err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods)); |
| 253 | return err; |
| 254 | } |