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
28 static int initialized = 0;
29
30 static jclass nioAccessClass;
31 static jclass bufferClass;
32 static jmethodID getBasePointerID;
33 static jmethodID getBaseArrayID;
34 static jmethodID getBaseArrayOffsetID;
35 static jfieldID positionID;
36 static jfieldID limitID;
37 static jfieldID elementSizeShiftID;
38
39 /* Cache method IDs each time the class is loaded. */
40
41 static void
nativeClassInit(JNIEnv * _env,jclass glImplClass)42 nativeClassInit(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
64 static void *
getPointer(JNIEnv * _env,jobject buffer,jarray * array,jint * remaining,jint * offset)65 getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset)
66 {
67 jint position;
68 jint limit;
69 jint elementSizeShift;
70 jlong pointer;
71
72 position = _env->GetIntField(buffer, positionID);
73 limit = _env->GetIntField(buffer, limitID);
74 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
75 *remaining = (limit - position) << elementSizeShift;
76 pointer = _env->CallStaticLongMethod(nioAccessClass,
77 getBasePointerID, buffer);
78 if (pointer != 0L) {
79 *array = NULL;
80 return (void *) (jint) pointer;
81 }
82
83 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
84 getBaseArrayID, buffer);
85 *offset = _env->CallStaticIntMethod(nioAccessClass,
86 getBaseArrayOffsetID, buffer);
87
88 return NULL;
89 }
90
91
92 static void
releasePointer(JNIEnv * _env,jarray array,void * data,jboolean commit)93 releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
94 {
95 _env->ReleasePrimitiveArrayCritical(array, data,
96 commit ? 0 : JNI_ABORT);
97 }
98
99 static void *
getDirectBufferPointer(JNIEnv * _env,jobject buffer)100 getDirectBufferPointer(JNIEnv *_env, jobject buffer) {
101 char* buf = (char*) _env->GetDirectBufferAddress(buffer);
102 if (buf) {
103 jint position = _env->GetIntField(buffer, positionID);
104 jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
105 buf += position << elementSizeShift;
106 } else {
107 jniThrowException(_env, "java/lang/IllegalArgumentException",
108 "Must use a native order direct Buffer");
109 }
110 return (void*) buf;
111 }
112
113 static int
getNumCompressedTextureFormats()114 getNumCompressedTextureFormats() {
115 int numCompressedTextureFormats = 0;
116 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats);
117 return numCompressedTextureFormats;
118 }
119
glVertexAttribPointerBounds(GLuint indx,GLint size,GLenum type,GLboolean normalized,GLsizei stride,const GLvoid * pointer,GLsizei count)120 static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type,
121 GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) {
122 glVertexAttribPointer(indx, size, type, normalized, stride, pointer);
123 }
124
125 // --------------------------------------------------------------------------
126