Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 300aaee4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Parcel implicit ashmem copies of bitmaps as immutable" into main

parents edf584d1 986bb7da
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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
+28 −1
Original line number Diff line number Diff line
@@ -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();