diff options
| author | 2025-02-04 14:07:24 +0100 | |
|---|---|---|
| committer | 2025-03-11 06:45:17 -0700 | |
| commit | 13aefc4ba816dff4bd0875c6eca3b9dd1015a432 (patch) | |
| tree | 2a7ceb8c9b4f46ebfe94f6ef75d381a0ed100c50 | |
| parent | c396ff181fce9cd7e1dd8f75d40f6845915d0bf0 (diff) | |
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
| -rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 8 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Gainmap.java | 12 |
2 files changed, 18 insertions, 2 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index cd5a54c2fd3f..a4ba2b398deb 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -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); } diff --git a/graphics/java/android/graphics/Gainmap.java b/graphics/java/android/graphics/Gainmap.java index 7fc13db85659..2417a1270bc5 100644 --- a/graphics/java/android/graphics/Gainmap.java +++ b/graphics/java/android/graphics/Gainmap.java @@ -161,6 +161,18 @@ public final class Gainmap implements Parcelable { } /** + * @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 * such as {@link Bitmap#getColorSpace()} or {@link Bitmap#getGainmap()} as they are not |