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

Commit 13aefc4b authored by Robin Lee's avatar Robin Lee
Browse files

Retain the gainmap during Bitmap.asShared()

This was getting lost in some IPCs because the gainmap of an Ashmem
Bitmap was passed through as a local native pointer instead of also
being an Ashmem object.

Test: GainmapTests
Test: GainmapTest
Test: BitmapTest
Bug: 390675155
Flag: EXEMPT bugfix
Change-Id: I1940c5eb58d1cc5a83836f77e2618bd86ca35741
parent c396ff18
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