Update color-space flags to avoid shutdown destructors.

Note that both `unordered_map` and `sk_sp` had non-trivial
destructors.

Change-Id: I39ffc2193c7935e71aab9b5c7474a64b5f93f753
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/550176
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-06-15 09:41:01 -04:00 committed by SkCQ
parent 70b01b9f4f
commit 061a80c264

View File

@ -232,24 +232,28 @@ SkCommandLineConfig::SkCommandLineConfig(const SkString& tag,
const SkString& backend,
const SkTArray<SkString>& viaParts)
: fTag(tag), fBackend(backend) {
static std::unordered_map<std::string_view, sk_sp<SkColorSpace>> kColorSpaces = {
// 'narrow' has a gamut narrower than sRGB, and different transfer function.
{ "narrow", SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50) },
{ "srgb", SkColorSpace::MakeSRGB() },
{ "linear", SkColorSpace::MakeSRGBLinear() },
{ "p3", SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3) },
{ "spin", SkColorSpace::MakeSRGB()->makeColorSpin() },
{ "rec2020", SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, SkNamedGamut::kRec2020) },
static const auto* kColorSpaces = new std::unordered_map<std::string_view, SkColorSpace*>{
{"narrow", // 'narrow' has a gamut narrower than sRGB, and different transfer function.
SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50).release()},
{"srgb",
SkColorSpace::MakeSRGB().release()},
{"linear",
SkColorSpace::MakeSRGBLinear().release()},
{"p3",
SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3).release()},
{"spin",
SkColorSpace::MakeSRGB()->makeColorSpin().release()},
{"rec2020",
SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, SkNamedGamut::kRec2020).release()},
};
// Strip off any via parts that refer to color spaces (and remember the last one we see)
for (const SkString& via : viaParts) {
auto it = kColorSpaces.find(via.c_str());
if (it == kColorSpaces.end()) {
auto it = kColorSpaces->find(via.c_str());
if (it == kColorSpaces->end()) {
fViaParts.push_back(via);
} else {
fColorSpace = it->second;
fColorSpace = sk_ref_sp(it->second);
}
}
}