Loading libs/hwui/aconfig/hwui_flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -204,3 +204,10 @@ flag { bug: "389908734" is_fixed_read_only: true } flag { name: "bitmap_parcel_ashmem_as_immutable" namespace: "system_performance" description: "Whether to parcel implicit copies of bitmaps to ashmem as immutable" bug: "400807118" } No newline at end of file libs/hwui/jni/Bitmap.cpp +28 −1 Original line number Diff line number Diff line Loading @@ -28,8 +28,18 @@ #include "SkRefCnt.h" #include "SkStream.h" #include "SkTypes.h" #include "android/binder_parcel.h" #include "android_nio_utils.h" #ifdef __ANDROID__ #include <com_android_graphics_hwui_flags.h> namespace hwui_flags = com::android::graphics::hwui::flags; #else namespace hwui_flags { constexpr bool bitmap_parcel_ashmem_as_immutable() { return false; } } #endif #define DEBUG_PARCEL 0 static jclass gBitmap_class; Loading Loading @@ -841,6 +851,23 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { #endif } // Returns whether this bitmap should be written to the parcel as mutable. static bool shouldParcelAsMutable(SkBitmap& bitmap, AParcel* parcel) { // If the bitmap is immutable, then parcel as immutable. if (bitmap.isImmutable()) { return false; } if (!hwui_flags::bitmap_parcel_ashmem_as_immutable()) { return true; } // If we're going to copy the bitmap to ashmem and write that to the parcel, // then parcel as immutable, since we won't be mutating the bitmap after // writing it to the parcel. return !shouldUseAshmem(parcel, bitmap.computeByteSize()); } static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, jlong bitmapHandle, jint density, jobject parcel) { #ifdef __linux__ // Only Linux support parcel Loading @@ -855,7 +882,7 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, jlong bitmapHandle, j auto bitmapWrapper = reinterpret_cast<BitmapWrapper*>(bitmapHandle); bitmapWrapper->getSkBitmap(&bitmap); p.writeInt32(!bitmap.isImmutable()); p.writeInt32(shouldParcelAsMutable(bitmap, p.get())); p.writeInt32(bitmap.colorType()); p.writeInt32(bitmap.alphaType()); SkColorSpace* colorSpace = bitmap.colorSpace(); Loading Loading
libs/hwui/aconfig/hwui_flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -204,3 +204,10 @@ flag { bug: "389908734" is_fixed_read_only: true } flag { name: "bitmap_parcel_ashmem_as_immutable" namespace: "system_performance" description: "Whether to parcel implicit copies of bitmaps to ashmem as immutable" bug: "400807118" } No newline at end of file
libs/hwui/jni/Bitmap.cpp +28 −1 Original line number Diff line number Diff line Loading @@ -28,8 +28,18 @@ #include "SkRefCnt.h" #include "SkStream.h" #include "SkTypes.h" #include "android/binder_parcel.h" #include "android_nio_utils.h" #ifdef __ANDROID__ #include <com_android_graphics_hwui_flags.h> namespace hwui_flags = com::android::graphics::hwui::flags; #else namespace hwui_flags { constexpr bool bitmap_parcel_ashmem_as_immutable() { return false; } } #endif #define DEBUG_PARCEL 0 static jclass gBitmap_class; Loading Loading @@ -841,6 +851,23 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { #endif } // Returns whether this bitmap should be written to the parcel as mutable. static bool shouldParcelAsMutable(SkBitmap& bitmap, AParcel* parcel) { // If the bitmap is immutable, then parcel as immutable. if (bitmap.isImmutable()) { return false; } if (!hwui_flags::bitmap_parcel_ashmem_as_immutable()) { return true; } // If we're going to copy the bitmap to ashmem and write that to the parcel, // then parcel as immutable, since we won't be mutating the bitmap after // writing it to the parcel. return !shouldUseAshmem(parcel, bitmap.computeByteSize()); } static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, jlong bitmapHandle, jint density, jobject parcel) { #ifdef __linux__ // Only Linux support parcel Loading @@ -855,7 +882,7 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, jlong bitmapHandle, j auto bitmapWrapper = reinterpret_cast<BitmapWrapper*>(bitmapHandle); bitmapWrapper->getSkBitmap(&bitmap); p.writeInt32(!bitmap.isImmutable()); p.writeInt32(shouldParcelAsMutable(bitmap, p.get())); p.writeInt32(bitmap.colorType()); p.writeInt32(bitmap.alphaType()); SkColorSpace* colorSpace = bitmap.colorSpace(); Loading