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
This commit is contained in:
@@ -464,6 +464,17 @@ public class BitmapFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for passing inBitmap's native pointer to native.
|
||||
*/
|
||||
static long nativeInBitmap(Options opts) {
|
||||
if (opts == null || opts.inBitmap == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return opts.inBitmap.getNativeInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for passing SkColorSpace pointer to native.
|
||||
*
|
||||
@@ -652,6 +663,7 @@ public class BitmapFactory {
|
||||
Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
|
||||
try {
|
||||
bm = nativeDecodeByteArray(data, offset, length, opts,
|
||||
Options.nativeInBitmap(opts),
|
||||
Options.nativeColorSpace(opts));
|
||||
|
||||
if (bm == null && opts != null && opts.inBitmap != null) {
|
||||
@@ -747,7 +759,8 @@ public class BitmapFactory {
|
||||
try {
|
||||
if (is instanceof AssetManager.AssetInputStream) {
|
||||
final long asset = ((AssetManager.AssetInputStream) is).getNativeAsset();
|
||||
bm = nativeDecodeAsset(asset, outPadding, opts, Options.nativeColorSpace(opts));
|
||||
bm = nativeDecodeAsset(asset, outPadding, opts, Options.nativeInBitmap(opts),
|
||||
Options.nativeColorSpace(opts));
|
||||
} else {
|
||||
bm = decodeStreamInternal(is, outPadding, opts);
|
||||
}
|
||||
@@ -775,6 +788,7 @@ public class BitmapFactory {
|
||||
if (opts != null) tempStorage = opts.inTempStorage;
|
||||
if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE];
|
||||
return nativeDecodeStream(is, tempStorage, outPadding, opts,
|
||||
Options.nativeInBitmap(opts),
|
||||
Options.nativeColorSpace(opts));
|
||||
}
|
||||
|
||||
@@ -819,6 +833,7 @@ public class BitmapFactory {
|
||||
try {
|
||||
if (nativeIsSeekable(fd)) {
|
||||
bm = nativeDecodeFileDescriptor(fd, outPadding, opts,
|
||||
Options.nativeInBitmap(opts),
|
||||
Options.nativeColorSpace(opts));
|
||||
} else {
|
||||
FileInputStream fis = new FileInputStream(fd);
|
||||
@@ -856,15 +871,15 @@ public class BitmapFactory {
|
||||
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage,
|
||||
Rect padding, Options opts, long colorSpaceHandle);
|
||||
Rect padding, Options opts, long inBitmapHandle, long colorSpaceHandle);
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd,
|
||||
Rect padding, Options opts, long colorSpaceHandle);
|
||||
Rect padding, Options opts, long inBitmapHandle, long colorSpaceHandle);
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeAsset(long nativeAsset, Rect padding, Options opts,
|
||||
long colorSpaceHandle);
|
||||
long inBitmapHandle, long colorSpaceHandle);
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeByteArray(byte[] data, int offset,
|
||||
int length, Options opts, long colorSpaceHandle);
|
||||
int length, Options opts, long inBitmapHandle, long colorSpaceHandle);
|
||||
private static native boolean nativeIsSeekable(FileDescriptor fd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user