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