diff --git a/include/core/SkMatrix44.h b/include/core/SkMatrix44.h index 9820ee58cd..83e51abe55 100644 --- a/include/core/SkMatrix44.h +++ b/include/core/SkMatrix44.h @@ -491,7 +491,10 @@ private: return 0 == fTypeMask; } + inline const SkMScalar* values() const { return &fMat[0][0]; } + friend class SkColorSpace; + friend class SkColorSpace_XYZ; }; #endif diff --git a/src/core/SkColorSpace_XYZ.cpp b/src/core/SkColorSpace_XYZ.cpp index 4329ed8ef2..baf99694b3 100644 --- a/src/core/SkColorSpace_XYZ.cpp +++ b/src/core/SkColorSpace_XYZ.cpp @@ -5,17 +5,17 @@ * found in the LICENSE file. */ -#include "SkChecksum.h" #include "SkColorSpace_XYZ.h" #include "SkColorSpacePriv.h" #include "SkColorSpaceXform_Base.h" +#include "SkOpts.h" SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) : INHERITED(nullptr) , fGammaNamed(gammaNamed) , fGammas(nullptr) , fToXYZD50(toXYZD50) - , fToXYZD50Hash(SkGoodHash()(toXYZD50)) + , fToXYZD50Hash(SkOpts::hash_fn(toXYZD50.values(), 16 * sizeof(SkMScalar), 0)) , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) {} @@ -25,7 +25,7 @@ SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, sk_sp gamm , fGammaNamed(gammaNamed) , fGammas(std::move(gammas)) , fToXYZD50(toXYZD50) - , fToXYZD50Hash(SkGoodHash()(toXYZD50)) + , fToXYZD50Hash(SkOpts::hash_fn(toXYZD50.values(), 16 * sizeof(SkMScalar), 0)) , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) { SkASSERT(!fGammas || 3 == fGammas->channels()); if (fGammas) { diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp index ba355cd612..65e0450892 100644 --- a/tests/ColorSpaceTest.cpp +++ b/tests/ColorSpaceTest.cpp @@ -419,3 +419,23 @@ DEF_TEST(ColorSpace_InvalidICC, r) { sk_sp cs = SkColorSpace::MakeICC(data->data(), data->size()); REPORTER_ASSERT(r, !cs); } + +DEF_TEST(ColorSpace_MatrixHash, r) { + sk_sp srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + + SkColorSpaceTransferFn fn; + fn.fA = 1.0f; + fn.fB = 0.0f; + fn.fC = 0.0f; + fn.fD = 0.0f; + fn.fE = 0.0f; + fn.fF = 0.0f; + fn.fG = 3.0f; + + SkMatrix44 srgbMat(SkMatrix44::kUninitialized_Constructor); + srgbMat.set3x3RowMajorf(gSRGB_toXYZD50); + sk_sp strange = SkColorSpace::MakeRGB(fn, srgbMat); + + REPORTER_ASSERT(r, *as_CSB(srgb)->toXYZD50() == *as_CSB(strange)->toXYZD50()); + REPORTER_ASSERT(r, as_CSB(srgb)->toXYZD50Hash() == as_CSB(strange)->toXYZD50Hash()); +}