The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | ** |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 2 | ** Copyright 2009, The Android Open Source Project |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // This source file is automatically generated |
| 18 | |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 19 | #include "jni.h" |
| 20 | #include "JNIHelp.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | #include <utils/misc.h> |
| 23 | |
| 24 | #include <assert.h> |
| 25 | #include <GLES/gl.h> |
Jack Palevich | be509c9 | 2009-05-07 09:52:14 -0700 | [diff] [blame] | 26 | #include <GLES/glext.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
Mathias Agopian | 8331f72 | 2009-05-08 15:35:17 -0700 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | static int initialized = 0; |
| 42 | |
| 43 | static jclass nioAccessClass; |
| 44 | static jclass bufferClass; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 54 | static void |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 55 | nativeClassInit(JNIEnv *_env, jclass glImplClass) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | static void * |
| 77 | getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) |
| 78 | { |
| 79 | jint position; |
| 80 | jint limit; |
| 81 | jint elementSizeShift; |
| 82 | jlong pointer; |
| 83 | jint offset; |
| 84 | void *data; |
| 85 | |
| 86 | position = _env->GetIntField(buffer, positionID); |
| 87 | limit = _env->GetIntField(buffer, limitID); |
| 88 | elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 89 | *remaining = (limit - position) << elementSizeShift; |
| 90 | pointer = _env->CallStaticLongMethod(nioAccessClass, |
| 91 | getBasePointerID, buffer); |
| 92 | if (pointer != 0L) { |
| 93 | *array = NULL; |
| 94 | return (void *) (jint) pointer; |
| 95 | } |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 96 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, |
| 98 | getBaseArrayID, buffer); |
| 99 | offset = _env->CallStaticIntMethod(nioAccessClass, |
| 100 | getBaseArrayOffsetID, buffer); |
| 101 | data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | return (void *) ((char *) data + offset); |
| 104 | } |
| 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | static void |
| 107 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 108 | { |
| 109 | _env->ReleasePrimitiveArrayCritical(array, data, |
| 110 | commit ? 0 : JNI_ABORT); |
| 111 | } |
| 112 | |
Jack Palevich | 16e7972 | 2009-05-15 18:13:34 -0700 | [diff] [blame] | 113 | static void * |
| 114 | getDirectBufferPointer(JNIEnv *_env, jobject buffer) { |
| 115 | char* buf = (char*) _env->GetDirectBufferAddress(buffer); |
| 116 | if (buf) { |
| 117 | jint position = _env->GetIntField(buffer, positionID); |
| 118 | jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); |
| 119 | buf += position << elementSizeShift; |
| 120 | } else { |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame^] | 121 | jniThrowException(_env, "java/lang/IllegalArgumentException", |
| 122 | "Must use a native order direct Buffer"); |
Jack Palevich | 16e7972 | 2009-05-15 18:13:34 -0700 | [diff] [blame] | 123 | } |
| 124 | return (void*) buf; |
| 125 | } |
| 126 | |
Jack Palevich | be509c9 | 2009-05-07 09:52:14 -0700 | [diff] [blame] | 127 | static int |
| 128 | getNumCompressedTextureFormats() { |
| 129 | int numCompressedTextureFormats = 0; |
| 130 | glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); |
| 131 | return numCompressedTextureFormats; |
| 132 | } |
| 133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | // -------------------------------------------------------------------------- |