Merge "Use libnativehelper to get access to NIO buffer internals" into qt-dev
This commit is contained in:
@@ -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().
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@@ -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 = nullptr;
|
||||
pointer += position << elementSizeShift;
|
||||
return reinterpret_cast<void*>(pointer);
|
||||
}
|
||||
|
||||
*array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
|
||||
getBaseArrayID, buffer);
|
||||
if (*array == NULL) {
|
||||
*offset = 0;
|
||||
return (void*) NULL;
|
||||
}
|
||||
*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;
|
||||
if (buffer == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
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 buf;
|
||||
pointer += position << elementSizeShift;
|
||||
return reinterpret_cast<void*>(pointer);
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
Reference in New Issue
Block a user