Null out gainmaps on inBitmap re-use

Bug: 277230526
Test: android.graphics.cts.GainmapTest#testDecodeGainmapBitmapFactoryReuse
Change-Id: I437f2599f023d83bdd70f1bf123357318c79b4e3
This commit is contained in:
John Reck
2023-04-06 17:06:22 -04:00
parent 7220f21ddd
commit 9985065af0
2 changed files with 4 additions and 1 deletions

View File

@@ -1921,6 +1921,7 @@ public final class Bitmap implements Parcelable {
*/
public void setGainmap(@Nullable Gainmap gainmap) {
checkRecycled("Bitmap is recycled");
mGainmap = null;
nativeSetGainmap(mNativePtr, gainmap == null ? 0 : gainmap.mNativePtr);
}

View File

@@ -482,7 +482,9 @@ public class BitmapFactory {
if (opts == null || opts.inBitmap == null) {
return 0;
}
// Clear out the gainmap since we don't attempt to reuse it and don't want to
// accidentally keep it on the re-used bitmap
opts.inBitmap.setGainmap(null);
return opts.inBitmap.getNativeInstance();
}