Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2009, The Android Open Source Project |
| 4 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 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 |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 8 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 10 | ** |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 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 |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | // This source file is automatically generated |
| 19 | |
Andreas Gampe | bfe6333 | 2014-11-12 14:12:45 -0800 | [diff] [blame] | 20 | #pragma GCC diagnostic ignored "-Wunused-variable" |
Andreas Gampe | bfe6333 | 2014-11-12 14:12:45 -0800 | [diff] [blame] | 21 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 22 | |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 23 | #include <GLES/gl.h> |
| 24 | #include <GLES/glext.h> |
| 25 | |
Jesse Hall | 9626f82 | 2014-05-19 20:57:49 -0700 | [diff] [blame] | 26 | #include <jni.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 27 | #include <nativehelper/JNIHelp.h> |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 28 | #include <android_runtime/AndroidRuntime.h> |
| 29 | #include <utils/misc.h> |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 30 | #include <assert.h> |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 31 | |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 32 | |
| 33 | /* special calls implemented in Android's GLES wrapper used to more |
| 34 | * efficiently bound-check passed arrays */ |
| 35 | extern "C" { |
| 36 | #ifdef GL_VERSION_ES_CM_1_1 |
| 37 | GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride, |
| 38 | const GLvoid *ptr, GLsizei count); |
| 39 | GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, |
| 40 | const GLvoid *pointer, GLsizei count); |
| 41 | GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, |
| 42 | GLsizei stride, const GLvoid *pointer, GLsizei count); |
| 43 | GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type, |
| 44 | GLsizei stride, const GLvoid *pointer, GLsizei count); |
| 45 | GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, |
| 46 | GLsizei stride, const GLvoid *pointer, GLsizei count); |
| 47 | GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, |
| 48 | GLsizei stride, const GLvoid *pointer, GLsizei count); |
| 49 | GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, |
| 50 | GLsizei stride, const GLvoid *pointer, GLsizei count); |
| 51 | #endif |
| 52 | #ifdef GL_ES_VERSION_2_0 |
| 53 | static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type, |
| 54 | GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) { |
| 55 | glVertexAttribPointer(indx, size, type, normalized, stride, pointer); |
| 56 | } |
| 57 | #endif |
Andy McFadden | cee5198 | 2013-04-25 16:08:31 -0700 | [diff] [blame] | 58 | #ifdef GL_ES_VERSION_3_0 |
| 59 | static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, |
| 60 | GLsizei stride, const GLvoid *pointer, GLsizei count) { |
| 61 | glVertexAttribIPointer(indx, size, type, stride, pointer); |
| 62 | } |
| 63 | #endif |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 66 | static void |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 67 | nativeClassInit(JNIEnv *_env, jclass glImplClass) |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 68 | { |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 71 | static void * |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 72 | getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 73 | { |
| 74 | jint position; |
| 75 | jint limit; |
| 76 | jint elementSizeShift; |
| 77 | jlong pointer; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 78 | |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 79 | pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 80 | *remaining = (limit - position) << elementSizeShift; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 81 | if (pointer != 0L) { |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 82 | *array = nullptr; |
| 83 | pointer += position << elementSizeShift; |
Ashok Bhat | 01c26ea | 2014-02-24 09:49:07 +0000 | [diff] [blame] | 84 | return reinterpret_cast<void*>(pointer); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 85 | } |
Elliott Hughes | 24ce5fb | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 86 | |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 87 | *array = jniGetNioBufferBaseArray(_env, buffer); |
| 88 | *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); |
| 89 | return nullptr; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 92 | class ByteArrayGetter { |
| 93 | public: |
| 94 | static void* Get(JNIEnv* _env, jbyteArray array, jboolean* is_copy) { |
| 95 | return _env->GetByteArrayElements(array, is_copy); |
| 96 | } |
| 97 | }; |
| 98 | class BooleanArrayGetter { |
| 99 | public: |
| 100 | static void* Get(JNIEnv* _env, jbooleanArray array, jboolean* is_copy) { |
| 101 | return _env->GetBooleanArrayElements(array, is_copy); |
| 102 | } |
| 103 | }; |
| 104 | class CharArrayGetter { |
| 105 | public: |
| 106 | static void* Get(JNIEnv* _env, jcharArray array, jboolean* is_copy) { |
| 107 | return _env->GetCharArrayElements(array, is_copy); |
| 108 | } |
| 109 | }; |
| 110 | class ShortArrayGetter { |
| 111 | public: |
| 112 | static void* Get(JNIEnv* _env, jshortArray array, jboolean* is_copy) { |
| 113 | return _env->GetShortArrayElements(array, is_copy); |
| 114 | } |
| 115 | }; |
| 116 | class IntArrayGetter { |
| 117 | public: |
| 118 | static void* Get(JNIEnv* _env, jintArray array, jboolean* is_copy) { |
| 119 | return _env->GetIntArrayElements(array, is_copy); |
| 120 | } |
| 121 | }; |
| 122 | class LongArrayGetter { |
| 123 | public: |
| 124 | static void* Get(JNIEnv* _env, jlongArray array, jboolean* is_copy) { |
| 125 | return _env->GetLongArrayElements(array, is_copy); |
| 126 | } |
| 127 | }; |
| 128 | class FloatArrayGetter { |
| 129 | public: |
| 130 | static void* Get(JNIEnv* _env, jfloatArray array, jboolean* is_copy) { |
| 131 | return _env->GetFloatArrayElements(array, is_copy); |
| 132 | } |
| 133 | }; |
| 134 | class DoubleArrayGetter { |
| 135 | public: |
| 136 | static void* Get(JNIEnv* _env, jdoubleArray array, jboolean* is_copy) { |
| 137 | return _env->GetDoubleArrayElements(array, is_copy); |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | template<typename JTYPEARRAY, typename ARRAYGETTER> |
| 142 | static void* |
| 143 | getArrayPointer(JNIEnv *_env, JTYPEARRAY array, jboolean* is_copy) { |
| 144 | return ARRAYGETTER::Get(_env, array, is_copy); |
| 145 | } |
| 146 | |
| 147 | class ByteArrayReleaser { |
| 148 | public: |
| 149 | static void Release(JNIEnv* _env, jbyteArray array, jbyte* data, jboolean commit) { |
| 150 | _env->ReleaseByteArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 151 | } |
| 152 | }; |
| 153 | class BooleanArrayReleaser { |
| 154 | public: |
| 155 | static void Release(JNIEnv* _env, jbooleanArray array, jboolean* data, jboolean commit) { |
| 156 | _env->ReleaseBooleanArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 157 | } |
| 158 | }; |
| 159 | class CharArrayReleaser { |
| 160 | public: |
| 161 | static void Release(JNIEnv* _env, jcharArray array, jchar* data, jboolean commit) { |
| 162 | _env->ReleaseCharArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 163 | } |
| 164 | }; |
| 165 | class ShortArrayReleaser { |
| 166 | public: |
| 167 | static void Release(JNIEnv* _env, jshortArray array, jshort* data, jboolean commit) { |
| 168 | _env->ReleaseShortArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 169 | } |
| 170 | }; |
| 171 | class IntArrayReleaser { |
| 172 | public: |
| 173 | static void Release(JNIEnv* _env, jintArray array, jint* data, jboolean commit) { |
| 174 | _env->ReleaseIntArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 175 | } |
| 176 | }; |
| 177 | class LongArrayReleaser { |
| 178 | public: |
| 179 | static void Release(JNIEnv* _env, jlongArray array, jlong* data, jboolean commit) { |
| 180 | _env->ReleaseLongArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 181 | } |
| 182 | }; |
| 183 | class FloatArrayReleaser { |
| 184 | public: |
| 185 | static void Release(JNIEnv* _env, jfloatArray array, jfloat* data, jboolean commit) { |
| 186 | _env->ReleaseFloatArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 187 | } |
| 188 | }; |
| 189 | class DoubleArrayReleaser { |
| 190 | public: |
| 191 | static void Release(JNIEnv* _env, jdoubleArray array, jdouble* data, jboolean commit) { |
| 192 | _env->ReleaseDoubleArrayElements(array, data, commit ? 0 : JNI_ABORT); |
| 193 | } |
| 194 | }; |
| 195 | |
| 196 | template<typename JTYPEARRAY, typename NTYPEARRAY, typename ARRAYRELEASER> |
| 197 | static void |
| 198 | releaseArrayPointer(JNIEnv *_env, JTYPEARRAY array, NTYPEARRAY data, jboolean commit) { |
| 199 | ARRAYRELEASER::Release(_env, array, data, commit); |
| 200 | } |
| 201 | |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 202 | static void |
| 203 | releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) |
| 204 | { |
| 205 | _env->ReleasePrimitiveArrayCritical(array, data, |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 206 | commit ? 0 : JNI_ABORT); |
| 207 | } |
| 208 | |
| 209 | static void * |
| 210 | getDirectBufferPointer(JNIEnv *_env, jobject buffer) { |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 211 | jint position; |
| 212 | jint limit; |
| 213 | jint elementSizeShift; |
| 214 | jlong pointer; |
| 215 | pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); |
| 216 | if (pointer == 0) { |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 217 | jniThrowException(_env, "java/lang/IllegalArgumentException", |
| 218 | "Must use a native order direct Buffer"); |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 219 | return nullptr; |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 220 | } |
Orion Hodson | 02440d3 | 2019-02-28 15:15:34 +0000 | [diff] [blame] | 221 | pointer += position << elementSizeShift; |
| 222 | return reinterpret_cast<void*>(pointer); |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | // -------------------------------------------------------------------------- |
| 226 | |
| 227 | /* |
| 228 | * returns the number of values glGet returns for a given pname. |
| 229 | * |
| 230 | * The code below is written such that pnames requiring only one values |
| 231 | * are the default (and are not explicitely tested for). This makes the |
| 232 | * checking code much shorter/readable/efficient. |
| 233 | * |
| 234 | * This means that unknown pnames (e.g.: extensions) will default to 1. If |
| 235 | * that unknown pname needs more than 1 value, then the validation check |
| 236 | * is incomplete and the app may crash if it passed the wrong number params. |
| 237 | */ |
| 238 | static int getNeededCount(GLint pname) { |
| 239 | int needed = 1; |
Romain Guy | dc43a6c | 2017-02-17 19:54:25 -0800 | [diff] [blame] | 240 | #ifdef GL_ES_VERSION_3_0 |
| 241 | // GLES 3.x pnames |
| 242 | switch (pname) { |
| 243 | case GL_MAX_VIEWPORT_DIMS: |
| 244 | needed = 2; |
| 245 | break; |
| 246 | |
| 247 | case GL_PROGRAM_BINARY_FORMATS: |
| 248 | glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &needed); |
| 249 | break; |
| 250 | } |
| 251 | #endif |
| 252 | |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 253 | #ifdef GL_ES_VERSION_2_0 |
| 254 | // GLES 2.x pnames |
| 255 | switch (pname) { |
| 256 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 257 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 258 | needed = 2; |
| 259 | break; |
| 260 | |
| 261 | case GL_BLEND_COLOR: |
| 262 | case GL_COLOR_CLEAR_VALUE: |
| 263 | case GL_COLOR_WRITEMASK: |
| 264 | case GL_SCISSOR_BOX: |
| 265 | case GL_VIEWPORT: |
| 266 | needed = 4; |
| 267 | break; |
| 268 | |
| 269 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 270 | glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed); |
| 271 | break; |
| 272 | |
| 273 | case GL_SHADER_BINARY_FORMATS: |
| 274 | glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &needed); |
| 275 | break; |
| 276 | } |
| 277 | #endif |
| 278 | |
| 279 | #ifdef GL_VERSION_ES_CM_1_1 |
| 280 | // GLES 1.x pnames |
| 281 | switch (pname) { |
| 282 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 283 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 284 | case GL_DEPTH_RANGE: |
| 285 | case GL_SMOOTH_LINE_WIDTH_RANGE: |
| 286 | case GL_SMOOTH_POINT_SIZE_RANGE: |
| 287 | needed = 2; |
| 288 | break; |
| 289 | |
| 290 | case GL_CURRENT_NORMAL: |
| 291 | case GL_POINT_DISTANCE_ATTENUATION: |
| 292 | needed = 3; |
| 293 | break; |
| 294 | |
| 295 | case GL_COLOR_CLEAR_VALUE: |
| 296 | case GL_COLOR_WRITEMASK: |
| 297 | case GL_CURRENT_COLOR: |
| 298 | case GL_CURRENT_TEXTURE_COORDS: |
| 299 | case GL_FOG_COLOR: |
| 300 | case GL_LIGHT_MODEL_AMBIENT: |
| 301 | case GL_SCISSOR_BOX: |
| 302 | case GL_VIEWPORT: |
| 303 | needed = 4; |
| 304 | break; |
| 305 | |
| 306 | case GL_MODELVIEW_MATRIX: |
| 307 | case GL_PROJECTION_MATRIX: |
| 308 | case GL_TEXTURE_MATRIX: |
| 309 | needed = 16; |
| 310 | break; |
| 311 | |
| 312 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 313 | glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed); |
| 314 | break; |
| 315 | } |
| 316 | #endif |
| 317 | return needed; |
| 318 | } |
| 319 | |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 320 | template <typename JTYPEARRAY, typename ARRAYGETTER, typename NTYPEARRAY, |
| 321 | typename ARRAYRELEASER, typename CTYPE, void GET(GLenum, CTYPE*)> |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 322 | static void |
| 323 | get |
| 324 | (JNIEnv *_env, jobject _this, jint pname, JTYPEARRAY params_ref, jint offset) { |
| 325 | jint _exception = 0; |
| 326 | const char * _exceptionType; |
| 327 | const char * _exceptionMessage; |
| 328 | CTYPE *params_base = (CTYPE *) 0; |
| 329 | jint _remaining; |
| 330 | CTYPE *params = (CTYPE *) 0; |
| 331 | int _needed = 0; |
| 332 | |
| 333 | if (!params_ref) { |
| 334 | _exception = 1; |
| 335 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 336 | _exceptionMessage = "params == null"; |
| 337 | goto exit; |
| 338 | } |
| 339 | if (offset < 0) { |
| 340 | _exception = 1; |
| 341 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 342 | _exceptionMessage = "offset < 0"; |
| 343 | goto exit; |
| 344 | } |
| 345 | _remaining = _env->GetArrayLength(params_ref) - offset; |
| 346 | _needed = getNeededCount(pname); |
| 347 | // if we didn't find this pname, we just assume the user passed |
| 348 | // an array of the right size -- this might happen with extensions |
| 349 | // or if we forget an enum here. |
| 350 | if (_remaining < _needed) { |
| 351 | _exception = 1; |
| 352 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 353 | _exceptionMessage = "length - offset < needed"; |
| 354 | goto exit; |
| 355 | } |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 356 | params_base = (CTYPE *) getArrayPointer<JTYPEARRAY, ARRAYGETTER>( |
| 357 | _env, params_ref, (jboolean *)0); |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 358 | params = params_base + offset; |
| 359 | |
| 360 | GET( |
| 361 | (GLenum)pname, |
| 362 | (CTYPE *)params |
| 363 | ); |
| 364 | |
| 365 | exit: |
| 366 | if (params_base) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 367 | releaseArrayPointer<JTYPEARRAY, NTYPEARRAY, ARRAYRELEASER>( |
| 368 | _env, params_ref, params_base, !_exception); |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 369 | } |
| 370 | if (_exception) { |
| 371 | jniThrowException(_env, _exceptionType, _exceptionMessage); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 376 | template <typename CTYPE, typename JTYPEARRAY, typename ARRAYGETTER, typename NTYPEARRAY, |
| 377 | typename ARRAYRELEASER, void GET(GLenum, CTYPE*)> |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 378 | static void |
| 379 | getarray |
| 380 | (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) { |
| 381 | jint _exception = 0; |
| 382 | const char * _exceptionType; |
| 383 | const char * _exceptionMessage; |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 384 | JTYPEARRAY _array = (JTYPEARRAY) 0; |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 385 | jint _bufferOffset = (jint) 0; |
| 386 | jint _remaining; |
| 387 | CTYPE *params = (CTYPE *) 0; |
| 388 | int _needed = 0; |
| 389 | |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 390 | params = (CTYPE *)getPointer(_env, params_buf, (jarray*)&_array, &_remaining, &_bufferOffset); |
Andy McFadden | cee5198 | 2013-04-25 16:08:31 -0700 | [diff] [blame] | 391 | _remaining /= sizeof(CTYPE); // convert from bytes to item count |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 392 | _needed = getNeededCount(pname); |
| 393 | // if we didn't find this pname, we just assume the user passed |
| 394 | // an array of the right size -- this might happen with extensions |
| 395 | // or if we forget an enum here. |
| 396 | if (_needed>0 && _remaining < _needed) { |
| 397 | _exception = 1; |
| 398 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 399 | _exceptionMessage = "remaining() < needed"; |
| 400 | goto exit; |
| 401 | } |
| 402 | if (params == NULL) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 403 | char * _paramsBase = (char *) getArrayPointer<JTYPEARRAY, ARRAYGETTER>( |
| 404 | _env, _array, (jboolean *) 0); |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 405 | params = (CTYPE *) (_paramsBase + _bufferOffset); |
| 406 | } |
| 407 | GET( |
| 408 | (GLenum)pname, |
| 409 | (CTYPE *)params |
| 410 | ); |
| 411 | |
| 412 | exit: |
| 413 | if (_array) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 414 | releaseArrayPointer<JTYPEARRAY, NTYPEARRAY, ARRAYRELEASER>( |
| 415 | _env, _array, (NTYPEARRAY)params, _exception ? JNI_FALSE : JNI_TRUE); |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 416 | } |
| 417 | if (_exception) { |
| 418 | jniThrowException(_env, _exceptionType, _exceptionMessage); |
| 419 | } |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | // -------------------------------------------------------------------------- |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 423 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 424 | static jint |
| 425 | android_glQueryMatrixxOES___3II_3II |
| 426 | (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) { |
| 427 | jint _exception = 0; |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 428 | const char * _exceptionType = NULL; |
| 429 | const char * _exceptionMessage = NULL; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 430 | GLbitfield _returnValue = -1; |
| 431 | GLfixed *mantissa_base = (GLfixed *) 0; |
| 432 | jint _mantissaRemaining; |
| 433 | GLfixed *mantissa = (GLfixed *) 0; |
| 434 | GLint *exponent_base = (GLint *) 0; |
| 435 | jint _exponentRemaining; |
| 436 | GLint *exponent = (GLint *) 0; |
| 437 | |
| 438 | if (!mantissa_ref) { |
| 439 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 440 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 441 | _exceptionMessage = "mantissa == null"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 442 | goto exit; |
| 443 | } |
| 444 | if (mantissaOffset < 0) { |
| 445 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 446 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 447 | _exceptionMessage = "mantissaOffset < 0"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 448 | goto exit; |
| 449 | } |
| 450 | _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset; |
| 451 | if (_mantissaRemaining < 16) { |
| 452 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 453 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 454 | _exceptionMessage = "length - mantissaOffset < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 455 | goto exit; |
| 456 | } |
| 457 | mantissa_base = (GLfixed *) |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 458 | _env->GetIntArrayElements(mantissa_ref, (jboolean *)0); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 459 | mantissa = mantissa_base + mantissaOffset; |
| 460 | |
| 461 | if (!exponent_ref) { |
| 462 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 463 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 464 | _exceptionMessage = "exponent == null"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 465 | goto exit; |
| 466 | } |
| 467 | if (exponentOffset < 0) { |
| 468 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 469 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 470 | _exceptionMessage = "exponentOffset < 0"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 471 | goto exit; |
| 472 | } |
| 473 | _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset; |
| 474 | if (_exponentRemaining < 16) { |
| 475 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 476 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 477 | _exceptionMessage = "length - exponentOffset < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 478 | goto exit; |
| 479 | } |
| 480 | exponent_base = (GLint *) |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 481 | _env->GetIntArrayElements(exponent_ref, (jboolean *)0); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 482 | exponent = exponent_base + exponentOffset; |
| 483 | |
| 484 | _returnValue = glQueryMatrixxOES( |
| 485 | (GLfixed *)mantissa, |
| 486 | (GLint *)exponent |
| 487 | ); |
| 488 | |
| 489 | exit: |
| 490 | if (exponent_base) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 491 | _env->ReleaseIntArrayElements(exponent_ref, (jint*)exponent_base, |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 492 | _exception ? JNI_ABORT: 0); |
| 493 | } |
| 494 | if (mantissa_base) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 495 | _env->ReleaseIntArrayElements(mantissa_ref, (jint*)mantissa_base, |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 496 | _exception ? JNI_ABORT: 0); |
| 497 | } |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 498 | if (_exception) { |
| 499 | jniThrowException(_env, _exceptionType, _exceptionMessage); |
Orion Hodson | c240f22 | 2019-02-26 18:05:03 +0000 | [diff] [blame] | 500 | return (jint)0; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 501 | } |
Andy McFadden | cee5198 | 2013-04-25 16:08:31 -0700 | [diff] [blame] | 502 | return (jint)_returnValue; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ |
| 506 | static jint |
| 507 | android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 |
| 508 | (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) { |
| 509 | jint _exception = 0; |
Mathias Agopian | 2ad0477 | 2013-02-23 03:12:30 -0800 | [diff] [blame] | 510 | const char * _exceptionType = NULL; |
| 511 | const char * _exceptionMessage = NULL; |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 512 | jintArray _mantissaArray = (jintArray) 0; |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 513 | jint _mantissaBufferOffset = (jint) 0; |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 514 | jintArray _exponentArray = (jintArray) 0; |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 515 | jint _exponentBufferOffset = (jint) 0; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 516 | GLbitfield _returnValue = -1; |
| 517 | jint _mantissaRemaining; |
| 518 | GLfixed *mantissa = (GLfixed *) 0; |
| 519 | jint _exponentRemaining; |
| 520 | GLint *exponent = (GLint *) 0; |
| 521 | |
Romain Guy | 84cac20 | 2016-12-05 12:26:02 -0800 | [diff] [blame] | 522 | if (!mantissa_buf) { |
| 523 | _exception = 1; |
| 524 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 525 | _exceptionMessage = "mantissa == null"; |
| 526 | goto exit; |
| 527 | } |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 528 | mantissa = (GLfixed *)getPointer(_env, mantissa_buf, (jarray*)&_mantissaArray, &_mantissaRemaining, &_mantissaBufferOffset); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 529 | if (_mantissaRemaining < 16) { |
| 530 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 531 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 532 | _exceptionMessage = "remaining() < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 533 | goto exit; |
| 534 | } |
Romain Guy | 84cac20 | 2016-12-05 12:26:02 -0800 | [diff] [blame] | 535 | if (!exponent_buf) { |
| 536 | _exception = 1; |
| 537 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 538 | _exceptionMessage = "exponent == null"; |
| 539 | goto exit; |
| 540 | } |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 541 | exponent = (GLint *)getPointer(_env, exponent_buf, (jarray*)&_exponentArray, &_exponentRemaining, &_exponentBufferOffset); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 542 | if (_exponentRemaining < 16) { |
| 543 | _exception = 1; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 544 | _exceptionType = "java/lang/IllegalArgumentException"; |
| 545 | _exceptionMessage = "remaining() < 16 < needed"; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 546 | goto exit; |
| 547 | } |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 548 | if (mantissa == NULL) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 549 | char * _mantissaBase = (char *)_env->GetIntArrayElements(_mantissaArray, (jboolean *) 0); |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 550 | mantissa = (GLfixed *) (_mantissaBase + _mantissaBufferOffset); |
| 551 | } |
| 552 | if (exponent == NULL) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 553 | char * _exponentBase = (char *)_env->GetIntArrayElements(_exponentArray, (jboolean *) 0); |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 554 | exponent = (GLint *) (_exponentBase + _exponentBufferOffset); |
| 555 | } |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 556 | _returnValue = glQueryMatrixxOES( |
| 557 | (GLfixed *)mantissa, |
| 558 | (GLint *)exponent |
| 559 | ); |
| 560 | |
| 561 | exit: |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 562 | if (_exponentArray) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 563 | _env->ReleaseIntArrayElements(_exponentArray, (jint*)exponent, _exception ? JNI_ABORT : 0); |
Thomas Tafertshofer | 17045a1 | 2012-07-12 13:55:55 -0700 | [diff] [blame] | 564 | } |
| 565 | if (_mantissaArray) { |
Hiroshi Yamauchi | 3b1d46e | 2015-05-13 13:10:33 -0700 | [diff] [blame] | 566 | _env->ReleaseIntArrayElements(_mantissaArray, (jint*)mantissa, _exception ? JNI_ABORT : 0); |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 567 | } |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 568 | if (_exception) { |
| 569 | jniThrowException(_env, _exceptionType, _exceptionMessage); |
Orion Hodson | c240f22 | 2019-02-26 18:05:03 +0000 | [diff] [blame] | 570 | return (jint)0; |
Thomas Tafertshofer | 2545b32 | 2012-06-27 16:33:26 -0700 | [diff] [blame] | 571 | } |
Andy McFadden | cee5198 | 2013-04-25 16:08:31 -0700 | [diff] [blame] | 572 | return (jint)_returnValue; |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | static const char *classPathName = "android/opengl/GLES10Ext"; |
| 576 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 577 | static const JNINativeMethod methods[] = { |
Jack Palevich | 27f8002 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 578 | {"_nativeClassInit", "()V", (void*)nativeClassInit }, |
| 579 | {"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II }, |
| 580 | {"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 }, |
| 581 | }; |
| 582 | |
| 583 | int register_android_opengl_jni_GLES10Ext(JNIEnv *_env) |
| 584 | { |
| 585 | int err; |
| 586 | err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods)); |
| 587 | return err; |
| 588 | } |