skip transfer functions when not needed

Change-Id: I72e1084e6a14b3c1fa3f0a5c2100f13c6bcb24c7
Reviewed-on: https://skia-review.googlesource.com/130062
Commit-Queue: Mike Klein <mtklein@chromium.org>
Auto-Submit: Mike Klein <mtklein@chromium.org>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2018-05-24 15:36:09 -04:00 committed by Skia Commit-Bot
parent a06f215a7d
commit 77418559ca
3 changed files with 28 additions and 11 deletions

View File

@ -83,4 +83,23 @@ SkColorSpaceXformSteps::SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType sr
// Step II) if dst has linear blending, encode back using dst transfer function before storing
this->late_encode = !dstNL;
// Fill out all the transfer functions we'll use:
SkColorSpaceTransferFn srcTF, dstTF;
SkAssertResult(src->isNumericalTransferFn(&srcTF));
SkAssertResult(dst->isNumericalTransferFn(&dstTF));
this->srcTFInv = srcTF.invert();
this->dstTF = dstTF;
this->dstTFInv = dstTF.invert();
// If we linearize then immediately reencode with the same transfer function, skip both.
if ( this->linearize_src &&
!this->late_unpremul &&
!this->gamut_transform &&
this->early_encode &&
0 == memcmp(&srcTF, &dstTF, sizeof(SkColorSpaceTransferFn)))
{
this->linearize_src = false;
this->early_encode = false;
}
}

View File

@ -29,11 +29,9 @@ struct SkColorSpaceXformSteps {
// Post-blend steps.
bool late_encode;
/* TODO
SkColorSpaceTransferFn srcTFInv, // Apply for linearize_src.
dstTFInv, // Apply for linearize_dst.
dstTF; // Apply for early_encode or late_encode.
*/
float src_to_dst_matrix[9]; // Apply this 3x3 row-major matrix for gamut_transform.
};

View File

@ -170,20 +170,20 @@ 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,true,false, false,true,true, false,false },
{ 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 },
// And the usual variants for opaque + unpremul sources.
{ srgb_N, srgb_N, kOpaque_SkAlphaType, false,true,false, false,true,false, false,false },
{ srgb_N, srgb_N, kUnpremul_SkAlphaType, false,true,false, false,true,true, false,false },
{ srgb_L, srgb_L, kOpaque_SkAlphaType, false,true,false, false,false,false, true,true },
{ srgb_L, srgb_L, kUnpremul_SkAlphaType, false,true,false, false,false,true, true,true },
{ srgb_L, srgb_N, kOpaque_SkAlphaType, false,true,false, false,true,false, false,false },
{ srgb_L, srgb_N, kUnpremul_SkAlphaType, false,true,false, false,true,true, false,false },
{ srgb_N, srgb_L, kOpaque_SkAlphaType, false,true,false, false,false,false, true,true },
{ srgb_N, srgb_L, kUnpremul_SkAlphaType, false,true,false, false,false,true, true,true },
{ srgb_N, srgb_N, kOpaque_SkAlphaType, false,false,false, false,false,false, false,false},
{ srgb_N, srgb_N, kUnpremul_SkAlphaType, false,false,false, false,false,true, false,false},
{ srgb_L, srgb_L, kOpaque_SkAlphaType, false,true,false, false,false,false, true,true },
{ srgb_L, srgb_L, kUnpremul_SkAlphaType, false,true,false, false,false,true, true,true },
{ srgb_L, srgb_N, kOpaque_SkAlphaType, false,false,false, false,false,false, false,false},
{ srgb_L, srgb_N, kUnpremul_SkAlphaType, false,false,false, false,false,true, false,false},
{ srgb_N, srgb_L, kOpaque_SkAlphaType, false,true,false, false,false,false, true,true },
{ srgb_N, srgb_L, kUnpremul_SkAlphaType, false,true,false, false,false,true, true,true },
// TODO: versions of above crossing in linear transfer functions
};