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