GLES11ExtcHeader.cpp revision 66089a33ea4efda711a3a5180f0b001bdac48dcf
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 */ 28extern "C" { 29GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, GLsizei stride, 30 const GLvoid *ptr, GLsizei count); 31GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride, 32 const GLvoid *ptr, GLsizei count); 33} 34 35static int initialized = 0; 36 37static jclass nioAccessClass; 38static jclass bufferClass; 39static jclass OOMEClass; 40static jclass UOEClass; 41static jclass IAEClass; 42static jclass AIOOBEClass; 43static jmethodID getBasePointerID; 44static jmethodID getBaseArrayID; 45static jmethodID getBaseArrayOffsetID; 46static jfieldID positionID; 47static jfieldID limitID; 48static jfieldID elementSizeShiftID; 49 50/* Cache method IDs each time the class is loaded. */ 51 52static void 53nativeClassInitBuffer(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 75static void 76nativeClassInit(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 95static void * 96getPointer(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 126static void 127releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) 128{ 129 _env->ReleasePrimitiveArrayCritical(array, data, 130 commit ? 0 : JNI_ABORT); 131} 132 133static void * 134getDirectBufferPointer(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} 145// -------------------------------------------------------------------------- 146 147