From 3eadfde67f32bebf109634110a0e189263fa7e11 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Mon, 23 Apr 2018 15:52:22 -0400 Subject: [PATCH] Attach color space after performing a readback Bug: 78463311 Test: I28713c3e5ce38dea15c75542801f9aef0e5b5b0a Bitmap::getSkBitmap() is used by Bitmap#compress before encoding. If the Bitmap has Config HARDWARE, we have to do a readback first. We cannot necessarily do the readback using the SkColorSpace of the Bitmap, since that requires creating an SkSurface, which does not support all SkColorSpaces. Instead, continue using nullptr for the readback, and then change the info and reattach the SkPixelRef. This fixes a bug where encoding a non-SRGB HARDWARE Bitmap and then decoding it results in a Bitmap with the wrong ColorSpace. Change-Id: If55b2dbfeb17d81ceaf9594b32ed69b6a9058f06 --- libs/hwui/hwui/Bitmap.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index 795ec5bd4f768..263d249d20e98 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -296,6 +296,11 @@ void Bitmap::getSkBitmap(SkBitmap* outBitmap) { outBitmap->allocPixels(info()); } uirenderer::renderthread::RenderProxy::copyGraphicBufferInto(graphicBuffer(), outBitmap); + if (mInfo.colorSpace()) { + sk_sp pixelRef = sk_ref_sp(outBitmap->pixelRef()); + outBitmap->setInfo(mInfo); + outBitmap->setPixelRef(std::move(pixelRef), 0, 0); + } return; } outBitmap->setInfo(mInfo, rowBytes());