diff options
author | 2025-03-11 15:23:46 -0700 | |
---|---|---|
committer | 2025-03-11 15:23:46 -0700 | |
commit | 986bb7daeccdba303c31de9e7ed4964e829fc647 (patch) | |
tree | eef2fc147003d68bfb17fd8cb0b5022d94be2669 | |
parent | 25a5ca4ea9c5ac6ab12203421fd0ea4f7f578c3d (diff) |
Parcel implicit ashmem copies of bitmaps as immutable
Bug: 400807118
Flag: com.android.graphics.hwui.flags.bitmap_parcel_ashmem_as_immutable
Change-Id: I8b82c78bb13ca70f2ead8eb0f8ba2438db12dca0
-rw-r--r-- | libs/hwui/aconfig/hwui_flags.aconfig | 7 | ||||
-rw-r--r-- | libs/hwui/jni/Bitmap.cpp | 29 |
2 files changed, 35 insertions, 1 deletions
diff --git a/libs/hwui/aconfig/hwui_flags.aconfig b/libs/hwui/aconfig/hwui_flags.aconfig index d3fc91b65829..b3badd0bd51d 100644 --- a/libs/hwui/aconfig/hwui_flags.aconfig +++ b/libs/hwui/aconfig/hwui_flags.aconfig @@ -203,4 +203,11 @@ flag { description: "Initialize GraphicBufferAllocater on ViewRootImpl init, to avoid blocking on init during buffer allocation, improving app launch latency." 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 diff --git a/libs/hwui/jni/Bitmap.cpp b/libs/hwui/jni/Bitmap.cpp index 27d4ac7cef4b..104ece6582f5 100644 --- a/libs/hwui/jni/Bitmap.cpp +++ b/libs/hwui/jni/Bitmap.cpp @@ -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; @@ -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 @@ -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(); |