From ae6377c08e5c3735c65212ba9ff86fa51af7d68a Mon Sep 17 00:00:00 2001 From: msarett Date: Tue, 23 Aug 2016 14:36:20 -0700 Subject: [PATCH] Make singleton SkColorSpaces thread safe SkColorSpaces may be once-ptrs, so we can reuse common color spaces. This means that they must be thread safe. SkMatrix44 is not thread safe because it maintains a mutable type mask. This CL ensures that we precompute the type mask so we can use const SkMatrix44's safely. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2277463002 Review-Url: https://codereview.chromium.org/2277463002 --- src/core/SkColorSpace.cpp | 6 ++++++ tests/ColorSpaceTest.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp index 3a5d9c196a..6302075658 100644 --- a/src/core/SkColorSpace.cpp +++ b/src/core/SkColorSpace.cpp @@ -136,6 +136,9 @@ sk_sp SkColorSpace::NewNamed(Named named) { sRGBOnce([] { SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50); + + // Force the mutable type mask to be computed. This avoids races. + (void)srgbToxyzD50.getType(); sRGB.reset(new SkColorSpace_Base(kSRGB_GammaNamed, srgbToxyzD50, kSRGB_Named)); }); return sRGB; @@ -144,6 +147,9 @@ sk_sp SkColorSpace::NewNamed(Named named) { adobeRGBOnce([] { SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Constructor); adobergbToxyzD50.set3x3RowMajorf(gAdobeRGB_toXYZD50); + + // Force the mutable type mask to be computed. This avoids races. + (void)adobergbToxyzD50.getType(); adobeRGB.reset(new SkColorSpace_Base(k2Dot2Curve_GammaNamed, adobergbToxyzD50, kAdobeRGB_Named)); }); diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp index abc02b74d8..393d75310b 100644 --- a/tests/ColorSpaceTest.cpp +++ b/tests/ColorSpaceTest.cpp @@ -24,7 +24,7 @@ static void test_space(skiatest::Reporter* r, SkColorSpace* space, REPORTER_ASSERT(r, expectedGamma == space->gammaNamed()); - SkMatrix44 mat = space->xyz(); + const SkMatrix44& mat = space->xyz(); const float src[] = { 1, 0, 0, 1, 0, 1, 0, 1,