diff options
| -rw-r--r-- | core/jni/AndroidRuntime.cpp | 2 | ||||
| -rw-r--r-- | core/jni/android/opengl/util.cpp | 45 | ||||
| -rw-r--r-- | core/jni/android_nio_utils.cpp | 56 | ||||
| -rw-r--r-- | core/jni/android_opengl_EGL15.cpp | 46 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES10.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES10Ext.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES11.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES11Ext.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES20.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES30.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES31.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES31Ext.cpp | 62 | ||||
| -rw-r--r-- | core/jni/android_opengl_GLES32.cpp | 62 | ||||
| -rw-r--r-- | core/jni/com_google_android_gles_jni_GLImpl.cpp | 101 |
14 files changed, 177 insertions, 631 deletions
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 967abce60cd3..b6ee0fe782a6 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -174,7 +174,6 @@ extern int register_android_database_CursorWindow(JNIEnv* env); extern int register_android_database_SQLiteConnection(JNIEnv* env); extern int register_android_database_SQLiteGlobal(JNIEnv* env); extern int register_android_database_SQLiteDebug(JNIEnv* env); -extern int register_android_nio_utils(JNIEnv* env); extern int register_android_os_Debug(JNIEnv* env); extern int register_android_os_GraphicsEnvironment(JNIEnv* env); extern int register_android_os_HidlSupport(JNIEnv* env); @@ -1422,7 +1421,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_os_NativeHandle), REG_JNI(register_android_os_VintfObject), REG_JNI(register_android_os_VintfRuntimeInfo), - REG_JNI(register_android_nio_utils), REG_JNI(register_android_graphics_Canvas), // This needs to be before register_android_graphics_Graphics, or the latter // will not be able to find the jmethodID for ColorSpace.get(). diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index 09f0e8e232bf..55abc932cff2 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -773,54 +773,18 @@ static jint util_texSubImage2D(JNIEnv *env, jclass clazz, * ETC1 methods. */ -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - -/* Cache method IDs each time the class is loaded. */ - -static void -nativeClassInitBuffer(JNIEnv *env) -{ - jclass nioAccessClassLocal = FindClassOrDie(env, "java/nio/NIOAccess"); - nioAccessClass = MakeGlobalRefOrDie(env, nioAccessClassLocal); - getBasePointerID = GetStaticMethodIDOrDie(env, nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = GetStaticMethodIDOrDie(env, nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = GetStaticMethodIDOrDie(env, nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - jclass bufferClassLocal = FindClassOrDie(env, "java/nio/Buffer"); - bufferClass = MakeGlobalRefOrDie(env, bufferClassLocal); - positionID = GetFieldIDOrDie(env, bufferClass, "position", "I"); - limitID = GetFieldIDOrDie(env, bufferClass, "limit", "I"); - elementSizeShiftID = GetFieldIDOrDie(env, bufferClass, "_elementSizeShift", "I"); -} - static void * getPointer(JNIEnv *_env, jobject buffer, jint *remaining) { jint position; jint limit; jint elementSizeShift; - jlong pointer; - - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); + jlong pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); if (pointer != 0L) { - return reinterpret_cast<void *>(pointer); + pointer += position << elementSizeShift; } - return NULL; + *remaining = (limit - position) << elementSizeShift; + return reinterpret_cast<void*>(pointer); } class BufferHelper { @@ -1101,7 +1065,6 @@ static const ClassRegistrationInfo gClasses[] = { int register_android_opengl_classes(JNIEnv* env) { - nativeClassInitBuffer(env); int result = 0; for (int i = 0; i < NELEM(gClasses); i++) { const ClassRegistrationInfo* cri = &gClasses[i]; diff --git a/core/jni/android_nio_utils.cpp b/core/jni/android_nio_utils.cpp index ed8c6038f69d..19a1c7212fae 100644 --- a/core/jni/android_nio_utils.cpp +++ b/core/jni/android_nio_utils.cpp @@ -18,37 +18,22 @@ #include "core_jni_helpers.h" -struct NioJNIData { - jclass nioAccessClass; - - jmethodID getBasePointerID; - jmethodID getBaseArrayID; - jmethodID getBaseArrayOffsetID; -}; - -static NioJNIData gNioJNI; - void* android::nio_getPointer(JNIEnv *_env, jobject buffer, jarray *array) { assert(array); - jlong pointer; - jint offset; - void *data; - - pointer = _env->CallStaticLongMethod(gNioJNI.nioAccessClass, - gNioJNI.getBasePointerID, buffer); + jint position; + jint limit; + jint elementSizeShift; + jlong pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); if (pointer != 0L) { - *array = NULL; - return reinterpret_cast<void *>(pointer); + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(gNioJNI.nioAccessClass, - gNioJNI.getBaseArrayID, buffer); - offset = _env->CallStaticIntMethod(gNioJNI.nioAccessClass, - gNioJNI.getBaseArrayOffsetID, buffer); - data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - - return (void *) ((char *) data + offset); + jint offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + *array = jniGetNioBufferBaseArray(_env, buffer); + void * data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); + return reinterpret_cast<void*>(reinterpret_cast<char*>(data) + offset); } @@ -72,24 +57,3 @@ android::AutoBufferPointer::~AutoBufferPointer() { android::nio_releasePointer(fEnv, fArray, fPointer, fCommit); } } - -/////////////////////////////////////////////////////////////////////////////// - -namespace android { - -int register_android_nio_utils(JNIEnv* env) { - jclass localClass = FindClassOrDie(env, "java/nio/NIOAccess"); - gNioJNI.getBasePointerID = GetStaticMethodIDOrDie(env, localClass, "getBasePointer", - "(Ljava/nio/Buffer;)J"); - gNioJNI.getBaseArrayID = GetStaticMethodIDOrDie(env, localClass, "getBaseArray", - "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - gNioJNI.getBaseArrayOffsetID = GetStaticMethodIDOrDie(env, localClass, "getBaseArrayOffset", - "(Ljava/nio/Buffer;)I"); - - // now record a permanent version of the class ID - gNioJNI.nioAccessClass = MakeGlobalRefOrDie(env, localClass); - - return 0; -} - -} diff --git a/core/jni/android_opengl_EGL15.cpp b/core/jni/android_opengl_EGL15.cpp index 717b50579325..4aeed8765165 100644 --- a/core/jni/android_opengl_EGL15.cpp +++ b/core/jni/android_opengl_EGL15.cpp @@ -35,16 +35,6 @@ static jclass egldisplayClass; static jclass eglsurfaceClass; static jclass eglconfigClass; static jclass eglcontextClass; -static jclass bufferClass; -static jclass nioAccessClass; - -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; static jmethodID egldisplayGetHandleID; static jmethodID eglconfigGetHandleID; @@ -116,24 +106,6 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject); // EGL 1.5 init - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); - jclass eglimageClassLocal = _env->FindClass("android/opengl/EGLImage"); eglimageClass = (jclass) _env->NewGlobalRef(eglimageClassLocal); jclass eglsyncClassLocal = _env->FindClass("android/opengl/EGLSync"); @@ -160,23 +132,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } static void diff --git a/core/jni/android_opengl_GLES10.cpp b/core/jni/android_opengl_GLES10.cpp index a4ab5db8c8d7..3d9a3b6687b1 100644 --- a/core/jni/android_opengl_GLES10.cpp +++ b/core/jni/android_opengl_GLES10.cpp @@ -29,15 +29,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -72,28 +63,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -104,23 +76,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -242,16 +208,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES10Ext.cpp b/core/jni/android_opengl_GLES10Ext.cpp index a5dcbf765b60..6d7f41e5b3b2 100644 --- a/core/jni/android_opengl_GLES10Ext.cpp +++ b/core/jni/android_opengl_GLES10Ext.cpp @@ -29,15 +29,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -72,28 +63,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -104,23 +76,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -242,16 +208,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES11.cpp b/core/jni/android_opengl_GLES11.cpp index be86a037bfbd..39ef41a0e19e 100644 --- a/core/jni/android_opengl_GLES11.cpp +++ b/core/jni/android_opengl_GLES11.cpp @@ -29,15 +29,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -72,28 +63,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -104,23 +76,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -242,16 +208,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES11Ext.cpp b/core/jni/android_opengl_GLES11Ext.cpp index d28d9a387b5e..1144d5bfb4e6 100644 --- a/core/jni/android_opengl_GLES11Ext.cpp +++ b/core/jni/android_opengl_GLES11Ext.cpp @@ -29,15 +29,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -72,28 +63,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -104,23 +76,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -242,16 +208,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES20.cpp b/core/jni/android_opengl_GLES20.cpp index 0e20d474e275..2add72d14c7b 100644 --- a/core/jni/android_opengl_GLES20.cpp +++ b/core/jni/android_opengl_GLES20.cpp @@ -29,15 +29,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -72,28 +63,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -104,23 +76,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -242,16 +208,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES30.cpp b/core/jni/android_opengl_GLES30.cpp index 992239865db7..a9c021951758 100644 --- a/core/jni/android_opengl_GLES30.cpp +++ b/core/jni/android_opengl_GLES30.cpp @@ -29,15 +29,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -72,28 +63,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -104,23 +76,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -242,16 +208,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES31.cpp b/core/jni/android_opengl_GLES31.cpp index 27dbd399d77c..456da93784d5 100644 --- a/core/jni/android_opengl_GLES31.cpp +++ b/core/jni/android_opengl_GLES31.cpp @@ -27,15 +27,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -70,28 +61,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -102,23 +74,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -240,16 +206,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES31Ext.cpp b/core/jni/android_opengl_GLES31Ext.cpp index 5b671c8e55fb..dcaf4a58cd53 100644 --- a/core/jni/android_opengl_GLES31Ext.cpp +++ b/core/jni/android_opengl_GLES31Ext.cpp @@ -28,15 +28,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -71,28 +62,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -103,23 +75,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -241,16 +207,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES32.cpp b/core/jni/android_opengl_GLES32.cpp index d59d25c2c483..6bdc711d64a2 100644 --- a/core/jni/android_opengl_GLES32.cpp +++ b/core/jni/android_opengl_GLES32.cpp @@ -27,15 +27,6 @@ #include <utils/misc.h> #include <assert.h> -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - /* special calls implemented in Android's GLES wrapper used to more * efficiently bound-check passed arrays */ @@ -70,28 +61,9 @@ static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type, #endif } -/* Cache method IDs each time the class is loaded. */ - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -102,23 +74,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *array = NULL; + *array = nullptr; + pointer += position << elementSizeShift; return reinterpret_cast<void*>(pointer); } - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } class ByteArrayGetter { @@ -240,16 +206,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - char* buf = (char*) _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf += position << elementSizeShift; - } else { + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); + return nullptr; } - return (void*) buf; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } // -------------------------------------------------------------------------- diff --git a/core/jni/com_google_android_gles_jni_GLImpl.cpp b/core/jni/com_google_android_gles_jni_GLImpl.cpp index c806162c2534..6b893cb94444 100644 --- a/core/jni/com_google_android_gles_jni_GLImpl.cpp +++ b/core/jni/com_google_android_gles_jni_GLImpl.cpp @@ -65,16 +65,7 @@ GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count); } -static jclass nioAccessClass; -static jclass bufferClass; static jclass G11ImplClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jmethodID allowIndirectBuffersID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; static jfieldID haveCheckedExtensionsID; static jfieldID have_OES_blend_equation_separateID; static jfieldID have_OES_blend_subtractID; @@ -86,12 +77,6 @@ static jfieldID have_OES_texture_cube_mapID; static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - jclass g11impClassLocal = _env->FindClass("com/google/android/gles_jni/GLImpl"); G11ImplClass = (jclass) _env->NewGlobalRef(g11impClassLocal); haveCheckedExtensionsID = _env->GetFieldID(G11ImplClass, "haveCheckedExtensions", "Z"); @@ -99,19 +84,6 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) have_OES_blend_subtractID = _env->GetFieldID(G11ImplClass, "have_OES_blend_subtract", "Z"); have_OES_framebuffer_objectID = _env->GetFieldID(G11ImplClass, "have_OES_framebuffer_object", "Z"); have_OES_texture_cube_mapID = _env->GetFieldID(G11ImplClass, "have_OES_texture_cube_map", "Z"); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - allowIndirectBuffersID = _env->GetStaticMethodID(g11impClassLocal, - "allowIndirectBuffers", "(Ljava/lang/String;)Z"); - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } static void * @@ -122,28 +94,17 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o jint elementSizeShift; jlong pointer; - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); if (pointer != 0L) { - *offset = 0; - *array = NULL; - return reinterpret_cast<void *>(pointer); - } - - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - if (*array == NULL) { - *offset = 0; - return (void*) NULL; + *array = nullptr; + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - return NULL; + *array = jniGetNioBufferBaseArray(_env, buffer); + *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); + return nullptr; } static void @@ -157,42 +118,24 @@ extern "C" { extern char* __progname; } -static bool -allowIndirectBuffers(JNIEnv *_env) { - static jint sIndirectBufferCompatability; - if (sIndirectBufferCompatability == 0) { - jobject appName = _env->NewStringUTF(::__progname); - sIndirectBufferCompatability = _env->CallStaticBooleanMethod(G11ImplClass, allowIndirectBuffersID, appName) ? 2 : 1; - } - return sIndirectBufferCompatability == 2; -} - static void * getDirectBufferPointer(JNIEnv *_env, jobject buffer) { - if (!buffer) { - return NULL; - } - void* buf = _env->GetDirectBufferAddress(buffer); - if (buf) { - jint position = _env->GetIntField(buffer, positionID); - jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - buf = ((char*) buf) + (position << elementSizeShift); - } else { - if (allowIndirectBuffers(_env)) { - jarray array = 0; - jint remaining; - jint offset; - buf = getPointer(_env, buffer, &array, &remaining, &offset); - if (array) { - releasePointer(_env, array, buf, 0); - } - buf = (char*)buf + offset; - } else { - jniThrowException(_env, "java/lang/IllegalArgumentException", - "Must use a native order direct Buffer"); - } + if (buffer == nullptr) { + return nullptr; } - return buf; + + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); + if (pointer == 0) { + jniThrowException(_env, "java/lang/IllegalArgumentException", + "Must use a native order direct Buffer"); + return nullptr; + } + pointer += position << elementSizeShift; + return reinterpret_cast<void*>(pointer); } static int |