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 | |
| 26 | static int initialized = 0; |
| 27 | |
| 28 | static jclass nioAccessClass; |
| 29 | static jclass bufferClass; |
| 30 | static jclass OOMEClass; |
| 31 | static jclass UOEClass; |
| 32 | static jclass IAEClass; |
| 33 | static jclass AIOOBEClass; |
| 34 | static jmethodID getBasePointerID; |
| 35 | static jmethodID getBaseArrayID; |
| 36 | static jmethodID getBaseArrayOffsetID; |
| 37 | static jfieldID positionID; |
| 38 | static jfieldID limitID; |
| 39 | static jfieldID elementSizeShiftID; |
| 40 | |
| 41 | /* Cache method IDs each time the class is loaded. */ |
| 42 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 43 | static void |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | nativeClassInitBuffer(JNIEnv *_env) |
| 45 | { |
| 46 | jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); |
| 47 | nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); |
| 48 | |
| 49 | jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); |
| 50 | bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); |
| 51 | |
| 52 | getBasePointerID = _env->GetStaticMethodID(nioAccessClass, |
| 53 | "getBasePointer", "(Ljava/nio/Buffer;)J"); |
| 54 | getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, |
| 55 | "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); |
| 56 | getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, |
| 57 | "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); |
| 58 | |
| 59 | positionID = _env->GetFieldID(bufferClass, "position", "I"); |
| 60 | limitID = _env->GetFieldID(bufferClass, "limit", "I"); |
| 61 | elementSizeShiftID = |
| 62 | _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | static void |
| 67 | nativeClassInit(JNIEnv *_env, jclass glImplClass) |
| 68 | { |
| 69 | nativeClassInitBuffer(_env); |
| 70 | |
| 71 | jclass IAEClassLocal = |
| 72 | _env->FindClass("java/lang/IllegalArgumentException"); |
| 73 | jclass OOMEClassLocal = |
| 74 | _env->FindClass("java/lang/OutOfMemoryError"); |
| 75 | jclass UOEClassLocal = |
| 76 | _env->FindClass("java/lang/UnsupportedOperationException"); |
| 77 | jclass AIOOBEClassLocal = |
| 78 | _env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); |
| 79 | |
| 80 | IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal); |
| 81 | OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal); |
| 82 | UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal); |
| 83 | AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal); |
| 84 | } |
| 85 | |
| 86 | static void * |
| 87 | getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) |
| 88 | { |
| 89 | jint position; |
| 90 | jint limit; |
| 91 | jint elementSizeShift; |
| 92 | jlong pointer; |
| 93 | jint offset; |
| 94 | void *data; |
| 95 | |
| 96 | position = _env->GetIntField(buffer, positionID); |
| 97 | limit = _env->GetIntField(buffer, limitID); |
| 98 | elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 99 | *remaining = (limit - position) << elementSizeShift; |
| 100 | pointer = _env->CallStaticLongMethod(nioAccessClass, |
| 101 | getBasePointerID, buffer); |
| 102 | if (pointer != 0L) { |
| 103 | *array = NULL; |
| 104 | return (void *) (jint) pointer; |
| 105 | } |
| 106 | |
| 107 | *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, |
| 108 | getBaseArrayID, buffer); |
| 109 | offset = _env->CallStaticIntMethod(nioAccessClass, |
| 110 | getBaseArrayOffsetID, buffer); |
| 111 | data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); |
| 112 | |
| 113 | return (void *) ((char *) data + offset); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | static void |
| 118 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 119 | { |
| 120 | _env->ReleasePrimitiveArrayCritical(array, data, |
| 121 | commit ? 0 : JNI_ABORT); |
| 122 | } |
| 123 | |
| 124 | // -------------------------------------------------------------------------- |
| 125 | |