From 4a0ad501e4919e06bcf7a7ef4adec8f28818946b Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Thu, 24 May 2018 15:54:59 -0400 Subject: [PATCH] skip unpremul...premul with only linear ops between Change-Id: I26ed83bb613a83a0fd73f2f8b868b775be1ce968 Reviewed-on: https://skia-review.googlesource.com/130121 Commit-Queue: Mike Klein Auto-Submit: Mike Klein Reviewed-by: Brian Osman --- src/core/SkColorSpaceXformSteps.cpp | 18 ++++++++++++++++++ tests/SkColorSpaceXformStepsTest.cpp | 18 +++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/core/SkColorSpaceXformSteps.cpp b/src/core/SkColorSpaceXformSteps.cpp index 08a59fc672..e4b465e6cf 100644 --- a/src/core/SkColorSpaceXformSteps.cpp +++ b/src/core/SkColorSpaceXformSteps.cpp @@ -102,4 +102,22 @@ SkColorSpaceXformSteps::SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType sr this->linearize_src = false; this->early_encode = false; } + + // Skip unpremul...premul if there are no non-linear operations between. + if ( this->early_unpremul && + !this->linearize_src && + !this->early_encode && + this->premul) + { + this->early_unpremul = false; + this->premul = false; + } + + if ( this->late_unpremul && + !this->early_encode && + this->premul) + { + this->late_unpremul = false; + this->premul = false; + } } diff --git a/tests/SkColorSpaceXformStepsTest.cpp b/tests/SkColorSpaceXformStepsTest.cpp index b0b9c44afe..6b2cf46203 100644 --- a/tests/SkColorSpaceXformStepsTest.cpp +++ b/tests/SkColorSpaceXformStepsTest.cpp @@ -69,16 +69,16 @@ DEF_TEST(SkColorSpaceXformSteps, r) { { adobe_L, srgb_L, kPremul_SkAlphaType, false, // src is encoded as f(s*a),a, so we linearize before unpremul. true, // Linearize, - true, // then unpremul. + false, // then unpremul, but we can skip this here. true, // Gamut transform. false, // We're doing linear blending, so we don't encode to sRGB yet. - true, // Premul so we can blend. + false, // Premul so we can blend, but skipped because we never unpremulled. true, // We're doing linear blending, so we need to linearize dst. true, // Once blending is done, finally encode to sRGB. }, - { srgb_L, adobe_L, kPremul_SkAlphaType, false,true,true, true,false,true, true,true }, + { srgb_L, adobe_L, kPremul_SkAlphaType, false,true,false, true,false,false, true,true }, { adobe_L, srgb_N, kPremul_SkAlphaType, false, // src is encoded as f(s*a),a, so we linearize before unpremul. @@ -138,8 +138,8 @@ DEF_TEST(SkColorSpaceXformSteps, r) { { srgb_N, srgb22_N, kPremul_SkAlphaType, true,true,false, false,true,true, false,false }, { srgb22_N, srgb_N, kPremul_SkAlphaType, true,true,false, false,true,true, false,false }, - { srgb_L, srgb22_L, kPremul_SkAlphaType, false,true,true, false,false,true, true,true }, - { srgb22_L, srgb_L, kPremul_SkAlphaType, false,true,true, false,false,true, true,true }, + { srgb_L, srgb22_L, kPremul_SkAlphaType, false,true,false, false,false,false, true,true }, + { srgb22_L, srgb_L, kPremul_SkAlphaType, false,true,false, false,false,false, true,true }, { srgb_L, srgb22_N, kPremul_SkAlphaType, false,true,true, false,true,true, false,false }, { srgb22_L, srgb_N, kPremul_SkAlphaType, false,true,true, false,true,true, false,false }, @@ -170,10 +170,10 @@ DEF_TEST(SkColorSpaceXformSteps, r) { // These four test cases test drawing in the same color space. // There is lots of room for optimization here. - { srgb_N, srgb_N, kPremul_SkAlphaType, true,false,false, false,false,true, false,false }, - { srgb_L, srgb_L, kPremul_SkAlphaType, false,true,true, false,false,true, true,true }, - { srgb_L, srgb_N, kPremul_SkAlphaType, false,true,true, false,true,true, false,false }, - { srgb_N, srgb_L, kPremul_SkAlphaType, true,true,false, false,false,true, true,true }, + { srgb_N, srgb_N, kPremul_SkAlphaType, false,false,false, false,false,false, false,false}, + { srgb_L, srgb_L, kPremul_SkAlphaType, false,true,false, false,false,false, true,true }, + { srgb_L, srgb_N, kPremul_SkAlphaType, false,true,true, false,true,true, false,false}, + { srgb_N, srgb_L, kPremul_SkAlphaType, true,true,false, false,false,true, true,true }, // And the usual variants for opaque + unpremul sources. { srgb_N, srgb_N, kOpaque_SkAlphaType, false,false,false, false,false,false, false,false},