Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: src/core/SkColorSpace.cpp

Issue 2302413002: Delete SkColorSpace::kUnknown_Named, remove fNamed field (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use a bare ptr instead of an sk_sp Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpace_Base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpace.cpp
diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp
index abdd647a258c173e329a4db1f87b550192e14acb..191d077223da772f7b71a4840ba6bf6b090b0f21 100644
--- a/src/core/SkColorSpace.cpp
+++ b/src/core/SkColorSpace.cpp
@@ -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) {
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpace_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698