diff options
author | Leon Scroggins III <scroggo@google.com> | 2019-03-26 16:28:41 -0400 |
---|---|---|
committer | Leon Scroggins III <scroggo@google.com> | 2019-03-27 13:39:23 -0400 |
commit | 71fae62f5fe03e9f8453ac3880587567ffcf9be6 (patch) | |
tree | 2d6c009c2e34eaebd050506048406dd1876a9f02 /rs/jni | |
parent | ca8aef63766b3193464b8f9b4cde45324a83789a (diff) |
Pass Bitmap's native instance to JNI where feasible
Test: CtsGraphicsTestCases, CtsUiRenderingTestCases,
CtsRenderscriptTestCases
This is significantly faster than passing the Java object down and then
calling a JNI method to retrieve the pointer. See
https://buganizer.corp.google.com/issues/16656908#comment19
In some cases this changes what used to be native crashes (due to
android::BitmapWrapper:assertValid's LOG_ALWAYS_FATAL_IF) into
NullPointerExceptions (if a caller used a null Bitmap).
In addition:
- Remove unnecessary JNIEnv param from toBitmap(jlong)
- Change instances of toBitmap(JNIEnv*, jobject) to the above
- Replace calls to GraphicsJNI::getSkBitmap() to inline calls to
toBitmap/getSkBitmap
- make Canvas#nInitRaster @FastNative (FIXME: Could these be
@CriticalNative?)
Change-Id: I6194097be1b6e6952eba70e1e7052a5a250eed93
Diffstat (limited to 'rs/jni')
-rw-r--r-- | rs/jni/android_renderscript_RenderScript.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp index 52d0e08e4e7f..dfee96182a48 100644 --- a/rs/jni/android_renderscript_RenderScript.cpp +++ b/rs/jni/android_renderscript_RenderScript.cpp @@ -1321,10 +1321,10 @@ nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc) static jlong nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, - jobject jbitmap, jint usage) + jlong bitmapPtr, jint usage) { SkBitmap bitmap; - GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); + bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap); const void* ptr = bitmap.getPixels(); jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con, @@ -1335,10 +1335,10 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, static jlong nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, - jint mip, jobject jbitmap, jint usage) + jint mip, jlong bitmapPtr, jint usage) { SkBitmap bitmap; - GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); + bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap); const void* ptr = bitmap.getPixels(); jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con, @@ -1349,10 +1349,10 @@ nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, static jlong nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, - jobject jbitmap, jint usage) + jlong bitmapPtr, jint usage) { SkBitmap bitmap; - GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); + bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap); const void* ptr = bitmap.getPixels(); jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con, @@ -1362,10 +1362,10 @@ nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong ty } static void -nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) +nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jlong bitmapPtr) { SkBitmap bitmap; - GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); + bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap); int w = bitmap.width(); int h = bitmap.height(); @@ -1376,10 +1376,10 @@ nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, j } static void -nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) +nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jlong bitmapPtr) { SkBitmap bitmap; - GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); + bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap); void* ptr = bitmap.getPixels(); rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.computeByteSize()); @@ -2866,13 +2866,13 @@ static const JNINativeMethod methods[] = { {"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate }, {"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData }, -{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped }, -{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap }, -{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation }, -{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap }, +{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped }, +{"rsnAllocationCreateFromBitmap", "(JJIJI)J", (void*)nAllocationCreateFromBitmap }, +{"rsnAllocationCreateBitmapBackedAllocation", "(JJIJI)J", (void*)nAllocationCreateBitmapBackedAllocation }, +{"rsnAllocationCubeCreateFromBitmap","(JJIJI)J", (void*)nAllocationCubeCreateFromBitmap }, -{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, -{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, +{"rsnAllocationCopyFromBitmap", "(JJJ)V", (void*)nAllocationCopyFromBitmap }, +{"rsnAllocationCopyToBitmap", "(JJJ)V", (void*)nAllocationCopyToBitmap }, {"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll }, {"rsnAllocationSetupBufferQueue", "(JJI)V", (void*)nAllocationSetupBufferQueue }, |