From 9f49a7cd7432950d0695ba4450b49a71a88ddc8e Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Wed, 29 Jan 2020 14:51:26 -0500 Subject: [PATCH] Force compressing ALPHA_8 to fail Bug: 146637821 Test: Iaf4d038379f46aa7e55384351d8098a32c4cd9ea This failed up through O, but "succeeded" for Bitmap.CompressFormat.PNG starting in P. The P behavior, though, uses a non-standard encoding. When re-decoding it, Android would treat it as an all black 8888 Bitmap with transparency, which is likely not what they wanted. Restore the pre-P behavior. Change-Id: I0f221fe66b6e318d2c9ed8fc199c2253f9f52497 --- libs/hwui/hwui/Bitmap.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index 7c0efe16838e1..58cc08bc2d733 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -479,6 +479,14 @@ bool Bitmap::compress(JavaCompressFormat format, int32_t quality, SkWStream* str bool Bitmap::compress(const SkBitmap& bitmap, JavaCompressFormat format, int32_t quality, SkWStream* stream) { + if (bitmap.colorType() == kAlpha_8_SkColorType) { + // None of the JavaCompressFormats have a sensible way to compress an + // ALPHA_8 Bitmap. SkPngEncoder will compress one, but it uses a non- + // standard format that most decoders do not understand, so this is + // likely not useful. + return false; + } + SkEncodedImageFormat fm; switch (format) { case JavaCompressFormat::Jpeg: