GLES10cHeader.cpp revision be509c9c7de5929d014dfe6d45e71cc8454ede0f
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 26static int initialized = 0; 27 28static jclass nioAccessClass; 29static jclass bufferClass; 30static jclass OOMEClass; 31static jclass UOEClass; 32static jclass IAEClass; 33static jclass AIOOBEClass; 34static jmethodID getBasePointerID; 35static jmethodID getBaseArrayID; 36static jmethodID getBaseArrayOffsetID; 37static jfieldID positionID; 38static jfieldID limitID; 39static jfieldID elementSizeShiftID; 40 41/* Cache method IDs each time the class is loaded. */ 42 43static void 44nativeClassInitBuffer(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 65static void 66nativeClassInit(JNIEnv *_env, jclass glImplClass) 67{ 68 nativeClassInitBuffer(_env); 69 70 jclass IAEClassLocal = 71 _env->FindClass("java/lang/IllegalArgumentException"); 72 jclass OOMEClassLocal = 73 _env->FindClass("java/lang/OutOfMemoryError"); 74 jclass UOEClassLocal = 75 _env->FindClass("java/lang/UnsupportedOperationException"); 76 jclass AIOOBEClassLocal = 77 _env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); 78 79 IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal); 80 OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal); 81 UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal); 82 AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal); 83} 84 85static void * 86getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) 87{ 88 jint position; 89 jint limit; 90 jint elementSizeShift; 91 jlong pointer; 92 jint offset; 93 void *data; 94 95 position = _env->GetIntField(buffer, positionID); 96 limit = _env->GetIntField(buffer, limitID); 97 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); 98 *remaining = (limit - position) << elementSizeShift; 99 pointer = _env->CallStaticLongMethod(nioAccessClass, 100 getBasePointerID, buffer); 101 if (pointer != 0L) { 102 *array = NULL; 103 return (void *) (jint) pointer; 104 } 105 106 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, 107 getBaseArrayID, buffer); 108 offset = _env->CallStaticIntMethod(nioAccessClass, 109 getBaseArrayOffsetID, buffer); 110 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); 111 112 return (void *) ((char *) data + offset); 113} 114 115static void 116releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) 117{ 118 _env->ReleasePrimitiveArrayCritical(array, data, 119 commit ? 0 : JNI_ABORT); 120} 121 122static int 123getNumCompressedTextureFormats() { 124 int numCompressedTextureFormats = 0; 125 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); 126 return numCompressedTextureFormats; 127} 128 129// -------------------------------------------------------------------------- 130 131