blob: f17ef21a521ed95e8424ced02812b04fd86e2a1a [file] [log] [blame]
Jack Palevich27f80022009-04-15 19:13:17 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18// This source file is automatically generated
19
20#include <android_runtime/AndroidRuntime.h>
21#include <utils/misc.h>
22
23#include <assert.h>
24#include <GLES/gl.h>
Jack Palevichbe509c92009-05-07 09:52:14 -070025#include <GLES/glext.h>
Jack Palevich27f80022009-04-15 19:13:17 -070026
27static int initialized = 0;
28
29static jclass nioAccessClass;
30static jclass bufferClass;
31static jclass OOMEClass;
32static jclass UOEClass;
33static jclass IAEClass;
34static jclass AIOOBEClass;
35static jmethodID getBasePointerID;
36static jmethodID getBaseArrayID;
37static jmethodID getBaseArrayOffsetID;
38static jfieldID positionID;
39static jfieldID limitID;
40static jfieldID elementSizeShiftID;
41
42/* Cache method IDs each time the class is loaded. */
43
44static void
45nativeClassInitBuffer(JNIEnv *_env)
46{
47 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
48 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
49
50 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
51 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
52
53 getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
54 "getBasePointer", "(Ljava/nio/Buffer;)J");
55 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
56 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
57 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
58 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
59
60 positionID = _env->GetFieldID(bufferClass, "position", "I");
61 limitID = _env->GetFieldID(bufferClass, "limit", "I");
62 elementSizeShiftID =
63 _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
64}
65
66
67static void
68nativeClassInit(JNIEnv *_env, jclass glImplClass)
69{
70 nativeClassInitBuffer(_env);
71
72 jclass IAEClassLocal =
73 _env->FindClass("java/lang/IllegalArgumentException");
74 jclass OOMEClassLocal =
75 _env->FindClass("java/lang/OutOfMemoryError");
76 jclass UOEClassLocal =
77 _env->FindClass("java/lang/UnsupportedOperationException");
78 jclass AIOOBEClassLocal =
79 _env->FindClass("java/lang/ArrayIndexOutOfBoundsException");
80
81 IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal);
82 OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal);
83 UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal);
84 AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal);
85}
86
87static void *
88getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining)
89{
90 jint position;
91 jint limit;
92 jint elementSizeShift;
93 jlong pointer;
94 jint offset;
95 void *data;
96
97 position = _env->GetIntField(buffer, positionID);
98 limit = _env->GetIntField(buffer, limitID);
99 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
100 *remaining = (limit - position) << elementSizeShift;
101 pointer = _env->CallStaticLongMethod(nioAccessClass,
102 getBasePointerID, buffer);
103 if (pointer != 0L) {
104 *array = NULL;
105 return (void *) (jint) pointer;
106 }
107
108 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
109 getBaseArrayID, buffer);
110 offset = _env->CallStaticIntMethod(nioAccessClass,
111 getBaseArrayOffsetID, buffer);
112 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0);
113
114 return (void *) ((char *) data + offset);
115}
116
117
118static void
119releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
120{
121 _env->ReleasePrimitiveArrayCritical(array, data,
122 commit ? 0 : JNI_ABORT);
123}
124
125// --------------------------------------------------------------------------
126
127/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
128static jint
129android_glQueryMatrixxOES___3II_3II
130 (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) {
131 jint _exception = 0;
132 GLbitfield _returnValue = -1;
133 GLfixed *mantissa_base = (GLfixed *) 0;
134 jint _mantissaRemaining;
135 GLfixed *mantissa = (GLfixed *) 0;
136 GLint *exponent_base = (GLint *) 0;
137 jint _exponentRemaining;
138 GLint *exponent = (GLint *) 0;
139
140 if (!mantissa_ref) {
141 _exception = 1;
142 _env->ThrowNew(IAEClass, "mantissa == null");
143 goto exit;
144 }
145 if (mantissaOffset < 0) {
146 _exception = 1;
147 _env->ThrowNew(IAEClass, "mantissaOffset < 0");
148 goto exit;
149 }
150 _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset;
151 if (_mantissaRemaining < 16) {
152 _exception = 1;
153 _env->ThrowNew(IAEClass, "length - mantissaOffset < 16");
154 goto exit;
155 }
156 mantissa_base = (GLfixed *)
157 _env->GetPrimitiveArrayCritical(mantissa_ref, (jboolean *)0);
158 mantissa = mantissa_base + mantissaOffset;
159
160 if (!exponent_ref) {
161 _exception = 1;
162 _env->ThrowNew(IAEClass, "exponent == null");
163 goto exit;
164 }
165 if (exponentOffset < 0) {
166 _exception = 1;
167 _env->ThrowNew(IAEClass, "exponentOffset < 0");
168 goto exit;
169 }
170 _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset;
171 if (_exponentRemaining < 16) {
172 _exception = 1;
173 _env->ThrowNew(IAEClass, "length - exponentOffset < 16");
174 goto exit;
175 }
176 exponent_base = (GLint *)
177 _env->GetPrimitiveArrayCritical(exponent_ref, (jboolean *)0);
178 exponent = exponent_base + exponentOffset;
179
180 _returnValue = glQueryMatrixxOES(
181 (GLfixed *)mantissa,
182 (GLint *)exponent
183 );
184
185exit:
186 if (exponent_base) {
187 _env->ReleasePrimitiveArrayCritical(exponent_ref, exponent_base,
188 _exception ? JNI_ABORT: 0);
189 }
190 if (mantissa_base) {
191 _env->ReleasePrimitiveArrayCritical(mantissa_ref, mantissa_base,
192 _exception ? JNI_ABORT: 0);
193 }
194 return _returnValue;
195}
196
197/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
198static jint
199android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2
200 (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) {
201 jint _exception = 0;
202 jarray _mantissaArray = (jarray) 0;
203 jarray _exponentArray = (jarray) 0;
204 GLbitfield _returnValue = -1;
205 jint _mantissaRemaining;
206 GLfixed *mantissa = (GLfixed *) 0;
207 jint _exponentRemaining;
208 GLint *exponent = (GLint *) 0;
209
210 mantissa = (GLfixed *)getPointer(_env, mantissa_buf, &_mantissaArray, &_mantissaRemaining);
211 if (_mantissaRemaining < 16) {
212 _exception = 1;
213 _env->ThrowNew(IAEClass, "remaining() < 16");
214 goto exit;
215 }
216 exponent = (GLint *)getPointer(_env, exponent_buf, &_exponentArray, &_exponentRemaining);
217 if (_exponentRemaining < 16) {
218 _exception = 1;
219 _env->ThrowNew(IAEClass, "remaining() < 16");
220 goto exit;
221 }
222 _returnValue = glQueryMatrixxOES(
223 (GLfixed *)mantissa,
224 (GLint *)exponent
225 );
226
227exit:
228 if (_mantissaArray) {
229 releasePointer(_env, _mantissaArray, exponent, _exception ? JNI_FALSE : JNI_TRUE);
230 }
231 if (_exponentArray) {
232 releasePointer(_env, _exponentArray, mantissa, _exception ? JNI_FALSE : JNI_TRUE);
233 }
234 return _returnValue;
235}
236
237static const char *classPathName = "android/opengl/GLES10Ext";
238
239static JNINativeMethod methods[] = {
240{"_nativeClassInit", "()V", (void*)nativeClassInit },
241{"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II },
242{"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 },
243};
244
245int register_android_opengl_jni_GLES10Ext(JNIEnv *_env)
246{
247 int err;
248 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
249 return err;
250}