Home | History | Annotate | Download | only in gles11
      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 static int initialized = 0;
     29 
     30 static jclass nioAccessClass;
     31 static jclass bufferClass;
     32 static jmethodID getBasePointerID;
     33 static jmethodID getBaseArrayID;
     34 static jmethodID getBaseArrayOffsetID;
     35 static jfieldID positionID;
     36 static jfieldID limitID;
     37 static jfieldID elementSizeShiftID;
     38 
     39 /* Cache method IDs each time the class is loaded. */
     40 
     41 static void
     42 nativeClassInit(JNIEnv *_env, jclass glImplClass)
     43 {
     44     jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
     45     nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
     46 
     47     jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
     48     bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
     49 
     50     getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
     51             "getBasePointer", "(Ljava/nio/Buffer;)J");
     52     getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
     53             "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
     54     getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
     55             "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
     56 
     57     positionID = _env->GetFieldID(bufferClass, "position", "I");
     58     limitID = _env->GetFieldID(bufferClass, "limit", "I");
     59     elementSizeShiftID =
     60         _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
     61 }
     62 
     63 
     64 static void *
     65 getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining)
     66 {
     67     jint position;
     68     jint limit;
     69     jint elementSizeShift;
     70     jlong pointer;
     71     jint offset;
     72     void *data;
     73 
     74     position = _env->GetIntField(buffer, positionID);
     75     limit = _env->GetIntField(buffer, limitID);
     76     elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
     77     *remaining = (limit - position) << elementSizeShift;
     78     pointer = _env->CallStaticLongMethod(nioAccessClass,
     79             getBasePointerID, buffer);
     80     if (pointer != 0L) {
     81         *array = NULL;
     82         return (void *) (jint) pointer;
     83     }
     84 
     85     *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
     86             getBaseArrayID, buffer);
     87     offset = _env->CallStaticIntMethod(nioAccessClass,
     88             getBaseArrayOffsetID, buffer);
     89     data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0);
     90 
     91     return (void *) ((char *) data + offset);
     92 }
     93 
     94 
     95 static void
     96 releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
     97 {
     98     _env->ReleasePrimitiveArrayCritical(array, data,
     99 					   commit ? 0 : JNI_ABORT);
    100 }
    101 
    102 // --------------------------------------------------------------------------
    103