GLES11ExtcHeader.cpp revision 9875750593aae7c2a62f33c620809d49162393eb
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 "jni.h"
20#include "JNIHelp.h"
21#include <android_runtime/AndroidRuntime.h>
22#include <utils/misc.h>
23
24#include <assert.h>
25#include <GLES/gl.h>
26#include <GLES/glext.h>
27
28/* special calls implemented in Android's GLES wrapper used to more
29 * efficiently bound-check passed arrays */
30extern "C" {
31GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, GLsizei stride,
32        const GLvoid *ptr, GLsizei count);
33GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride,
34        const GLvoid *ptr, GLsizei count);
35}
36
37static int initialized = 0;
38
39static jclass nioAccessClass;
40static jclass bufferClass;
41static jmethodID getBasePointerID;
42static jmethodID getBaseArrayID;
43static jmethodID getBaseArrayOffsetID;
44static jfieldID positionID;
45static jfieldID limitID;
46static jfieldID elementSizeShiftID;
47
48/* Cache method IDs each time the class is loaded. */
49
50static void
51nativeClassInit(JNIEnv *_env, jclass glImplClass)
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
73static void *
74getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining)
75{
76    jint position;
77    jint limit;
78    jint elementSizeShift;
79    jlong pointer;
80    jint offset;
81    void *data;
82
83    position = _env->GetIntField(buffer, positionID);
84    limit = _env->GetIntField(buffer, limitID);
85    elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
86    *remaining = (limit - position) << elementSizeShift;
87    pointer = _env->CallStaticLongMethod(nioAccessClass,
88            getBasePointerID, buffer);
89    if (pointer != 0L) {
90        *array = NULL;
91        return (void *) (jint) pointer;
92    }
93
94    *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
95            getBaseArrayID, buffer);
96    offset = _env->CallStaticIntMethod(nioAccessClass,
97            getBaseArrayOffsetID, buffer);
98    data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0);
99
100    return (void *) ((char *) data + offset);
101}
102
103
104static void
105releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
106{
107    _env->ReleasePrimitiveArrayCritical(array, data,
108					   commit ? 0 : JNI_ABORT);
109}
110
111static void *
112getDirectBufferPointer(JNIEnv *_env, jobject buffer) {
113    char* buf = (char*) _env->GetDirectBufferAddress(buffer);
114    if (buf) {
115        jint position = _env->GetIntField(buffer, positionID);
116        jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
117        buf += position << elementSizeShift;
118    } else {
119        jniThrowException(_env, "java/lang/IllegalArgumentException",
120                          "Must use a native order direct Buffer");
121    }
122    return (void*) buf;
123}
124// --------------------------------------------------------------------------
125