diff --git a/src/core/SkColorSpacePriv.h b/src/core/SkColorSpacePriv.h index 12379d7c33..9ff9c3ac20 100644 --- a/src/core/SkColorSpacePriv.h +++ b/src/core/SkColorSpacePriv.h @@ -122,4 +122,17 @@ static inline bool is_almost_linear(const skcms_TransferFunction& coeffs) { SkColorSpace* sk_srgb_singleton(); SkColorSpace* sk_srgb_linear_singleton(); +/** + * Returns true if the combination of src and dst colorspaces result in basically a no-op, + * and thus we will generate correct results if we ignore both colorspaces (as we did in the + * legacy world of blits). + * + * Some examples: + * dst == null returns true: this is the classic definition of our legacy blits + * dst == src returns true: going through the new process is effectively a no-op + * src == null treats src as sRGB... + */ +bool sk_can_use_legacy_blits(SkColorSpace* src, SkColorSpace* dst); + + #endif // SkColorSpacePriv_DEFINED diff --git a/src/core/SkColorSpaceXformSteps.cpp b/src/core/SkColorSpaceXformSteps.cpp index 6e318149d7..7f0d5fb960 100644 --- a/src/core/SkColorSpaceXformSteps.cpp +++ b/src/core/SkColorSpaceXformSteps.cpp @@ -174,3 +174,13 @@ void SkColorSpaceXformSteps::apply(SkRasterPipeline* p, bool src_is_normalized) } if (flags.premul) { p->append(SkRasterPipeline::premul); } } + +////////////// + +bool sk_can_use_legacy_blits(SkColorSpace* src, SkColorSpace* dst) { + // When considering legacy blits, we only supported premul, so set those here + SkAlphaType srcAT = kPremul_SkAlphaType; + SkAlphaType dstAT = kPremul_SkAlphaType; + + return SkColorSpaceXformSteps(src, srcAT, dst, dstAT).flags.mask() == 0; +} diff --git a/src/shaders/SkShader.cpp b/src/shaders/SkShader.cpp index b75da92023..1f4114e163 100644 --- a/src/shaders/SkShader.cpp +++ b/src/shaders/SkShader.cpp @@ -8,6 +8,7 @@ #include "SkArenaAlloc.h" #include "SkBitmapProcShader.h" #include "SkColorShader.h" +#include "SkColorSpacePriv.h" #include "SkColorSpaceXformer.h" #include "SkEmptyShader.h" #include "SkMallocPixelRef.h" @@ -110,16 +111,7 @@ SkShaderBase::Context::Context(const SkShaderBase& shader, const ContextRec& rec SkShaderBase::Context::~Context() {} bool SkShaderBase::ContextRec::isLegacyCompatible(SkColorSpace* shaderColorSpace) const { - // Compatible means that the shader's (unmodified) colors will blend correctly with the - // device in the legacy mode where the colorspaces (of src and dst) are ignored. - if (fDstColorSpace == nullptr) { - return true; // untagged dst is by definition compatible with untagged/ignored src - } - if (shaderColorSpace == nullptr) { - // we treat untagged src as being srgb (e.g. SkColor) - return fDstColorSpace->isSRGB(); - } - return SkColorSpace::Equals(shaderColorSpace, fDstColorSpace); + return sk_can_use_legacy_blits(shaderColorSpace, fDstColorSpace); } const SkMatrix& SkShader::getLocalMatrix() const {