The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | ** |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 2 | ** Copyright 2009, The Android Open Source Project |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | ** |
| 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ** you may not use this file except in compliance with the License. |
| 6 | ** You may obtain a copy of the License at |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
| 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // This source file is automatically generated |
| 18 | |
| 19 | #include <android_runtime/AndroidRuntime.h> |
| 20 | #include <utils/misc.h> |
| 21 | |
| 22 | #include <assert.h> |
| 23 | #include <GLES/gl.h> |
Jack Palevich | be509c9 | 2009-05-07 09:52:14 -0700 | [diff] [blame] | 24 | #include <GLES/glext.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
Jack Palevich | be6eac8 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 26 | /* special calls implemented in Android's GLES wrapper used to more |
| 27 | * efficiently bound-check passed arrays */ |
| 28 | extern "C" { |
| 29 | GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, GLsizei stride, |
| 30 | const GLvoid *ptr, GLsizei count); |
| 31 | GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride, |
| 32 | const GLvoid *ptr, GLsizei count); |
| 33 | } |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | static int initialized = 0; |
| 36 | |
| 37 | static jclass nioAccessClass; |
| 38 | static jclass bufferClass; |
| 39 | static jclass OOMEClass; |
| 40 | static jclass UOEClass; |
| 41 | static jclass IAEClass; |
| 42 | static jclass AIOOBEClass; |
| 43 | static jmethodID getBasePointerID; |
| 44 | static jmethodID getBaseArrayID; |
| 45 | static jmethodID getBaseArrayOffsetID; |
| 46 | static jfieldID positionID; |
| 47 | static jfieldID limitID; |
| 48 | static jfieldID elementSizeShiftID; |
| 49 | |
| 50 | /* Cache method IDs each time the class is loaded. */ |
| 51 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 52 | static void |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | nativeClassInitBuffer(JNIEnv *_env) |
| 54 | { |
| 55 | jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); |
| 56 | nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); |
| 57 | |
| 58 | jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); |
| 59 | bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); |
| 60 | |
| 61 | getBasePointerID = _env->GetStaticMethodID(nioAccessClass, |
| 62 | "getBasePointer", "(Ljava/nio/Buffer;)J"); |
| 63 | getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, |
| 64 | "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); |
| 65 | getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, |
| 66 | "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); |
| 67 | |
| 68 | positionID = _env->GetFieldID(bufferClass, "position", "I"); |
| 69 | limitID = _env->GetFieldID(bufferClass, "limit", "I"); |
| 70 | elementSizeShiftID = |
| 71 | _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | static void |
| 76 | nativeClassInit(JNIEnv *_env, jclass glImplClass) |
| 77 | { |
| 78 | nativeClassInitBuffer(_env); |
| 79 | |
| 80 | jclass IAEClassLocal = |
| 81 | _env->FindClass("java/lang/IllegalArgumentException"); |
| 82 | jclass OOMEClassLocal = |
| 83 | _env->FindClass("java/lang/OutOfMemoryError"); |
| 84 | jclass UOEClassLocal = |
| 85 | _env->FindClass("java/lang/UnsupportedOperationException"); |
| 86 | jclass AIOOBEClassLocal = |
| 87 | _env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); |
| 88 | |
| 89 | IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal); |
| 90 | OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal); |
| 91 | UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal); |
| 92 | AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal); |
| 93 | } |
| 94 | |
| 95 | static void * |
| 96 | getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) |
| 97 | { |
| 98 | jint position; |
| 99 | jint limit; |
| 100 | jint elementSizeShift; |
| 101 | jlong pointer; |
| 102 | jint offset; |
| 103 | void *data; |
| 104 | |
| 105 | position = _env->GetIntField(buffer, positionID); |
| 106 | limit = _env->GetIntField(buffer, limitID); |
| 107 | elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 108 | *remaining = (limit - position) << elementSizeShift; |
| 109 | pointer = _env->CallStaticLongMethod(nioAccessClass, |
| 110 | getBasePointerID, buffer); |
| 111 | if (pointer != 0L) { |
| 112 | *array = NULL; |
| 113 | return (void *) (jint) pointer; |
| 114 | } |
| 115 | |
| 116 | *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, |
| 117 | getBaseArrayID, buffer); |
| 118 | offset = _env->CallStaticIntMethod(nioAccessClass, |
| 119 | getBaseArrayOffsetID, buffer); |
| 120 | data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); |
| 121 | |
| 122 | return (void *) ((char *) data + offset); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | static void |
| 127 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 128 | { |
| 129 | _env->ReleasePrimitiveArrayCritical(array, data, |
| 130 | commit ? 0 : JNI_ABORT); |
| 131 | } |
| 132 | |
Jack Palevich | be6eac8 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 133 | static void * |
| 134 | getDirectBufferPointer(JNIEnv *_env, jobject buffer) { |
| 135 | char* buf = (char*) _env->GetDirectBufferAddress(buffer); |
| 136 | if (buf) { |
| 137 | jint position = _env->GetIntField(buffer, positionID); |
| 138 | jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 139 | buf += position << elementSizeShift; |
| 140 | } else { |
| 141 | _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); |
| 142 | } |
| 143 | return (void*) buf; |
| 144 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | // -------------------------------------------------------------------------- |
| 146 | |