diff options
author | subhransu mohanty <sub.mohanty@samsung.com> | 2017-12-20 13:51:46 +0900 |
---|---|---|
committer | subhransu mohanty <sub.mohanty@samsung.com> | 2018-04-12 13:51:52 +0900 |
commit | 7fc9a6060c71b6781f948a3d4e3f9c378cdd4062 (patch) | |
tree | 00aa226c217e5ac4b910a28effb9a688641269c0 | |
parent | 1a021f700c63315955d65eb87a6170e920a1f5f7 (diff) | |
download | efl-7fc9a6060c71b6781f948a3d4e3f9c378cdd4062.tar.gz |
lottie: make all lotti node as shared node
-rw-r--r-- | ssg/src/lottie/lottiemodel.cpp | 16 | ||||
-rw-r--r-- | ssg/src/lottie/lottiemodel.h | 17 | ||||
-rw-r--r-- | ssg/src/lottie/lottieparser.cpp | 146 |
3 files changed, 105 insertions, 74 deletions
diff --git a/ssg/src/lottie/lottiemodel.cpp b/ssg/src/lottie/lottiemodel.cpp index 0a3dffe30b..3e5c7bd62d 100644 --- a/ssg/src/lottie/lottiemodel.cpp +++ b/ssg/src/lottie/lottiemodel.cpp @@ -18,11 +18,12 @@ public: void visit(LottieStrokeObject *) {} void visitChildren(LottieGroupObject *obj) { for(auto child :obj->mChildren) { - child->accept(this); + child.get()->accept(this); if (mRepeaterFound) { - LottieRepeaterObject *repeater = static_cast<LottieRepeaterObject *>(child); - LottieShapeGroup *shapeGroup = new LottieShapeGroup(); - repeater->mChildren.push_back(shapeGroup); + LottieRepeaterObject *repeater = static_cast<LottieRepeaterObject *>(child.get()); + std::shared_ptr<LottieShapeGroup> sharedShapeGroup= std::make_shared<LottieShapeGroup>(); + LottieShapeGroup *shapeGroup = sharedShapeGroup.get(); + repeater->mChildren.push_back(sharedShapeGroup); // copy all the child of the object till repeater and // move that in to a group and then add that group to // the repeater object. @@ -31,9 +32,9 @@ public: break; // we shouldn't copy the trim as trim operation is // already applied to the objects. - if (cpChild->type() == LottieObject::Type::Trim) + if (cpChild.get()->type() == LottieObject::Type::Trim) continue; - shapeGroup->mChildren.push_back(cpChild->copy()); + shapeGroup->mChildren.push_back(cpChild); } mRepeaterFound = false; } @@ -56,8 +57,9 @@ void LottieComposition::processRepeaterObjects() */ LottieGroupObject::LottieGroupObject(const LottieGroupObject &other):LottieObject(other.mType) { + sgDebug<<"We Shouldn't come here ************************"; for(auto child: other.mChildren) { - mChildren.push_back(child->copy()); + mChildren.push_back(child); } } diff --git a/ssg/src/lottie/lottiemodel.h b/ssg/src/lottie/lottiemodel.h index 52fd1e30a7..29e8fbe65b 100644 --- a/ssg/src/lottie/lottiemodel.h +++ b/ssg/src/lottie/lottiemodel.h @@ -147,12 +147,12 @@ class LottieGroupObject: public LottieObject public: LottieGroupObject(LottieObject::Type type):LottieObject(type){} LottieGroupObject(const LottieGroupObject &other); - ~LottieGroupObject() { - for(auto child : mChildren) - delete child; - } +// ~LottieGroupObject() { +// for(auto child : mChildren) +// delete child; +// } public: - std::vector<LottieObject *> mChildren; + std::vector<std::shared_ptr<LottieObject>> mChildren; }; class LottieShapeGroup : public LottieGroupObject @@ -204,7 +204,7 @@ public: long mStartTime; LottieBlendMode mBlendMode; float mTimeStreatch; - LottieTransform *mTransform; + std::shared_ptr<LottieObject> mTransform; }; class LottieTransform : public LottieObject @@ -351,13 +351,12 @@ public: {visitor->visit(this); visitor->visitChildren(this);} LottieRepeaterObject():LottieGroupObject(LottieObject::Type::Repeater), mCopies(0), - mOffset(0), - mTransform(nullptr){} + mOffset(0){} LottieObject *copy() {return new LottieRepeaterObject(*this);} public: LottieAnimatable<float> mCopies; LottieAnimatable<float> mOffset; - LottieTransform *mTransform; + std::shared_ptr<LottieObject> mTransform; }; diff --git a/ssg/src/lottie/lottieparser.cpp b/ssg/src/lottie/lottieparser.cpp index 0335babcd3..725d9b88ff 100644 --- a/ssg/src/lottie/lottieparser.cpp +++ b/ssg/src/lottie/lottieparser.cpp @@ -135,24 +135,24 @@ public: JoinStyle getLineJoin(); LottieTrimObject::TrimType getTrimType(); - LottieComposition *parseComposition(); + std::shared_ptr<LottieComposition> parseComposition(); void parseLayers(LottieComposition *comp); - LottieLayer *parseLayer(); + std::shared_ptr<LottieObject> parseLayer(); void parseShapesAttr(LottieLayer *layer); void parseObject(LottieGroupObject *parent); - LottieObject* parseObjectTypeAttr(); - LottieObject *parseGroupObject(); - LottieObject *parseRectObject(); - LottieObject *parseEllipseObject(); - LottieObject *parseShapeObject(); - - LottieTransform *parseTransformObject(); - LottieObject *parseFillObject(); - LottieObject *parseGradientFillObject(); - LottieObject *parseStrokeObject(); - LottieObject *parseGradientStrokeObject(); - LottieObject *parseTrimObject(); - LottieObject *parseReapeaterObject(); + std::shared_ptr<LottieObject> parseObjectTypeAttr(); + std::shared_ptr<LottieObject> parseGroupObject(); + std::shared_ptr<LottieObject> parseRectObject(); + std::shared_ptr<LottieObject> parseEllipseObject(); + std::shared_ptr<LottieObject> parseShapeObject(); + + std::shared_ptr<LottieObject> parseTransformObject(); + std::shared_ptr<LottieObject> parseFillObject(); + std::shared_ptr<LottieObject> parseGradientFillObject(); + std::shared_ptr<LottieObject> parseStrokeObject(); + std::shared_ptr<LottieObject> parseGradientStrokeObject(); + std::shared_ptr<LottieObject> parseTrimObject(); + std::shared_ptr<LottieObject> parseReapeaterObject(); SGPointF parseInperpolatorPoint(); void parseArrayValue(SGPointF &pt); @@ -425,11 +425,13 @@ SGRect LottieParser::getRect() return r; } -LottieComposition *LottieParser::parseComposition() +std::shared_ptr<LottieComposition> +LottieParser::parseComposition() { RAPIDJSON_ASSERT(PeekType() == kObjectType); EnterObject(); - LottieComposition *comp = new LottieComposition(); + std::shared_ptr<LottieComposition> sharedComposition = std::make_shared<LottieComposition>(); + LottieComposition *comp = sharedComposition.get(); compRef = comp; while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "w")) { @@ -459,10 +461,11 @@ LottieComposition *LottieParser::parseComposition() // update the static property of Composition bool staticFlag = true; for (auto child : comp->mChildren) { - staticFlag &= child->isStatic(); + staticFlag &= child.get()->isStatic(); } comp->setStatic(staticFlag); - return comp; + + return sharedComposition; } void LottieParser::parseLayers(LottieComposition *composition) @@ -470,7 +473,7 @@ void LottieParser::parseLayers(LottieComposition *composition) RAPIDJSON_ASSERT(PeekType() == kArrayType); EnterArray(); while (NextArrayValue()) { - auto layer = parseLayer(); + std::shared_ptr<LottieObject> layer = parseLayer(); composition->mChildren.push_back(layer); } } @@ -479,10 +482,12 @@ void LottieParser::parseLayers(LottieComposition *composition) * https://github.com/airbnb/lottie-web/blob/master/docs/json/layers/shape.json * */ -LottieLayer * LottieParser::parseLayer() +std::shared_ptr<LottieObject> +LottieParser::parseLayer() { RAPIDJSON_ASSERT(PeekType() == kObjectType); - LottieLayer *layer = new LottieLayer(); + std::shared_ptr<LottieLayer> sharedLayer = std::make_shared<LottieLayer>(); + LottieLayer *layer = sharedLayer.get(); EnterObject(); while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "ty")) { /* Type of layer: Shape. Value 4.*/ @@ -526,13 +531,13 @@ LottieLayer * LottieParser::parseLayer() // update the static property of layer bool staticFlag = true; for (auto child : layer->mChildren) { - staticFlag &= child->isStatic(); + staticFlag &= child.get()->isStatic(); } layer->setStatic(staticFlag && layer->mTransform->isStatic()); - return layer; + return sharedLayer; } void LottieParser::parseShapesAttr(LottieLayer *layer) @@ -544,7 +549,7 @@ void LottieParser::parseShapesAttr(LottieLayer *layer) } } -LottieObject* +std::shared_ptr<LottieObject> LottieParser::parseObjectTypeAttr() { RAPIDJSON_ASSERT(PeekType() == kStringType); @@ -591,10 +596,12 @@ LottieParser::parseObject(LottieGroupObject *parent) } } -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseGroupObject() { - LottieShapeGroup *group = new LottieShapeGroup(); + std::shared_ptr<LottieShapeGroup> sharedGroup = std::make_shared<LottieShapeGroup>(); + + LottieShapeGroup *group = sharedGroup.get(); while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "it")) { RAPIDJSON_ASSERT(PeekType() == kArrayType); @@ -609,19 +616,22 @@ LottieParser::parseGroupObject() } bool staticFlag = true; for (auto child : group->mChildren) { - staticFlag &= child->isStatic(); + staticFlag &= child.get()->isStatic(); } group->setStatic(staticFlag); - return group; + + return sharedGroup; } /* * https://github.com/airbnb/lottie-web/blob/master/docs/json/shapes/rect.json */ -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseRectObject() { - LottieRectObject *obj = new LottieRectObject(); + std::shared_ptr<LottieRectObject> sharedRect = std::make_shared<LottieRectObject>(); + LottieRectObject *obj = sharedRect.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "p")) { parseProperty(obj->mPos); @@ -638,16 +648,18 @@ LottieParser::parseRectObject() obj->setStatic(obj->mPos.isStatic() && obj->mSize.isStatic() && obj->mRound.isStatic()); - return obj; + return sharedRect; } /* * https://github.com/airbnb/lottie-web/blob/master/docs/json/shapes/ellipse.json */ -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseEllipseObject() { - LottieEllipseObject *obj = new LottieEllipseObject(); + std::shared_ptr<LottieEllipseObject> sharedEllipse = std::make_shared<LottieEllipseObject>(); + LottieEllipseObject *obj = sharedEllipse.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "p")) { parseProperty(obj->mPos); @@ -659,16 +671,18 @@ LottieParser::parseEllipseObject() } obj->setStatic(obj->mPos.isStatic() && obj->mSize.isStatic()); - return obj; + return sharedEllipse; } /* * https://github.com/airbnb/lottie-web/blob/master/docs/json/properties/shape.json */ -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseShapeObject() { - LottieShapeObject *obj = new LottieShapeObject(); + std::shared_ptr<LottieShapeObject> sharedShape = std::make_shared<LottieShapeObject>(); + LottieShapeObject *obj = sharedShape.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "ks")) { parseShapeProperty(obj->mShape); @@ -683,7 +697,8 @@ LottieParser::parseShapeObject() } obj->process(); obj->setStatic(obj->mShape.isStatic()); - return obj; + + return sharedShape; } LottieTrimObject::TrimType @@ -706,10 +721,12 @@ LottieParser::getTrimType() /* * https://github.com/airbnb/lottie-web/blob/master/docs/json/shapes/trim.json */ -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseTrimObject() { - LottieTrimObject *obj = new LottieTrimObject(); + std::shared_ptr<LottieTrimObject> sharedTrim = std::make_shared<LottieTrimObject>(); + LottieTrimObject *obj = sharedTrim.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "s")) { parseProperty(obj->mStart); @@ -729,13 +746,16 @@ LottieParser::parseTrimObject() obj->setStatic(obj->mStart.isStatic() && obj->mEnd.isStatic() && obj->mOffset.isStatic()); - return obj; + + return sharedTrim; } -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseReapeaterObject() { - LottieRepeaterObject *obj = new LottieRepeaterObject(); + std::shared_ptr<LottieRepeaterObject> sharedRepeater = std::make_shared<LottieRepeaterObject>(); + LottieRepeaterObject *obj = sharedRepeater.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "c")) { parseProperty(obj->mCopies); @@ -753,17 +773,20 @@ LottieParser::parseReapeaterObject() obj->setStatic(obj->mCopies.isStatic() && obj->mOffset.isStatic() && obj->mTransform->isStatic()); - return obj; + + return sharedRepeater; } /* * https://github.com/airbnb/lottie-web/blob/master/docs/json/shapes/transform.json */ -LottieTransform * +std::shared_ptr<LottieObject> LottieParser::parseTransformObject() { - LottieTransform *obj = new LottieTransform(); + std::shared_ptr<LottieTransform> sharedTransform = std::make_shared<LottieTransform>(); + LottieTransform *obj = sharedTransform.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "a")) { parseProperty(obj->mAnchor); @@ -790,16 +813,19 @@ LottieParser::parseTransformObject() obj->mSkew.isStatic() && obj->mSkewAxis.isStatic() && obj->mOpacity.isStatic() ); - return obj; + + return sharedTransform; } /* * https://github.com/airbnb/lottie-web/blob/master/docs/json/shapes/fill.json */ -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseFillObject() { - LottieFillObject *obj = new LottieFillObject(); + std::shared_ptr<LottieFillObject> sharedFill = std::make_shared<LottieFillObject>(); + LottieFillObject *obj = sharedFill.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "c")) { parseProperty(obj->mColor); @@ -816,7 +842,8 @@ LottieParser::parseFillObject() } obj->setStatic(obj->mColor.isStatic() && obj->mOpacity.isStatic()); - return obj; + + return sharedFill; } /* @@ -860,10 +887,12 @@ JoinStyle LottieParser::getLineJoin() /* * https://github.com/airbnb/lottie-web/blob/master/docs/json/shapes/stroke.json */ -LottieObject * +std::shared_ptr<LottieObject> LottieParser::parseStrokeObject() { - LottieStrokeObject *obj = new LottieStrokeObject(); + std::shared_ptr<LottieStrokeObject> sharedStroke = std::make_shared<LottieStrokeObject>(); + LottieStrokeObject *obj = sharedStroke.get(); + while (const char* key = NextObjectKey()) { if (0 == strcmp(key, "c")) { parseProperty(obj->mColor); @@ -890,7 +919,8 @@ LottieParser::parseStrokeObject() obj->setStatic(obj->mColor.isStatic() && obj->mOpacity.isStatic() && obj->mWidth.isStatic()); - return obj; + + return sharedStroke; } void LottieParser::parseArrayValue(LottieColor &color) @@ -1240,7 +1270,7 @@ public: } void visitChildren(LottieGroupObject *obj) { for(auto child :obj->mChildren) - child->accept(this); + child.get()->accept(this); switch (obj->type()) { case LottieObject::Type::Layer: sgDebug<<"[LAYER End ]"; @@ -1266,15 +1296,15 @@ SGJson::SGJson(const char *data) t.start(); LottieParser r(const_cast<char *>(data)); - LottieComposition *comp = r.parseComposition(); + std::shared_ptr<LottieComposition> comp = r.parseComposition(); #ifdef DEBUG_PARSER LottieObjectInspector inspector; - comp->accept(&inspector); + comp.get()->accept(&inspector); #endif - comp->processRepeaterObjects(); + comp.get()->processRepeaterObjects(); #ifdef DEBUG_PARSER sgDebug<<"******** After Repeater Processing **********"; - comp->accept(&inspector); + comp.get()->accept(&inspector); #endif sgCritical<<"Parsing time = "<<t.elapsed()<<" ms"; } |