blob: 823079f39f282eb82d3c77ebd4c9f0b6b463a15b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001**
Jack Palevich27f80022009-04-15 19:13:17 -07002** Copyright 2009, The Android Open Source Project
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07004** 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07008** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070010** 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080014** limitations under the License.
15*/
16
17// This source file is automatically generated
18
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070019#include "jni.h"
20#include "JNIHelp.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021#include <android_runtime/AndroidRuntime.h>
22#include <utils/misc.h>
23
24#include <assert.h>
25#include <GLES/gl.h>
Jack Palevichbe509c92009-05-07 09:52:14 -070026#include <GLES/glext.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Jack Palevichbe6eac82009-12-08 15:43:51 +080028/* special calls implemented in Android's GLES wrapper used to more
29 * efficiently bound-check passed arrays */
30extern "C" {
31GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, GLsizei stride,
32 const GLvoid *ptr, GLsizei count);
33}
34
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035static int initialized = 0;
36
37static jclass nioAccessClass;
38static jclass bufferClass;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039static jmethodID getBasePointerID;
40static jmethodID getBaseArrayID;
41static jmethodID getBaseArrayOffsetID;
42static jfieldID positionID;
43static jfieldID limitID;
44static jfieldID elementSizeShiftID;
45
46/* Cache method IDs each time the class is loaded. */
47
Jack Palevich27f80022009-04-15 19:13:17 -070048static void
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070049nativeClassInit(JNIEnv *_env, jclass glImplClass)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050{
51 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
52 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
53
54 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
55 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
56
57 getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
58 "getBasePointer", "(Ljava/nio/Buffer;)J");
59 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
60 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
61 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
62 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
63
64 positionID = _env->GetFieldID(bufferClass, "position", "I");
65 limitID = _env->GetFieldID(bufferClass, "limit", "I");
66 elementSizeShiftID =
67 _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
68}
69
70
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071static void *
72getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining)
73{
74 jint position;
75 jint limit;
76 jint elementSizeShift;
77 jlong pointer;
78 jint offset;
79 void *data;
80
81 position = _env->GetIntField(buffer, positionID);
82 limit = _env->GetIntField(buffer, limitID);
83 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
84 *remaining = (limit - position) << elementSizeShift;
85 pointer = _env->CallStaticLongMethod(nioAccessClass,
86 getBasePointerID, buffer);
87 if (pointer != 0L) {
88 *array = NULL;
89 return (void *) (jint) pointer;
90 }
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
93 getBaseArrayID, buffer);
94 offset = _env->CallStaticIntMethod(nioAccessClass,
95 getBaseArrayOffsetID, buffer);
96 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0);
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 return (void *) ((char *) data + offset);
99}
100
101
102static void
103releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
104{
105 _env->ReleasePrimitiveArrayCritical(array, data,
106 commit ? 0 : JNI_ABORT);
107}
108
Jack Palevichbe6eac82009-12-08 15:43:51 +0800109static void *
110getDirectBufferPointer(JNIEnv *_env, jobject buffer) {
111 char* buf = (char*) _env->GetDirectBufferAddress(buffer);
112 if (buf) {
113 jint position = _env->GetIntField(buffer, positionID);
114 jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
115 buf += position << elementSizeShift;
116 } else {
Elliott Hughes24ce5fb2011-04-08 20:01:01 -0700117 jniThrowException(_env, "java/lang/IllegalArgumentException",
118 "Must use a native order direct Buffer");
Jack Palevichbe6eac82009-12-08 15:43:51 +0800119 }
120 return (void*) buf;
121}
122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123// --------------------------------------------------------------------------