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
This commit is contained in:
Leon Scroggins III
2018-04-23 15:52:22 -04:00
parent e5d97dd6f9
commit 3eadfde67f

View File

@@ -296,6 +296,11 @@ void Bitmap::getSkBitmap(SkBitmap* outBitmap) {
outBitmap->allocPixels(info());
}
uirenderer::renderthread::RenderProxy::copyGraphicBufferInto(graphicBuffer(), outBitmap);
if (mInfo.colorSpace()) {
sk_sp<SkPixelRef> pixelRef = sk_ref_sp(outBitmap->pixelRef());
outBitmap->setInfo(mInfo);
outBitmap->setPixelRef(std::move(pixelRef), 0, 0);
}
return;
}
outBitmap->setInfo(mInfo, rowBytes());