HardwareBitmaps: support createBitmap methods that return immutable bitmap
Test: testCreateScaledBitmap, testCreateTransformedBitmap, testCreateSubsetBitmap in HardwareBitmapTests bug:30999911 Change-Id: Ic128dfed78b18ad6f12dad50023ee7c2f5bfa4ad
This commit is contained in:
@@ -1291,6 +1291,23 @@ static jint Bitmap_getAllocationByteCount(JNIEnv* env, jobject, jlong bitmapPtr)
|
||||
return static_cast<jint>(bitmapHandle->getAllocationByteCount());
|
||||
}
|
||||
|
||||
static jobject Bitmap_nativeCopyPreserveInternalConfig(JNIEnv* env, jobject, jlong bitmapPtr) {
|
||||
LocalScopedBitmap bitmapHandle(bitmapPtr);
|
||||
LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(),
|
||||
"Hardware config is only supported config in Bitmap_nativeCopyPreserveInternalConfig");
|
||||
Bitmap& hwuiBitmap = bitmapHandle->bitmap();
|
||||
SkBitmap src;
|
||||
hwuiBitmap.getSkBitmap(&src);
|
||||
|
||||
SkBitmap result;
|
||||
HeapAllocator allocator;
|
||||
if (!src.copyTo(&result, hwuiBitmap.info().colorType(), &allocator)) {
|
||||
doThrowRE(env, "Could not copy a hardware bitmap.");
|
||||
return NULL;
|
||||
}
|
||||
return createBitmap(env, allocator.getStorageObjAndReset(), kBitmapCreateFlag_None);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static jclass make_globalref(JNIEnv* env, const char classname[])
|
||||
{
|
||||
@@ -1349,6 +1366,8 @@ static const JNINativeMethod gBitmapMethods[] = {
|
||||
{ "nativeSameAs", "(JJ)Z", (void*)Bitmap_sameAs },
|
||||
{ "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw },
|
||||
{ "nativeGetAllocationByteCount", "(J)I", (void*)Bitmap_getAllocationByteCount },
|
||||
{ "nativeCopyPreserveInternalConfig", "(J)Landroid/graphics/Bitmap;",
|
||||
(void*)Bitmap_nativeCopyPreserveInternalConfig },
|
||||
};
|
||||
|
||||
int register_android_graphics_Bitmap(JNIEnv* env)
|
||||
|
||||
@@ -753,6 +753,11 @@ public final class Bitmap implements Parcelable {
|
||||
return source;
|
||||
}
|
||||
|
||||
boolean isHardware = source.getConfig() == Config.HARDWARE;
|
||||
if (isHardware) {
|
||||
source = nativeCopyPreserveInternalConfig(source.mNativePtr);
|
||||
}
|
||||
|
||||
int neww = width;
|
||||
int newh = height;
|
||||
Canvas canvas = new Canvas();
|
||||
@@ -824,7 +829,9 @@ public final class Bitmap implements Parcelable {
|
||||
canvas.setBitmap(bitmap);
|
||||
canvas.drawBitmap(source, srcR, dstR, paint);
|
||||
canvas.setBitmap(null);
|
||||
|
||||
if (isHardware) {
|
||||
return bitmap.copy(Config.HARDWARE, false);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@@ -1773,4 +1780,5 @@ public final class Bitmap implements Parcelable {
|
||||
private static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1);
|
||||
private static native void nativePrepareToDraw(long nativeBitmap);
|
||||
private static native int nativeGetAllocationByteCount(long nativeBitmap);
|
||||
private static native Bitmap nativeCopyPreserveInternalConfig(long nativeBitmap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user