blob: 35a3c333a6a171ea4c16df43d5bf8da57da068e6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001**
Jack Palevich27f80022009-04-15 19:13:17 -07002** Copyright 2009, The Android Open Source Project
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07004** 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 Project9066cfe2009-03-03 19:31:44 -08007**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07008** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070010** 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 Project9066cfe2009-03-03 19:31:44 -080014** limitations under the License.
15*/
16
17// This source file is automatically generated
18
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070019#include "jni.h"
20#include "JNIHelp.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021#include <android_runtime/AndroidRuntime.h>
22#include <utils/misc.h>
23
24#include <assert.h>
25#include <GLES/gl.h>
Jack Palevichbe509c92009-05-07 09:52:14 -070026#include <GLES/glext.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Mathias Agopian8331f722009-05-08 15:35:17 -070028/* special calls implemented in Android's GLES wrapper used to more
29 * efficiently bound-check passed arrays */
30extern "C" {
31GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
32 const GLvoid *ptr, GLsizei count);
33GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride,
34 const GLvoid *pointer, GLsizei count);
35GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type,
36 GLsizei stride, const GLvoid *pointer, GLsizei count);
37GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type,
38 GLsizei stride, const GLvoid *pointer, GLsizei count);
39}
40
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041static int initialized = 0;
42
43static jclass nioAccessClass;
44static jclass bufferClass;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045static jmethodID getBasePointerID;
46static jmethodID getBaseArrayID;
47static jmethodID getBaseArrayOffsetID;
48static jfieldID positionID;
49static jfieldID limitID;
50static jfieldID elementSizeShiftID;
51
52/* Cache method IDs each time the class is loaded. */
53
Jack Palevich27f80022009-04-15 19:13:17 -070054static void
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070055nativeClassInit(JNIEnv *_env, jclass glImplClass)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056{
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 Project9066cfe2009-03-03 19:31:44 -080076static void *
77getPointer(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 Hughes24ce5fb2011-04-08 20:01:01 -070096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
98 getBaseArrayID, buffer);
99 offset = _env->CallStaticIntMethod(nioAccessClass,
100 getBaseArrayOffsetID, buffer);
101 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0);
Elliott Hughes24ce5fb2011-04-08 20:01:01 -0700102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 return (void *) ((char *) data + offset);
104}
105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106static void
107releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
108{
109 _env->ReleasePrimitiveArrayCritical(array, data,
110 commit ? 0 : JNI_ABORT);
111}
112
Jack Palevich16e79722009-05-15 18:13:34 -0700113static void *
114getDirectBufferPointer(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 Hughes24ce5fb2011-04-08 20:01:01 -0700121 jniThrowException(_env, "java/lang/IllegalArgumentException",
122 "Must use a native order direct Buffer");
Jack Palevich16e79722009-05-15 18:13:34 -0700123 }
124 return (void*) buf;
125}
126
Jack Palevichbe509c92009-05-07 09:52:14 -0700127static int
128getNumCompressedTextureFormats() {
129 int numCompressedTextureFormats = 0;
130 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats);
131 return numCompressedTextureFormats;
132}
133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134// --------------------------------------------------------------------------