diff options
author | 2019-03-01 17:11:02 +0000 | |
---|---|---|
committer | 2019-04-11 16:52:50 +0100 | |
commit | 9c5ed187e68b907c7138639e4a399a7fe5c92843 (patch) | |
tree | efaa8a39ee1e7a87d83ed39b6729a8b571113411 | |
parent | 43adcf288bdd66d2fe8dd40f6cd47ca034406192 (diff) |
Update stubs to use libnativehelper for java.nio.Buffer access
Bug: 124338141
Test: atest CtsGraphicsTestCases
(cherry picked from commit 13309b3d8f837eb32774dd6e401452d1cf5010a1)
Change-Id: I6bb5cbc27dbb00fe944f78bb8095cd3002989547
Merged-In: I5e4978f4523d4f80bc6813740f2ed9cb57c6d9f4
-rw-r--r-- | opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp | 46 | ||||
-rw-r--r-- | opengl/tools/glgen/stubs/gles11/common.cpp | 62 | ||||
-rw-r--r-- | opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp | 99 |
3 files changed, 42 insertions, 165 deletions
diff --git a/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp b/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp index 8bb0c6a04f..34cb3e1a99 100644 --- a/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp +++ b/opengl/tools/glgen/stubs/egl/EGL15cHeader.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/opengl/tools/glgen/stubs/gles11/common.cpp b/opengl/tools/glgen/stubs/gles11/common.cpp index 51e62ed393..e763b4e983 100644 --- a/opengl/tools/glgen/stubs/gles11/common.cpp +++ b/opengl/tools/glgen/stubs/gles11/common.cpp @@ -4,15 +4,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 */ @@ -47,28 +38,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 * @@ -79,23 +51,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 { @@ -217,16 +183,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/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp index c808fe9681..c12efc3795 100644 --- a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp +++ b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp @@ -64,16 +64,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; @@ -85,12 +76,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"); @@ -98,19 +83,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 * @@ -121,28 +93,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 @@ -156,42 +117,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 |