Index: src/core/SkColorSpace_A2B.h |
diff --git a/src/core/SkColorSpace_A2B.h b/src/core/SkColorSpace_A2B.h |
index 844800588ba85085222421061834e3eda977bd94..94eaa75574d87f41cb487b59ba023adbe426c0ea 100644 |
--- a/src/core/SkColorSpace_A2B.h |
+++ b/src/core/SkColorSpace_A2B.h |
@@ -63,25 +63,94 @@ public: |
explicit Element(SkGammaNamed gammaNamed) |
: fType(Type::kGammaNamed) |
, fGammaNamed(gammaNamed) |
- , fMatrix(SkMatrix44::kUninitialized_Constructor) |
{} |
explicit Element(sk_sp<SkGammas> gammas) |
: fType(Type::kGammas) |
- , fGammas(std::move(gammas)) |
- , fMatrix(SkMatrix44::kUninitialized_Constructor) |
+ , fGammas(gammas.release()) |
{} |
explicit Element(sk_sp<SkColorLookUpTable> colorLUT) |
: fType(Type::kCLUT) |
- , fCLUT(std::move(colorLUT)) |
- , fMatrix(SkMatrix44::kUninitialized_Constructor) |
+ , fCLUT(colorLUT.release()) |
{} |
explicit Element(const SkMatrix44& matrix) |
: fType(Type::kMatrix) |
- , fMatrix(matrix) |
+ , fMatrix(new SkMatrix44(matrix)) |
{} |
+ |
+ ~Element() { dispose(); } |
+ |
+ Element(const Element& rhs) |
+ : fType(rhs.fType) { |
+ switch (fType) { |
+ case Type::kGammaNamed: |
+ fGammaNamed = rhs.fGammaNamed; |
+ break; |
+ case Type::kGammas: |
+ fGammas = rhs.fGammas; |
+ fGammas->ref(); |
+ break; |
+ case Type::kCLUT: |
+ fCLUT = rhs.fCLUT; |
+ fCLUT->ref(); |
+ break; |
+ case Type::kMatrix: |
+ fMatrix = new SkMatrix44(*rhs.fMatrix); |
+ break; |
+ } |
+ } |
+ |
+ Element& operator=(const Element& rhs) { |
+ Element copy(rhs); |
+ *this = std::move(copy); |
+ return *this; |
+ } |
+ |
+ Element(Element&& rhs) |
+ : fType(rhs.fType) { |
+ switch (fType) { |
+ case Type::kGammaNamed: |
+ fGammaNamed = rhs.fGammaNamed; |
+ break; |
+ case Type::kGammas: |
+ fGammas = rhs.fGammas; |
+ break; |
+ case Type::kCLUT: |
+ fCLUT = rhs.fCLUT; |
+ break; |
+ case Type::kMatrix: |
+ fMatrix = rhs.fMatrix; |
+ break; |
+ } |
+ // stop moved object from accessing shared contents as GammaNamed is |
+ // stored locally in Element, unlike the pointers |
+ rhs.fType = Type::kGammaNamed; |
+ } |
+ |
+ Element& operator=(Element&& rhs) { |
+ dispose(); |
+ fType = rhs.fType; |
+ switch (fType) { |
+ case Type::kGammaNamed: |
+ fGammaNamed = rhs.fGammaNamed; |
+ break; |
+ case Type::kGammas: |
+ fGammas = rhs.fGammas; |
+ break; |
+ case Type::kCLUT: |
+ fCLUT = rhs.fCLUT; |
+ break; |
+ case Type::kMatrix: |
+ fMatrix = rhs.fMatrix; |
+ break; |
+ } |
+ // stop moved object from accessing shared contents as GammaNamed is |
+ // stored locally in Element, unlike the pointers |
+ rhs.fType = Type::kGammaNamed; |
+ return *this; |
+ } |
enum class Type { |
kGammaNamed, |
@@ -109,15 +178,32 @@ public: |
const SkMatrix44& matrix() const { |
SkASSERT(Type::kMatrix == fType); |
- return fMatrix; |
+ return *fMatrix; |
} |
private: |
- Type fType; |
- SkGammaNamed fGammaNamed; |
- sk_sp<SkGammas> fGammas; |
- sk_sp<SkColorLookUpTable> fCLUT; |
- SkMatrix44 fMatrix; |
+ void dispose() { |
+ switch (fType) { |
+ case Type::kGammaNamed: |
+ break; |
+ case Type::kGammas: |
+ fGammas->unref(); |
+ break; |
+ case Type::kCLUT: |
+ fCLUT->unref(); |
+ break; |
+ case Type::kMatrix: |
+ delete fMatrix; |
+ break; |
+ } |
+ } |
+ Type fType; |
+ union { |
+ SkGammaNamed fGammaNamed; |
+ const SkGammas* fGammas; |
+ const SkColorLookUpTable* fCLUT; |
+ const SkMatrix44* fMatrix; |
+ }; |
}; |
const Element& element(size_t i) const { return fElements[i]; } |