From 649fb73ab8c580b0112f7e0ebf4dc247c607022a Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Mon, 26 Feb 2018 15:09:16 -0500 Subject: [PATCH] make 1010102/888x layers 8888, not 1010102/888x This hopefully keeps all other considerations the same, like sRGB keeps sRGB layers, F16 F16 layers, etc. Change-Id: Icdf0b259ae782321e6f96c6f8bc814d520c7dd25 Reviewed-on: https://skia-review.googlesource.com/110442 Reviewed-by: Brian Osman Commit-Queue: Mike Klein --- src/core/SkCanvas.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 59365f76b0..269fac6f31 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1037,18 +1037,19 @@ void SkCanvas::DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filt } static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, const SkPaint* paint) { - // need to force L32 for now if we have an image filter. Once filters support other colortypes - // e.g. sRGB or F16, we can remove this check - // SRGBTODO: Can we remove this check now? - const bool hasImageFilter = paint && paint->getImageFilter(); - - if ((prev.bytesPerPixel() < 4) || hasImageFilter) { - // force to L32 + // Need to force L32 for now if we have an image filter. + // If filters ever support other colortypes, e.g. sRGB or F16, we can remove this check. + if (paint && paint->getImageFilter()) { return SkImageInfo::MakeN32Premul(w, h); - } else { - // keep the same characteristics as the prev - return SkImageInfo::Make(w, h, prev.colorType(), kPremul_SkAlphaType, prev.refColorSpace()); } + + SkColorType ct = prev.colorType(); + if (prev.bytesPerPixel() <= 4) { + // "Upgrade" A8, G8, 565, 4444, 1010102, 101010x, and 888x to 8888, + // ensuring plenty of alpha bits for the layer, perhaps losing some color bits in return. + ct = kN32_SkColorType; + } + return SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType, prev.refColorSpace()); } void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy strategy) {