blob: 6495686b2aad4a47ba6dcf1d7b5b352925228475 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001**
2** Copyright 2006, 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 <android_runtime/AndroidRuntime.h>
20#include <utils/misc.h>
21
22#include <assert.h>
23#include <GLES/gl.h>
24
25#include <private/opengles/gl_context.h>
26
27#define _NUM_COMPRESSED_TEXTURE_FORMATS \
28 (::android::OGLES_NUM_COMPRESSED_TEXTURE_FORMATS)
29
30static int initialized = 0;
31
32static jclass nioAccessClass;
33static jclass bufferClass;
34static jclass OOMEClass;
35static jclass UOEClass;
36static jclass IAEClass;
37static jclass AIOOBEClass;
38static jmethodID getBasePointerID;
39static jmethodID getBaseArrayID;
40static jmethodID getBaseArrayOffsetID;
41static jfieldID positionID;
42static jfieldID limitID;
43static jfieldID elementSizeShiftID;
44
45/* Cache method IDs each time the class is loaded. */
46
47void
48nativeClassInitBuffer(JNIEnv *_env)
49{
50 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
51 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
52
53 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
54 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
55
56 getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
57 "getBasePointer", "(Ljava/nio/Buffer;)J");
58 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
59 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
60 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
61 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
62
63 positionID = _env->GetFieldID(bufferClass, "position", "I");
64 limitID = _env->GetFieldID(bufferClass, "limit", "I");
65 elementSizeShiftID =
66 _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
67}
68
69
70static void
71nativeClassInit(JNIEnv *_env, jclass glImplClass)
72{
73 nativeClassInitBuffer(_env);
74
75 jclass IAEClassLocal =
76 _env->FindClass("java/lang/IllegalArgumentException");
77 jclass OOMEClassLocal =
78 _env->FindClass("java/lang/OutOfMemoryError");
79 jclass UOEClassLocal =
80 _env->FindClass("java/lang/UnsupportedOperationException");
81 jclass AIOOBEClassLocal =
82 _env->FindClass("java/lang/ArrayIndexOutOfBoundsException");
83
84 IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal);
85 OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal);
86 UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal);
87 AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal);
88}
89
90static void *
91getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining)
92{
93 jint position;
94 jint limit;
95 jint elementSizeShift;
96 jlong pointer;
97 jint offset;
98 void *data;
99
100 position = _env->GetIntField(buffer, positionID);
101 limit = _env->GetIntField(buffer, limitID);
102 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
103 *remaining = (limit - position) << elementSizeShift;
104 pointer = _env->CallStaticLongMethod(nioAccessClass,
105 getBasePointerID, buffer);
106 if (pointer != 0L) {
107 *array = NULL;
108 return (void *) (jint) pointer;
109 }
110
111 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
112 getBaseArrayID, buffer);
113 offset = _env->CallStaticIntMethod(nioAccessClass,
114 getBaseArrayOffsetID, buffer);
115 data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0);
116
117 return (void *) ((char *) data + offset);
118}
119
120
121static void
122releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
123{
124 _env->ReleasePrimitiveArrayCritical(array, data,
125 commit ? 0 : JNI_ABORT);
126}
127
128// --------------------------------------------------------------------------
129