blob: 16a884a239ca8349b433fe702b6622f0586f9389 [file] [log] [blame]
Jack Palevich27f80022009-04-15 19:13:17 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07005** 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
Jack Palevich27f80022009-04-15 19:13:17 -07008**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07009** http://www.apache.org/licenses/LICENSE-2.0
Jack Palevich27f80022009-04-15 19:13:17 -070010**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070011** 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
Jack Palevich27f80022009-04-15 19:13:17 -070015** limitations under the License.
16*/
17
18// This source file is automatically generated
19
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070020#include "jni.h"
21#include "JNIHelp.h"
Jack Palevich27f80022009-04-15 19:13:17 -070022#include <android_runtime/AndroidRuntime.h>
23#include <utils/misc.h>
24
25#include <assert.h>
26#include <GLES/gl.h>
Jack Palevichbe509c92009-05-07 09:52:14 -070027#include <GLES/glext.h>
Jack Palevich27f80022009-04-15 19:13:17 -070028
29static int initialized = 0;
30
31static jclass nioAccessClass;
32static jclass bufferClass;
Jack Palevich27f80022009-04-15 19:13:17 -070033static jmethodID getBasePointerID;
34static jmethodID getBaseArrayID;
35static jmethodID getBaseArrayOffsetID;
36static jfieldID positionID;
37static jfieldID limitID;
38static jfieldID elementSizeShiftID;
39
40/* Cache method IDs each time the class is loaded. */
41
42static void
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070043nativeClassInit(JNIEnv *_env, jclass glImplClass)
Jack Palevich27f80022009-04-15 19:13:17 -070044{
45 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
46 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
47
48 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
49 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
50
51 getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
52 "getBasePointer", "(Ljava/nio/Buffer;)J");
53 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
54 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
55 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
56 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
57
58 positionID = _env->GetFieldID(bufferClass, "position", "I");
59 limitID = _env->GetFieldID(bufferClass, "limit", "I");
60 elementSizeShiftID =
61 _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
62}
63
64
Jack Palevich27f80022009-04-15 19:13:17 -070065static void *
66getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining)
67{
68 jint position;
69 jint limit;
70 jint elementSizeShift;
71 jlong pointer;
72 jint offset;
73 void *data;
74
75 position = _env->GetIntField(buffer, positionID);
76 limit = _env->GetIntField(buffer, limitID);
77 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
78 *remaining = (limit - position) << elementSizeShift;
79 pointer = _env->CallStaticLongMethod(nioAccessClass,
80 getBasePointerID, buffer);
81 if (pointer != 0L) {
82 *array = NULL;
83 return (void *) (jint) pointer;
84 }
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070085
Jack Palevich27f80022009-04-15 19:13:17 -070086 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
87 getBaseArrayID, buffer);
88 offset = _env->CallStaticIntMethod(nioAccessClass,
89 getBaseArrayOffsetID, buffer);
90 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0);
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070091
Jack Palevich27f80022009-04-15 19:13:17 -070092 return (void *) ((char *) data + offset);
93}
94
95
96static void
97releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
98{
99 _env->ReleasePrimitiveArrayCritical(array, data,
100 commit ? 0 : JNI_ABORT);
101}
102
103// --------------------------------------------------------------------------
Jack Palevich27f80022009-04-15 19:13:17 -0700104/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
105static jint
106android_glQueryMatrixxOES___3II_3II
107 (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) {
108 jint _exception = 0;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700109 const char * _exceptionType;
110 const char * _exceptionMessage;
Jack Palevich27f80022009-04-15 19:13:17 -0700111 GLbitfield _returnValue = -1;
112 GLfixed *mantissa_base = (GLfixed *) 0;
113 jint _mantissaRemaining;
114 GLfixed *mantissa = (GLfixed *) 0;
115 GLint *exponent_base = (GLint *) 0;
116 jint _exponentRemaining;
117 GLint *exponent = (GLint *) 0;
118
119 if (!mantissa_ref) {
120 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700121 _exceptionType = "java/lang/IllegalArgumentException";
122 _exceptionMessage = "mantissa == null";
Jack Palevich27f80022009-04-15 19:13:17 -0700123 goto exit;
124 }
125 if (mantissaOffset < 0) {
126 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700127 _exceptionType = "java/lang/IllegalArgumentException";
128 _exceptionMessage = "mantissaOffset < 0";
Jack Palevich27f80022009-04-15 19:13:17 -0700129 goto exit;
130 }
131 _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset;
132 if (_mantissaRemaining < 16) {
133 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700134 _exceptionType = "java/lang/IllegalArgumentException";
135 _exceptionMessage = "length - mantissaOffset < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700136 goto exit;
137 }
138 mantissa_base = (GLfixed *)
139 _env->GetPrimitiveArrayCritical(mantissa_ref, (jboolean *)0);
140 mantissa = mantissa_base + mantissaOffset;
141
142 if (!exponent_ref) {
143 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700144 _exceptionType = "java/lang/IllegalArgumentException";
145 _exceptionMessage = "exponent == null";
Jack Palevich27f80022009-04-15 19:13:17 -0700146 goto exit;
147 }
148 if (exponentOffset < 0) {
149 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700150 _exceptionType = "java/lang/IllegalArgumentException";
151 _exceptionMessage = "exponentOffset < 0";
Jack Palevich27f80022009-04-15 19:13:17 -0700152 goto exit;
153 }
154 _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset;
155 if (_exponentRemaining < 16) {
156 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700157 _exceptionType = "java/lang/IllegalArgumentException";
158 _exceptionMessage = "length - exponentOffset < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700159 goto exit;
160 }
161 exponent_base = (GLint *)
162 _env->GetPrimitiveArrayCritical(exponent_ref, (jboolean *)0);
163 exponent = exponent_base + exponentOffset;
164
165 _returnValue = glQueryMatrixxOES(
166 (GLfixed *)mantissa,
167 (GLint *)exponent
168 );
169
170exit:
171 if (exponent_base) {
172 _env->ReleasePrimitiveArrayCritical(exponent_ref, exponent_base,
173 _exception ? JNI_ABORT: 0);
174 }
175 if (mantissa_base) {
176 _env->ReleasePrimitiveArrayCritical(mantissa_ref, mantissa_base,
177 _exception ? JNI_ABORT: 0);
178 }
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700179 if (_exception) {
180 jniThrowException(_env, _exceptionType, _exceptionMessage);
181 }
Jack Palevich27f80022009-04-15 19:13:17 -0700182 return _returnValue;
183}
184
185/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
186static jint
187android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2
188 (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) {
189 jint _exception = 0;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700190 const char * _exceptionType;
191 const char * _exceptionMessage;
Jack Palevich27f80022009-04-15 19:13:17 -0700192 jarray _mantissaArray = (jarray) 0;
193 jarray _exponentArray = (jarray) 0;
194 GLbitfield _returnValue = -1;
195 jint _mantissaRemaining;
196 GLfixed *mantissa = (GLfixed *) 0;
197 jint _exponentRemaining;
198 GLint *exponent = (GLint *) 0;
199
200 mantissa = (GLfixed *)getPointer(_env, mantissa_buf, &_mantissaArray, &_mantissaRemaining);
201 if (_mantissaRemaining < 16) {
202 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700203 _exceptionType = "java/lang/IllegalArgumentException";
204 _exceptionMessage = "remaining() < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700205 goto exit;
206 }
207 exponent = (GLint *)getPointer(_env, exponent_buf, &_exponentArray, &_exponentRemaining);
208 if (_exponentRemaining < 16) {
209 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700210 _exceptionType = "java/lang/IllegalArgumentException";
211 _exceptionMessage = "remaining() < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700212 goto exit;
213 }
214 _returnValue = glQueryMatrixxOES(
215 (GLfixed *)mantissa,
216 (GLint *)exponent
217 );
218
219exit:
220 if (_mantissaArray) {
221 releasePointer(_env, _mantissaArray, exponent, _exception ? JNI_FALSE : JNI_TRUE);
222 }
223 if (_exponentArray) {
224 releasePointer(_env, _exponentArray, mantissa, _exception ? JNI_FALSE : JNI_TRUE);
225 }
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700226 if (_exception) {
227 jniThrowException(_env, _exceptionType, _exceptionMessage);
228 }
Jack Palevich27f80022009-04-15 19:13:17 -0700229 return _returnValue;
230}
231
232static const char *classPathName = "android/opengl/GLES10Ext";
233
234static JNINativeMethod methods[] = {
235{"_nativeClassInit", "()V", (void*)nativeClassInit },
236{"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II },
237{"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 },
238};
239
240int register_android_opengl_jni_GLES10Ext(JNIEnv *_env)
241{
242 int err;
243 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
244 return err;
245}