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[])
{
{ "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)
return source;
}
+ boolean isHardware = source.getConfig() == Config.HARDWARE;
+ if (isHardware) {
+ source = nativeCopyPreserveInternalConfig(source.mNativePtr);
+ }
+
int neww = width;
int newh = height;
Canvas canvas = new Canvas();
canvas.setBitmap(bitmap);
canvas.drawBitmap(source, srcR, dstR, paint);
canvas.setBitmap(null);
-
+ if (isHardware) {
+ return bitmap.copy(Config.HARDWARE, false);
+ }
return bitmap;
}
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);
}