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

Commit 5853a8d3 authored by Robin Lee's avatar Robin Lee Committed by Android (Google) Code Review
Browse files

Merge "Retain the gainmap during Bitmap.asShared()" into main

parents f6992ead 13aefc4b
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -755,6 +755,9 @@ public final class Bitmap implements Parcelable {
        if (b != null) {
            b.setPremultiplied(mRequestPremultiplied);
            b.mDensity = mDensity;
            if (hasGainmap()) {
                b.setGainmap(getGainmap().asShared());
            }
        }
        return b;
    }
@@ -767,7 +770,8 @@ public final class Bitmap implements Parcelable {
     */
    @NonNull
    public Bitmap asShared() {
        if (nativeIsBackedByAshmem(mNativePtr) && nativeIsImmutable(mNativePtr)) {
        if (nativeIsBackedByAshmem(mNativePtr) && nativeIsImmutable(mNativePtr)
                && (!hasGainmap() || getGainmap().asShared() == getGainmap())) {
            return this;
        }
        Bitmap shared = createAshmemBitmap();
@@ -2091,7 +2095,7 @@ public final class Bitmap implements Parcelable {
     */
    public void setGainmap(@Nullable Gainmap gainmap) {
        checkRecycled("Bitmap is recycled");
        mGainmap = null;
        mGainmap = gainmap;
        nativeSetGainmap(mNativePtr, gainmap == null ? 0 : gainmap.mNativePtr);
    }

+12 −0
Original line number Diff line number Diff line
@@ -160,6 +160,18 @@ public final class Gainmap implements Parcelable {
        this(gainmapContents, nCreateCopy(gainmap.mNativePtr));
    }

    /**
     * @hide
     */
    public Gainmap asShared() {
        final Bitmap sharedContents = mGainmapContents.asShared();
        if (sharedContents == mGainmapContents) {
            return this;
        } else {
            return new Gainmap(sharedContents, nCreateCopy(mNativePtr));
        }
    }

    /**
     * @return Returns the image data of the gainmap represented as a Bitmap. This is represented
     * as a Bitmap for broad API compatibility, however certain aspects of the Bitmap are ignored