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

Unified Diff: src/core/SkColorSpace_A2B.h

Issue 2451903002: Reduced memory footprint of SkColorSpace_A2B (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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]; }
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698