Delete SkColorSpace::kUnknown_Named, remove fNamed field
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2302413002 Committed: https://skia.googlesource.com/skia/+/54682e856cb66c653bc7e253981a421a2618398e Review-Url: https://codereview.chromium.org/2302413002
This commit is contained in:
parent
bf4a8f90c8
commit
47ae5c5d8f
@ -19,13 +19,21 @@ public:
|
||||
/**
|
||||
* Common, named profiles that we can recognize.
|
||||
*/
|
||||
enum Named {
|
||||
kUnknown_Named,
|
||||
enum Named : uint8_t {
|
||||
/**
|
||||
* By far the most common color space.
|
||||
* This is the default space for images, unmarked content, and monitors.
|
||||
*/
|
||||
kSRGB_Named,
|
||||
|
||||
/**
|
||||
* Very common wide gamut color space.
|
||||
* Often used by images and monitors.
|
||||
*/
|
||||
kAdobeRGB_Named,
|
||||
};
|
||||
|
||||
enum GammaNamed {
|
||||
enum GammaNamed : uint8_t {
|
||||
kLinear_GammaNamed,
|
||||
|
||||
/**
|
||||
@ -111,11 +119,10 @@ public:
|
||||
static bool Equals(const SkColorSpace* src, const SkColorSpace* dst);
|
||||
|
||||
protected:
|
||||
SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named);
|
||||
SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50);
|
||||
|
||||
const GammaNamed fGammaNamed;
|
||||
const SkMatrix44 fToXYZD50;
|
||||
const Named fNamed;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -10,14 +10,13 @@
|
||||
#include "SkColorSpacePriv.h"
|
||||
#include "SkOnce.h"
|
||||
|
||||
SkColorSpace::SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named)
|
||||
SkColorSpace::SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50)
|
||||
: fGammaNamed(gammaNamed)
|
||||
, fToXYZD50(toXYZD50)
|
||||
, fNamed(named)
|
||||
{}
|
||||
|
||||
SkColorSpace_Base::SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named)
|
||||
: INHERITED(gammaNamed, toXYZD50, named)
|
||||
SkColorSpace_Base::SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& toXYZD50)
|
||||
: INHERITED(gammaNamed, toXYZD50)
|
||||
, fGammas(nullptr)
|
||||
, fProfileData(nullptr)
|
||||
{}
|
||||
@ -25,7 +24,7 @@ SkColorSpace_Base::SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& to
|
||||
SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, GammaNamed gammaNamed,
|
||||
sk_sp<SkGammas> gammas, const SkMatrix44& toXYZD50,
|
||||
sk_sp<SkData> profileData)
|
||||
: INHERITED(gammaNamed, toXYZD50, kUnknown_Named)
|
||||
: INHERITED(gammaNamed, toXYZD50)
|
||||
, fColorLUT(std::move(colorLUT))
|
||||
, fGammas(std::move(gammas))
|
||||
, fProfileData(std::move(profileData))
|
||||
@ -118,18 +117,19 @@ sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(GammaNamed gammaNamed, const SkMat
|
||||
break;
|
||||
}
|
||||
|
||||
return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50, kUnknown_Named));
|
||||
return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50));
|
||||
}
|
||||
|
||||
sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkMatrix44& toXYZD50) {
|
||||
return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50);
|
||||
}
|
||||
|
||||
static SkColorSpace* gAdobeRGB;
|
||||
static SkColorSpace* gSRGB;
|
||||
|
||||
sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
|
||||
static SkOnce sRGBOnce;
|
||||
static sk_sp<SkColorSpace> sRGB;
|
||||
static SkOnce adobeRGBOnce;
|
||||
static sk_sp<SkColorSpace> adobeRGB;
|
||||
|
||||
switch (named) {
|
||||
case kSRGB_Named: {
|
||||
@ -139,9 +139,9 @@ sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
|
||||
|
||||
// Force the mutable type mask to be computed. This avoids races.
|
||||
(void)srgbToxyzD50.getType();
|
||||
sRGB.reset(new SkColorSpace_Base(kSRGB_GammaNamed, srgbToxyzD50, kSRGB_Named));
|
||||
gSRGB = new SkColorSpace_Base(kSRGB_GammaNamed, srgbToxyzD50);
|
||||
});
|
||||
return sRGB;
|
||||
return sk_ref_sp<SkColorSpace>(gSRGB);
|
||||
}
|
||||
case kAdobeRGB_Named: {
|
||||
adobeRGBOnce([] {
|
||||
@ -150,10 +150,9 @@ sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
|
||||
|
||||
// Force the mutable type mask to be computed. This avoids races.
|
||||
(void)adobergbToxyzD50.getType();
|
||||
adobeRGB.reset(new SkColorSpace_Base(k2Dot2Curve_GammaNamed, adobergbToxyzD50,
|
||||
kAdobeRGB_Named));
|
||||
gAdobeRGB = new SkColorSpace_Base(k2Dot2Curve_GammaNamed, adobergbToxyzD50);
|
||||
});
|
||||
return adobeRGB;
|
||||
return sk_ref_sp<SkColorSpace>(gAdobeRGB);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@ -194,8 +193,8 @@ struct ColorSpaceHeader {
|
||||
*/
|
||||
static constexpr uint8_t kFloatGamma_Flag = 1 << 2;
|
||||
|
||||
static ColorSpaceHeader Pack(Version version, SkColorSpace::Named named,
|
||||
SkColorSpace::GammaNamed gammaNamed, uint8_t flags) {
|
||||
static ColorSpaceHeader Pack(Version version, uint8_t named, uint8_t gammaNamed, uint8_t flags)
|
||||
{
|
||||
ColorSpaceHeader header;
|
||||
|
||||
SkASSERT(k0_Version == version);
|
||||
@ -223,17 +222,17 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
|
||||
// we must have a profile that we can serialize easily.
|
||||
if (!as_CSB(this)->fProfileData) {
|
||||
// If we have a named profile, only write the enum.
|
||||
switch (fNamed) {
|
||||
case kSRGB_Named:
|
||||
case kAdobeRGB_Named: {
|
||||
if (memory) {
|
||||
*((ColorSpaceHeader*) memory) =
|
||||
ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed, 0);
|
||||
}
|
||||
return sizeof(ColorSpaceHeader);
|
||||
if (this == gSRGB) {
|
||||
if (memory) {
|
||||
*((ColorSpaceHeader*) memory) =
|
||||
ColorSpaceHeader::Pack(k0_Version, kSRGB_Named, fGammaNamed, 0);
|
||||
}
|
||||
return sizeof(ColorSpaceHeader);
|
||||
} else if (this == gAdobeRGB) {
|
||||
if (memory) {
|
||||
*((ColorSpaceHeader*) memory) =
|
||||
ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named, fGammaNamed, 0);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// If we have a named gamma, write the enum and the matrix.
|
||||
@ -243,7 +242,7 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
|
||||
case kLinear_GammaNamed: {
|
||||
if (memory) {
|
||||
*((ColorSpaceHeader*) memory) =
|
||||
ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed,
|
||||
ColorSpaceHeader::Pack(k0_Version, 0, fGammaNamed,
|
||||
ColorSpaceHeader::kMatrix_Flag);
|
||||
memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader));
|
||||
fToXYZD50.as4x3ColMajorf((float*) memory);
|
||||
@ -254,7 +253,7 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
|
||||
// Otherwise, write the gamma values and the matrix.
|
||||
if (memory) {
|
||||
*((ColorSpaceHeader*) memory) =
|
||||
ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed,
|
||||
ColorSpaceHeader::Pack(k0_Version, 0, fGammaNamed,
|
||||
ColorSpaceHeader::kFloatGamma_Flag);
|
||||
memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader));
|
||||
|
||||
@ -281,7 +280,7 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
|
||||
}
|
||||
|
||||
if (memory) {
|
||||
*((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, kUnknown_Named,
|
||||
*((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, 0,
|
||||
kNonStandard_GammaNamed,
|
||||
ColorSpaceHeader::kICC_Flag);
|
||||
memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader));
|
||||
@ -314,12 +313,8 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) {
|
||||
ColorSpaceHeader header = *((const ColorSpaceHeader*) data);
|
||||
data = SkTAddOffset<const void>(data, sizeof(ColorSpaceHeader));
|
||||
length -= sizeof(ColorSpaceHeader);
|
||||
switch ((Named) header.fNamed) {
|
||||
case kSRGB_Named:
|
||||
case kAdobeRGB_Named:
|
||||
return NewNamed((Named) header.fNamed);
|
||||
default:
|
||||
break;
|
||||
if (0 == header.fFlags) {
|
||||
return NewNamed((Named) header.fNamed);
|
||||
}
|
||||
|
||||
switch ((GammaNamed) header.fGammaNamed) {
|
||||
@ -382,17 +377,6 @@ bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (src->fNamed) {
|
||||
case kSRGB_Named:
|
||||
case kAdobeRGB_Named:
|
||||
return src->fNamed == dst->fNamed;
|
||||
case kUnknown_Named:
|
||||
if (kUnknown_Named != dst->fNamed) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
SkData* srcData = as_CSB(src)->fProfileData.get();
|
||||
SkData* dstData = as_CSB(dst)->fProfileData.get();
|
||||
if (srcData || dstData) {
|
||||
|
@ -193,7 +193,7 @@ private:
|
||||
|
||||
static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& toXYZD50);
|
||||
|
||||
SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& toXYZ, Named named);
|
||||
SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& toXYZ);
|
||||
|
||||
SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, GammaNamed gammaNamed,
|
||||
sk_sp<SkGammas> gammas, const SkMatrix44& toXYZ, sk_sp<SkData> profileData);
|
||||
|
@ -149,17 +149,15 @@ DEF_TEST(ColorSpaceWriteICC, r) {
|
||||
DEF_TEST(ColorSpace_Named, r) {
|
||||
const struct {
|
||||
SkColorSpace::Named fNamed;
|
||||
bool fExpectedToSucceed;
|
||||
bool fIsSRGB;
|
||||
} recs[] {
|
||||
{ SkColorSpace::kUnknown_Named, false, false },
|
||||
{ SkColorSpace::kSRGB_Named, true, true },
|
||||
{ SkColorSpace::kAdobeRGB_Named, true, false },
|
||||
{ SkColorSpace::kSRGB_Named, true },
|
||||
{ SkColorSpace::kAdobeRGB_Named, false },
|
||||
};
|
||||
|
||||
for (auto rec : recs) {
|
||||
auto cs = SkColorSpace::NewNamed(rec.fNamed);
|
||||
REPORTER_ASSERT(r, !cs == !rec.fExpectedToSucceed);
|
||||
REPORTER_ASSERT(r, cs);
|
||||
if (cs) {
|
||||
if (rec.fIsSRGB) {
|
||||
REPORTER_ASSERT(r, SkColorSpace::kSRGB_GammaNamed == cs->gammaNamed());
|
||||
|
Loading…
Reference in New Issue
Block a user