summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu sekhar mohanty <smohantty@subhransus-MacBook-Air.local>2017-12-20 22:55:16 +0900
committersubhransu mohanty <sub.mohanty@samsung.com>2018-04-12 13:51:53 +0900
commitfe000629c44e3eec81ec7c5fe5d74ce92f7301f2 (patch)
treead3b537bdb9ef8e8fd87464791b93ce9a6550e7f
parentf27b25b4e68b38fb1399b17d5b0c21d07f231422 (diff)
lottie: added paint node processor
-rw-r--r--ssg/example/main.cpp2
-rw-r--r--ssg/src/lottie/lottiemodel.cpp105
-rw-r--r--ssg/src/lottie/lottiemodel.h14
-rw-r--r--ssg/src/lottie/lottieparser.cpp24
4 files changed, 84 insertions, 61 deletions
diff --git a/ssg/example/main.cpp b/ssg/example/main.cpp
index 5e2398ef9a..84f8db0815 100644
--- a/ssg/example/main.cpp
+++ b/ssg/example/main.cpp
@@ -14,7 +14,7 @@ using namespace std;
14int main() 14int main()
15{ 15{
16 std::string filepath = DEMO_DIR; 16 std::string filepath = DEMO_DIR;
17 filepath += "withrepeater.json"; 17 filepath += "LightBulb.json";
18 initialize(GuaranteedLogger(), "/tmp/", "ssglog", 1); 18 initialize(GuaranteedLogger(), "/tmp/", "ssglog", 1);
19 set_log_level(LogLevel::INFO); 19 set_log_level(LogLevel::INFO);
20 //SGJson json; 20 //SGJson json;
diff --git a/ssg/src/lottie/lottiemodel.cpp b/ssg/src/lottie/lottiemodel.cpp
index e79f122aa4..5852d433b1 100644
--- a/ssg/src/lottie/lottiemodel.cpp
+++ b/ssg/src/lottie/lottiemodel.cpp
@@ -48,60 +48,95 @@ public:
48class LottiePathOperationProcesser : public LottieObjectVisitor 48class LottiePathOperationProcesser : public LottieObjectVisitor
49{ 49{
50public: 50public:
51 LottiePathOperationProcesser():mPathOperator(false), mPaintNode(false), mPathOperationCount(0){} 51 LottiePathOperationProcesser():mPathOperator(false), mDrawableNode(false){}
52 void visit(LottieComposition *obj) {} 52 void visit(LottieComposition *obj) {}
53 void visit(LottieLayer *obj) {} 53 void visit(LottieLayer *obj) {}
54 void visit(LottieTransform *) {} 54 void visit(LottieTransform *) {}
55 void visit(LottieShapeGroup *obj) {} 55 void visit(LottieShapeGroup *obj) {}
56 void visit(LottieShapeObject *) {mPaintNode = true;} 56 void visit(LottieShapeObject *) {mDrawableNode = true;}
57 void visit(LottieRectObject *) {mPaintNode = true;} 57 void visit(LottieRectObject *) {mDrawableNode = true;}
58 void visit(LottieEllipseObject *) { mPaintNode = true;} 58 void visit(LottieEllipseObject *) { mDrawableNode = true;}
59 void visit(LottieTrimObject *) { 59 void visit(LottieTrimObject *) { mPathOperator = true;}
60 mPathOperator = true;
61 }
62 void visit(LottieRepeaterObject *) {} 60 void visit(LottieRepeaterObject *) {}
63 void visit(LottieFillObject *) {} 61 void visit(LottieFillObject *) {}
64 void visit(LottieStrokeObject *) {} 62 void visit(LottieStrokeObject *) {}
65 void visitChildren(LottieGroupObject *obj) { 63 void visitChildren(LottieGroupObject *obj) {
64 int curOpCount = mPathOperationList.size();
66 mPathOperator = false; 65 mPathOperator = false;
67 mPaintNode = false; 66 mDrawableNode = false;
68 mPathOperationList.push_back(std::vector<std::shared_ptr<LottieObject>>());
69 for (auto i = obj->mChildren.rbegin(); i != obj->mChildren.rend(); ++i) { 67 for (auto i = obj->mChildren.rbegin(); i != obj->mChildren.rend(); ++i) {
70 auto child = *i; 68 auto child = *i;
71 child.get()->accept(this); 69 child.get()->accept(this);
72 if (mPathOperator) { 70 if (mPathOperator) {
73 mPathOperationList.back().push_back(child); 71 mPathOperationList.push_back(child);
74 mPathOperationCount++; 72 obj->mChildren.erase(std::next(i).base());
75 } 73 }
76 if (mPaintNode && mPathOperationCount) { 74 if (mDrawableNode) {
77 // put it in the list 75 // put it in the list
78 updatePaintObject(static_cast<LottieDrawableObject *>(child.get())); 76 updateDrawableObject(static_cast<LottieDrawableObject *>(child.get()));
79 } 77 }
80 mPathOperator = false; 78 mPathOperator = false;
81 mPaintNode = false; 79 mDrawableNode = false;
82 } 80 }
83 mPathOperationCount -= mPathOperationList.back().size(); 81 mPathOperationList.erase(mPathOperationList.begin() + curOpCount, mPathOperationList.end());
84 mPathOperationList.pop_back();
85 } 82 }
86 83
87 void updatePaintObject(LottieDrawableObject *drawable) { 84 void updateDrawableObject(LottieDrawableObject *drawable) {
88 sgDebug<<"For each path START";
89 for (auto i = mPathOperationList.rbegin(); i != mPathOperationList.rend(); ++i) { 85 for (auto i = mPathOperationList.rbegin(); i != mPathOperationList.rend(); ++i) {
90 auto trimList = *i; 86 drawable->mPathOperations.push_back(*i);
91 sgDebug<<"For each level START";
92 for (auto j = trimList.rbegin(); j != trimList.rend(); ++j) {
93 drawable->mPathOperations.push_back(*j);
94 sgDebug<<"Added path operaton to ";
95 }
96 sgDebug<<"For each level END";
97 } 87 }
98 sgDebug<<"For each path END";
99 } 88 }
100public: 89public:
101 bool mPathOperator; 90 bool mPathOperator;
102 bool mPaintNode; 91 bool mDrawableNode;
103 std::vector<std::vector<std::shared_ptr<LottieObject>>> mPathOperationList; 92 std::vector<std::shared_ptr<LottieObject>> mPathOperationList;
104 int mPathOperationCount; 93};
94
95class LottiePaintOperationProcesser : public LottieObjectVisitor
96{
97public:
98 LottiePaintOperationProcesser():mPaintOperator(false), mDrawableNode(false){}
99 void visit(LottieComposition *obj) {}
100 void visit(LottieLayer *obj) {}
101 void visit(LottieTransform *) {}
102 void visit(LottieShapeGroup *obj) {}
103 void visit(LottieShapeObject *) {mDrawableNode = true;}
104 void visit(LottieRectObject *) {mDrawableNode = true;}
105 void visit(LottieEllipseObject *) { mDrawableNode = true;}
106 void visit(LottieTrimObject *) {}
107 void visit(LottieRepeaterObject *) {}
108 void visit(LottieFillObject *) { mPaintOperator = true;}
109 void visit(LottieStrokeObject *) { mPaintOperator = true;}
110 void visitChildren(LottieGroupObject *obj) {
111 int curOpCount = mPaintOperationList.size();
112 mPaintOperator = false;
113 mDrawableNode = false;
114 for (auto i = obj->mChildren.rbegin(); i != obj->mChildren.rend(); ++i) {
115 auto child = *i;
116 child.get()->accept(this);
117 if (mPaintOperator) {
118 mPaintOperationList.push_back(child);
119 obj->mChildren.erase(std::next(i).base());
120 }
121 if (mDrawableNode) {
122 // put it in the list
123 updateDrawableObject(static_cast<LottieDrawableObject *>(child.get()));
124 }
125 mPaintOperator = false;
126 mDrawableNode = false;
127 }
128 mPaintOperationList.erase(mPaintOperationList.begin() + curOpCount, mPaintOperationList.end());
129 }
130
131 void updateDrawableObject(LottieDrawableObject *drawable) {
132 for (auto i = mPaintOperationList.begin(); i != mPaintOperationList.end(); ++i) {
133 drawable->mPaintOperations.push_back(*i);
134 }
135 }
136public:
137 bool mPaintOperator;
138 bool mDrawableNode;
139 std::vector<std::shared_ptr<LottieObject>> mPaintOperationList;
105}; 140};
106 141
107 142
@@ -117,16 +152,10 @@ void LottieComposition::processPathOperatorObjects()
117 accept(&visitor); 152 accept(&visitor);
118} 153}
119 154
120/* 155void LottieComposition::processPaintOperatorObjects()
121 * makes a deep copy of the object as well as all its children
122 *
123 */
124LottieGroupObject::LottieGroupObject(const LottieGroupObject &other):LottieObject(other.mType)
125{ 156{
126 sgDebug<<"We Shouldn't come here ************************"; 157 LottiePaintOperationProcesser visitor;
127 for(auto child: other.mChildren) { 158 accept(&visitor);
128 mChildren.push_back(child);
129 }
130} 159}
131 160
132/* 161/*
diff --git a/ssg/src/lottie/lottiemodel.h b/ssg/src/lottie/lottiemodel.h
index 48be5e92bc..623285c155 100644
--- a/ssg/src/lottie/lottiemodel.h
+++ b/ssg/src/lottie/lottiemodel.h
@@ -136,7 +136,6 @@ public:
136 LottieObject(LottieObject::Type type): mStatic(true), mType(type){} 136 LottieObject(LottieObject::Type type): mStatic(true), mType(type){}
137 bool isStatic() {return mStatic;} 137 bool isStatic() {return mStatic;}
138 void setStatic(bool value) {mStatic = value;} 138 void setStatic(bool value) {mStatic = value;}
139 virtual LottieObject *copy() = 0;
140public: 139public:
141 bool mStatic; 140 bool mStatic;
142 LottieObject::Type mType; 141 LottieObject::Type mType;
@@ -146,7 +145,6 @@ class LottieGroupObject: public LottieObject
146{ 145{
147public: 146public:
148 LottieGroupObject(LottieObject::Type type):LottieObject(type){} 147 LottieGroupObject(LottieObject::Type type):LottieObject(type){}
149 LottieGroupObject(const LottieGroupObject &other);
150public: 148public:
151 std::vector<std::shared_ptr<LottieObject>> mChildren; 149 std::vector<std::shared_ptr<LottieObject>> mChildren;
152}; 150};
@@ -158,7 +156,6 @@ public:
158 {visitor->visit(this); visitor->visitChildren(this);} 156 {visitor->visit(this); visitor->visitChildren(this);}
159 157
160 LottieShapeGroup():LottieGroupObject(LottieObject::Type::ShapeGroup){} 158 LottieShapeGroup():LottieGroupObject(LottieObject::Type::ShapeGroup){}
161 LottieObject *copy() {return new LottieShapeGroup(*this);}
162}; 159};
163 160
164class LottieTransform; 161class LottieTransform;
@@ -166,11 +163,11 @@ class LottieComposition : public LottieGroupObject
166{ 163{
167public: 164public:
168 void processPathOperatorObjects(); 165 void processPathOperatorObjects();
166 void processPaintOperatorObjects();
169 void processRepeaterObjects(); 167 void processRepeaterObjects();
170 void accept(LottieObjectVisitor *visitor) override 168 void accept(LottieObjectVisitor *visitor) override
171 {visitor->visit(this); visitor->visitChildren(this);} 169 {visitor->visit(this); visitor->visitChildren(this);}
172 LottieComposition():LottieGroupObject(LottieObject::Type::Composition){} 170 LottieComposition():LottieGroupObject(LottieObject::Type::Composition){}
173 LottieObject *copy() {return new LottieComposition(*this);}
174public: 171public:
175 SGRect mBound; 172 SGRect mBound;
176 bool mAnimation = false; 173 bool mAnimation = false;
@@ -189,7 +186,6 @@ public:
189 void accept(LottieObjectVisitor *visitor) override 186 void accept(LottieObjectVisitor *visitor) override
190 {visitor->visit(this); visitor->visitChildren(this);} 187 {visitor->visit(this); visitor->visitChildren(this);}
191 LottieLayer():LottieGroupObject(LottieObject::Type::Layer),mParentId(-1),mId(-1){} 188 LottieLayer():LottieGroupObject(LottieObject::Type::Layer),mParentId(-1),mId(-1){}
192 LottieObject *copy() {return new LottieLayer(*this);}
193public: 189public:
194 SGRect mBound; 190 SGRect mBound;
195 int mlayerType; //lottie layer type (solid/shape/precomp) 191 int mlayerType; //lottie layer type (solid/shape/precomp)
@@ -217,7 +213,6 @@ public:
217 mOpacity(100), 213 mOpacity(100),
218 mSkew(0), 214 mSkew(0),
219 mSkewAxis(0){} 215 mSkewAxis(0){}
220 LottieObject *copy() {return new LottieTransform(*this);}
221public: 216public:
222 LottieAnimatable<float> mRotation; /* "r" */ 217 LottieAnimatable<float> mRotation; /* "r" */
223 LottieAnimatable<SGPointF> mScale; /* "s" */ 218 LottieAnimatable<SGPointF> mScale; /* "s" */
@@ -234,7 +229,6 @@ public:
234 void accept(LottieObjectVisitor *visitor) final 229 void accept(LottieObjectVisitor *visitor) final
235 {visitor->visit(this);} 230 {visitor->visit(this);}
236 LottieFillObject():LottieObject(LottieObject::Type::Fill){} 231 LottieFillObject():LottieObject(LottieObject::Type::Fill){}
237 LottieObject *copy() {return new LottieFillObject(*this);}
238public: 232public:
239 LottieAnimatable<LottieColor> mColor; /* "c" */ 233 LottieAnimatable<LottieColor> mColor; /* "c" */
240 LottieAnimatable<int> mOpacity; /* "o" */ 234 LottieAnimatable<int> mOpacity; /* "o" */
@@ -247,7 +241,6 @@ public:
247 void accept(LottieObjectVisitor *visitor) final 241 void accept(LottieObjectVisitor *visitor) final
248 {visitor->visit(this);} 242 {visitor->visit(this);}
249 LottieStrokeObject():LottieObject(LottieObject::Type::Stroke){} 243 LottieStrokeObject():LottieObject(LottieObject::Type::Stroke){}
250 LottieObject *copy() {return new LottieStrokeObject(*this);}
251public: 244public:
252 LottieAnimatable<LottieColor> mColor; /* "c" */ 245 LottieAnimatable<LottieColor> mColor; /* "c" */
253 LottieAnimatable<int> mOpacity; /* "o" */ 246 LottieAnimatable<int> mOpacity; /* "o" */
@@ -292,7 +285,6 @@ public:
292 {visitor->visit(this);} 285 {visitor->visit(this);}
293 void process(); 286 void process();
294 LottieShapeObject():LottieDrawableObject(LottieObject::Type::Shape){} 287 LottieShapeObject():LottieDrawableObject(LottieObject::Type::Shape){}
295 LottieObject *copy() {return new LottieShapeObject(*this);}
296public: 288public:
297 LottieAnimatable<LottieShape> mShape; 289 LottieAnimatable<LottieShape> mShape;
298 bool mClosed = false; 290 bool mClosed = false;
@@ -307,7 +299,6 @@ public:
307 mPos(SGPointF(0,0)), 299 mPos(SGPointF(0,0)),
308 mSize(SGPointF(0,0)), 300 mSize(SGPointF(0,0)),
309 mRound(0){} 301 mRound(0){}
310 LottieObject *copy() {return new LottieRectObject(*this);}
311public: 302public:
312 LottieAnimatable<SGPointF> mPos; 303 LottieAnimatable<SGPointF> mPos;
313 LottieAnimatable<SGPointF> mSize; 304 LottieAnimatable<SGPointF> mSize;
@@ -322,7 +313,6 @@ public:
322 LottieEllipseObject():LottieDrawableObject(LottieObject::Type::Ellipse), 313 LottieEllipseObject():LottieDrawableObject(LottieObject::Type::Ellipse),
323 mPos(SGPointF(0,0)), 314 mPos(SGPointF(0,0)),
324 mSize(SGPointF(0,0)){} 315 mSize(SGPointF(0,0)){}
325 LottieObject *copy() {return new LottieEllipseObject(*this);}
326public: 316public:
327 LottieAnimatable<SGPointF> mPos; 317 LottieAnimatable<SGPointF> mPos;
328 LottieAnimatable<SGPointF> mSize; 318 LottieAnimatable<SGPointF> mSize;
@@ -342,7 +332,6 @@ public:
342 mEnd(0), 332 mEnd(0),
343 mOffset(0), 333 mOffset(0),
344 mTrimType(TrimType::Simultaneously){} 334 mTrimType(TrimType::Simultaneously){}
345 LottieObject *copy() {return new LottieTrimObject(*this);}
346public: 335public:
347 LottieAnimatable<float> mStart; 336 LottieAnimatable<float> mStart;
348 LottieAnimatable<float> mEnd; 337 LottieAnimatable<float> mEnd;
@@ -358,7 +347,6 @@ public:
358 LottieRepeaterObject():LottieGroupObject(LottieObject::Type::Repeater), 347 LottieRepeaterObject():LottieGroupObject(LottieObject::Type::Repeater),
359 mCopies(0), 348 mCopies(0),
360 mOffset(0){} 349 mOffset(0){}
361 LottieObject *copy() {return new LottieRepeaterObject(*this);}
362public: 350public:
363 LottieAnimatable<float> mCopies; 351 LottieAnimatable<float> mCopies;
364 LottieAnimatable<float> mOffset; 352 LottieAnimatable<float> mOffset;
diff --git a/ssg/src/lottie/lottieparser.cpp b/ssg/src/lottie/lottieparser.cpp
index 561e860c40..6fe3e3d159 100644
--- a/ssg/src/lottie/lottieparser.cpp
+++ b/ssg/src/lottie/lottieparser.cpp
@@ -5,7 +5,7 @@
5#include "lottiemodel.h" 5#include "lottiemodel.h"
6#include"sgelapsedtimer.h" 6#include"sgelapsedtimer.h"
7 7
8#define DEBUG_PARSER 8//#define DEBUG_PARSER
9 9
10RAPIDJSON_DIAG_PUSH 10RAPIDJSON_DIAG_PUSH
11#ifdef __GNUC__ 11#ifdef __GNUC__
@@ -1248,13 +1248,13 @@ public:
1248 sgDebug<<"[SHAPEGROP: START : static: "<<o->isStatic()<<" ]"; 1248 sgDebug<<"[SHAPEGROP: START : static: "<<o->isStatic()<<" ]";
1249 } 1249 }
1250 void visit(LottieShapeObject *s) { 1250 void visit(LottieShapeObject *s) {
1251 sgDebug<<"[SHAPE: static: "<<s->isStatic()<<" ]"; 1251 sgDebug<<"[SHAPE: static: "<<s->isStatic()<<" pthOps: "<<s->mPathOperations.size()<<" pntOps: "<<s->mPaintOperations.size()<<" ]";
1252 } 1252 }
1253 void visit(LottieRectObject *r) { 1253 void visit(LottieRectObject *r) {
1254 sgDebug<<"[RECT: static: "<<r->isStatic()<<" ]"; 1254 sgDebug<<"[RECT: static: "<<r->isStatic()<<" pthOps: "<<r->mPathOperations.size()<<" pntOps: "<<r->mPaintOperations.size()<<" ]";
1255 } 1255 }
1256 void visit(LottieEllipseObject *e) { 1256 void visit(LottieEllipseObject *e) {
1257 sgDebug<<"[ELLIPSE: static: "<<e->isStatic()<<" ]"; 1257 sgDebug<<"[ELLIPSE: static: "<<e->isStatic()<<" pthOps: "<<e->mPathOperations.size()<<" pntOps: "<<e->mPaintOperations.size()<<" ]";
1258 } 1258 }
1259 void visit(LottieTrimObject *t) { 1259 void visit(LottieTrimObject *t) {
1260 sgDebug<<"[TRIM: static: "<<t->isStatic()<<" ]"; 1260 sgDebug<<"[TRIM: static: "<<t->isStatic()<<" ]";
@@ -1297,17 +1297,23 @@ SGJson::SGJson(const char *data)
1297 LottieParser r(const_cast<char *>(data)); 1297 LottieParser r(const_cast<char *>(data));
1298 1298
1299 std::shared_ptr<LottieComposition> comp = r.parseComposition(); 1299 std::shared_ptr<LottieComposition> comp = r.parseComposition();
1300#ifdef DEBUG_PARSER 1300//#ifdef DEBUG_PARSER
1301 sgDebug<<"******* Before processing *************\n";
1302 sgDebug<<" ";
1303
1301 LottieObjectInspector inspector; 1304 LottieObjectInspector inspector;
1302 comp.get()->accept(&inspector); 1305 comp.get()->accept(&inspector);
1303#endif 1306//#endif
1304 comp.get()->processPathOperatorObjects(); 1307 comp.get()->processPathOperatorObjects();
1308 comp.get()->processPaintOperatorObjects();
1305 comp.get()->processRepeaterObjects(); 1309 comp.get()->processRepeaterObjects();
1306 1310
1307#ifdef DEBUG_PARSER 1311//#ifdef DEBUG_PARSER
1308 sgDebug<<"******** After Repeater Processing **********"; 1312 sgDebug<<" ";
1313 sgDebug<<"******** After Processing **********\n";
1309 comp.get()->accept(&inspector); 1314 comp.get()->accept(&inspector);
1310#endif 1315//#endif
1316 sgDebug<<" ";
1311 sgCritical<<"Parsing time = "<<t.elapsed()<<" ms"; 1317 sgCritical<<"Parsing time = "<<t.elapsed()<<" ms";
1312} 1318}
1313 1319