1 ** 2 ** Copyright 2009, The Android Open Source Project 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> 24 #include <GLES/glext.h> 25 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 glColorPointerBounds(GLint size, GLenum type, GLsizei stride, 30 const GLvoid *ptr, GLsizei count); 31 GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, 32 const GLvoid *pointer, GLsizei count); 33 GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, 34 GLsizei stride, const GLvoid *pointer, GLsizei count); 35 GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type, 36 GLsizei stride, const GLvoid *pointer, GLsizei count); 37 } 38 39 static int initialized = 0; 40 41 static jclass nioAccessClass; 42 static jclass bufferClass; 43 static jclass OOMEClass; 44 static jclass UOEClass; 45 static jclass IAEClass; 46 static jclass AIOOBEClass; 47 static jmethodID getBasePointerID; 48 static jmethodID getBaseArrayID; 49 static jmethodID getBaseArrayOffsetID; 50 static jfieldID positionID; 51 static jfieldID limitID; 52 static jfieldID elementSizeShiftID; 53 54 /* Cache method IDs each time the class is loaded. */ 55 56 static void 57 nativeClassInitBuffer(JNIEnv *_env) 58 { 59 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); 60 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); 61 62 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); 63 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); 64 65 getBasePointerID = _env->GetStaticMethodID(nioAccessClass, 66 "getBasePointer", "(Ljava/nio/Buffer;)J"); 67 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, 68 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); 69 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, 70 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); 71 72 positionID = _env->GetFieldID(bufferClass, "position", "I"); 73 limitID = _env->GetFieldID(bufferClass, "limit", "I"); 74 elementSizeShiftID = 75 _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); 76 } 77 78 static void 79 nativeClassInit(JNIEnv *_env, jclass glImplClass) 80 { 81 nativeClassInitBuffer(_env); 82 83 jclass IAEClassLocal = 84 _env->FindClass("java/lang/IllegalArgumentException"); 85 jclass OOMEClassLocal = 86 _env->FindClass("java/lang/OutOfMemoryError"); 87 jclass UOEClassLocal = 88 _env->FindClass("java/lang/UnsupportedOperationException"); 89 jclass AIOOBEClassLocal = 90 _env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); 91 92 IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal); 93 OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal); 94 UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal); 95 AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal); 96 } 97 98 static void * 99 getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) 100 { 101 jint position; 102 jint limit; 103 jint elementSizeShift; 104 jlong pointer; 105 jint offset; 106 void *data; 107 108 position = _env->GetIntField(buffer, positionID); 109 limit = _env->GetIntField(buffer, limitID); 110 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); 111 *remaining = (limit - position) << elementSizeShift; 112 pointer = _env->CallStaticLongMethod(nioAccessClass, 113 getBasePointerID, buffer); 114 if (pointer != 0L) { 115 *array = NULL; 116 return (void *) (jint) pointer; 117 } 118 119 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, 120 getBaseArrayID, buffer); 121 offset = _env->CallStaticIntMethod(nioAccessClass, 122 getBaseArrayOffsetID, buffer); 123 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); 124 125 return (void *) ((char *) data + offset); 126 } 127 128 static void 129 releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) 130 { 131 _env->ReleasePrimitiveArrayCritical(array, data, 132 commit ? 0 : JNI_ABORT); 133 } 134 135 static void * 136 getDirectBufferPointer(JNIEnv *_env, jobject buffer) { 137 char* buf = (char*) _env->GetDirectBufferAddress(buffer); 138 if (buf) { 139 jint position = _env->GetIntField(buffer, positionID); 140 jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); 141 buf += position << elementSizeShift; 142 } else { 143 _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); 144 } 145 return (void*) buf; 146 } 147 148 static int 149 getNumCompressedTextureFormats() { 150 int numCompressedTextureFormats = 0; 151 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); 152 return numCompressedTextureFormats; 153 } 154 155 // -------------------------------------------------------------------------- 156 157