From e42f93c730a41187a512c0263499b6e5e0ecb689 Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 30 Sep 2024 11:05:10 -0400 Subject: Add null colorspace protection Fixes: 367272642 Test: none Flag: EXEMPT bugfix Change-Id: I6831512e799df9025a91d768094a1862802803e4 --- libs/hwui/SkiaCanvas.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libs/hwui/SkiaCanvas.cpp') diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 9e825fb350d6..7c150862a422 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -619,8 +619,11 @@ bool SkiaCanvas::useGainmapShader(Bitmap& bitmap) { // If it's an unknown colortype then it's not a bitmap-backed canvas if (info.colorType() == SkColorType::kUnknown_SkColorType) return true; + auto colorSpace = info.colorSpace(); + // If we don't have a colorspace, we can't apply a gainmap + if (!colorSpace) return false; skcms_TransferFunction tfn; - info.colorSpace()->transferFn(&tfn); + colorSpace->transferFn(&tfn); auto transferType = skcms_TransferFunction_getType(&tfn); switch (transferType) { -- cgit v1.2.3-59-g8ed1b From e84cc9ea26177de58e2ae65a448c9b6882769d52 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Thu, 17 Oct 2024 14:56:25 +0000 Subject: Correctly render ISO gainmapped images * Apply the gainmap in reverse when using an HDR base image * Support alternative primaries * Nudge the guards that optimize away applying the gainmap shader Bug: 349357636 Flag: com.android.graphics.hwui.flags.iso_gainmap_apis Test: GainmapTests Change-Id: I230a765feddb306330e643e6ead8e62719f49ee5 --- libs/hwui/SkiaCanvas.cpp | 19 +++++++------------ libs/hwui/effects/GainmapRenderer.cpp | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'libs/hwui/SkiaCanvas.cpp') diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 7c150862a422..7f5ca44f7ceb 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -622,18 +622,13 @@ bool SkiaCanvas::useGainmapShader(Bitmap& bitmap) { auto colorSpace = info.colorSpace(); // If we don't have a colorspace, we can't apply a gainmap if (!colorSpace) return false; - skcms_TransferFunction tfn; - colorSpace->transferFn(&tfn); - - auto transferType = skcms_TransferFunction_getType(&tfn); - switch (transferType) { - case skcms_TFType_HLGish: - case skcms_TFType_HLGinvish: - case skcms_TFType_PQish: - return true; - case skcms_TFType_Invalid: - case skcms_TFType_sRGBish: - return false; + + const float targetRatio = uirenderer::getTargetHdrSdrRatio(colorSpace); + + if (bitmap.gainmap()->info.fBaseImageType == SkGainmapInfo::BaseImageType::kHDR) { + return targetRatio < bitmap.gainmap()->info.fDisplayRatioHdr; + } else { + return targetRatio > bitmap.gainmap()->info.fDisplayRatioSdr; } } diff --git a/libs/hwui/effects/GainmapRenderer.cpp b/libs/hwui/effects/GainmapRenderer.cpp index eac03609d72f..18b77bc51aca 100644 --- a/libs/hwui/effects/GainmapRenderer.cpp +++ b/libs/hwui/effects/GainmapRenderer.cpp @@ -73,7 +73,9 @@ void DrawGainmapBitmap(SkCanvas* c, const sk_sp& image, const SkR #ifdef __ANDROID__ auto destColorspace = c->imageInfo().refColorSpace(); float targetSdrHdrRatio = getTargetHdrSdrRatio(destColorspace.get()); - if (targetSdrHdrRatio > 1.f && gainmapImage) { + const bool baseImageHdr = gainmapInfo.fBaseImageType == SkGainmapInfo::BaseImageType::kHDR; + if (gainmapImage && ((baseImageHdr && targetSdrHdrRatio < gainmapInfo.fDisplayRatioHdr) || + (!baseImageHdr && targetSdrHdrRatio > gainmapInfo.fDisplayRatioSdr))) { SkPaint gainmapPaint = *paint; float sX = gainmapImage->width() / (float)image->width(); float sY = gainmapImage->height() / (float)image->height(); @@ -183,7 +185,10 @@ private: baseImage->colorSpace() ? baseImage->refColorSpace() : SkColorSpace::MakeSRGB(); // Determine the color space in which the gainmap math is to be applied. - sk_sp gainmapMathColorSpace = baseColorSpace->makeLinearGamma(); + sk_sp gainmapMathColorSpace = + mGainmapInfo.fGainmapMathColorSpace + ? mGainmapInfo.fGainmapMathColorSpace->makeLinearGamma() + : baseColorSpace->makeLinearGamma(); // Create a color filter to transform from the base image's color space to the color space // in which the gainmap is to be applied. @@ -266,6 +271,10 @@ private: W = 1.f; } } + + if (mGainmapInfo.fBaseImageType == SkGainmapInfo::BaseImageType::kHDR) { + W -= 1.f; + } mBuilder.uniform("W") = W; uniforms = mBuilder.uniforms(); } @@ -317,4 +326,4 @@ sk_sp MakeGainmapShader(const sk_sp& image, #endif // __ANDROID__ -} // namespace android::uirenderer \ No newline at end of file +} // namespace android::uirenderer -- cgit v1.2.3-59-g8ed1b