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 "jni.h" 20#include "JNIHelp.h" 21#include <android_runtime/AndroidRuntime.h> 22#include <utils/misc.h> 23 24#include <assert.h> 25#include <GLES2/gl2.h> 26#include <GLES2/gl2ext.h> 27 28static int initialized = 0; 29 30static jclass nioAccessClass; 31static jclass bufferClass; 32static jmethodID getBasePointerID; 33static jmethodID getBaseArrayID; 34static jmethodID getBaseArrayOffsetID; 35static jfieldID positionID; 36static jfieldID limitID; 37static jfieldID elementSizeShiftID; 38 39/* Cache method IDs each time the class is loaded. */ 40 41static void 42nativeClassInit(JNIEnv *_env, jclass glImplClass) 43{ 44 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); 45 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); 46 47 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); 48 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); 49 50 getBasePointerID = _env->GetStaticMethodID(nioAccessClass, 51 "getBasePointer", "(Ljava/nio/Buffer;)J"); 52 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, 53 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); 54 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, 55 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); 56 57 positionID = _env->GetFieldID(bufferClass, "position", "I"); 58 limitID = _env->GetFieldID(bufferClass, "limit", "I"); 59 elementSizeShiftID = 60 _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); 61} 62 63 64static void * 65getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) 66{ 67 jint position; 68 jint limit; 69 jint elementSizeShift; 70 jlong pointer; 71 jint offset; 72 void *data; 73 74 position = _env->GetIntField(buffer, positionID); 75 limit = _env->GetIntField(buffer, limitID); 76 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); 77 *remaining = (limit - position) << elementSizeShift; 78 pointer = _env->CallStaticLongMethod(nioAccessClass, 79 getBasePointerID, buffer); 80 if (pointer != 0L) { 81 *array = NULL; 82 return (void *) (jint) pointer; 83 } 84 85 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, 86 getBaseArrayID, buffer); 87 offset = _env->CallStaticIntMethod(nioAccessClass, 88 getBaseArrayOffsetID, buffer); 89 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); 90 91 return (void *) ((char *) data + offset); 92} 93 94 95static void 96releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) 97{ 98 _env->ReleasePrimitiveArrayCritical(array, data, 99 commit ? 0 : JNI_ABORT); 100} 101 102static void * 103getDirectBufferPointer(JNIEnv *_env, jobject buffer) { 104 char* buf = (char*) _env->GetDirectBufferAddress(buffer); 105 if (buf) { 106 jint position = _env->GetIntField(buffer, positionID); 107 jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); 108 buf += position << elementSizeShift; 109 } else { 110 jniThrowException(_env, "java/lang/IllegalArgumentException", 111 "Must use a native order direct Buffer"); 112 } 113 return (void*) buf; 114} 115 116static int 117getNumCompressedTextureFormats() { 118 int numCompressedTextureFormats = 0; 119 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); 120 return numCompressedTextureFormats; 121} 122 123static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type, 124 GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) { 125 glVertexAttribPointer(indx, size, type, normalized, stride, pointer); 126} 127 128// -------------------------------------------------------------------------- 129