From: subhransu mohanty Date: Fri, 24 Aug 2018 06:44:51 +0000 (+0900) Subject: lottie: refactor the viewitems to have a parent, to optimize the size of the structure. X-Git-Tag: submit/tizen/20180917.042405~64 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d2fc8fc57637be9350ec53c7d381674fa5fa2a1c;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie: refactor the viewitems to have a parent, to optimize the size of the structure. 1. we could move as much common data to parent structure and then keep the parent pointer in the child. 2. move expensive vmatrix data to parent. Change-Id: Icfd3aa885ebfce5c9555f8b107d3b885827ebedf --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index 35be998..992009b 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -548,7 +548,10 @@ void LOTContentGroupItem::addChildren(LOTGroupData *data) for (auto &i : data->mChildren) { auto content = LOTShapeLayerItem::createContentItem(i.get()); - if (content) mContents.push_back(std::move(content)); + if (content) { + content->setParent(this); + mContents.push_back(std::move(content)); + } } } @@ -574,6 +577,8 @@ void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix, } } + mMatrix = m; + for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) { (*i)->update(frameNo, m, alpha, newFlag); } @@ -635,7 +640,7 @@ void LOTContentGroupItem::processTrimItems( } } -void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix, +void LOTPathDataItem::update(int frameNo, const VMatrix &, float, const DirtyFlag &flag) { mPathChanged = false; @@ -651,7 +656,6 @@ void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix, // 3. compute the final path with parentMatrix if ((flag & DirtyFlagBit::Matrix) || mPathChanged) { - mMatrix = parentMatrix; mPathChanged = true; } } @@ -660,7 +664,7 @@ const VPath & LOTPathDataItem::finalPath() { if (mPathChanged || mNeedUpdate) { mFinalPath.clone(mTemp); - mFinalPath.transform(mMatrix); + mFinalPath.transform(static_cast(parent())->matrix()); mNeedUpdate = false; } return mFinalPath; @@ -755,7 +759,6 @@ void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix, { mRenderNodeUpdate = true; mParentAlpha = parentAlpha; - mParentMatrix = parentMatrix; mFlag = flag; mFrameNo = frameNo; @@ -833,7 +836,7 @@ LOTGFillItem::LOTGFillItem(LOTGFillData *data) void LOTGFillItem::updateContent(int frameNo) { mData->update(mGradient, frameNo); - mGradient->mMatrix = mParentMatrix; + mGradient->mMatrix = static_cast(parent())->matrix(); mFillRule = mData->fillRule(); } @@ -882,7 +885,7 @@ void LOTStrokeItem::updateRenderNode() color.setAlpha(color.a * parentAlpha()); VBrush brush(color); mDrawable->setBrush(brush); - float scale = getScale(mParentMatrix); + float scale = getScale(static_cast(parent())->matrix()); mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit, mWidth * scale); if (mDashArraySize) { @@ -901,7 +904,7 @@ LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data) void LOTGStrokeItem::updateContent(int frameNo) { mData->update(mGradient, frameNo); - mGradient->mMatrix = mParentMatrix; + mGradient->mMatrix = static_cast(parent())->matrix(); mCap = mData->capStyle(); mJoin = mData->joinStyle(); mMiterLimit = mData->meterLimit(); @@ -913,7 +916,7 @@ void LOTGStrokeItem::updateContent(int frameNo) void LOTGStrokeItem::updateRenderNode() { - float scale = getScale(mParentMatrix); + float scale = getScale(mGradient->mMatrix); mDrawable->setBrush(VBrush(mGradient.get())); mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit, mWidth * scale); diff --git a/src/lottie/lottieitem.h b/src/lottie/lottieitem.h index b2d8a8f..1396311 100644 --- a/src/lottie/lottieitem.h +++ b/src/lottie/lottieitem.h @@ -173,6 +173,10 @@ public: virtual ~LOTContentItem(){} virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) = 0; virtual void renderList(std::vector &){} + void setParent(LOTContentItem *parent) {mParent = parent;} + LOTContentItem *parent() const {return mParent;} +private: + LOTContentItem *mParent{nullptr}; }; class LOTContentGroupItem: public LOTContentItem @@ -185,9 +189,11 @@ public: void processTrimItems(std::vector &list); void processPaintItems(std::vector &list); void renderList(std::vector &list) final; + const VMatrix & matrix() const { return mMatrix;} private: LOTShapeGroupData *mData; std::vector> mContents; + VMatrix mMatrix; }; class LOTPathDataItem : public LOTContentItem @@ -200,17 +206,16 @@ public: const VPath &finalPath(); void updatePath(const VPath &path) {mTemp.clone(path); mPathChanged = true; mNeedUpdate = true;} bool staticPath() const { return mStaticPath; } +protected: + virtual void updatePath(VPath& path, int frameNo) = 0; + virtual bool hasChanged(int frameNo) = 0; private: - bool mStaticPath; VPath mLocalPath; VPath mTemp; VPath mFinalPath; - VMatrix mMatrix; bool mPathChanged{true}; bool mNeedUpdate{true}; -protected: - virtual void updatePath(VPath& path, int frameNo) = 0; - virtual bool hasChanged(int frameNo) = 0; + bool mStaticPath; }; class LOTRectItem: public LOTPathDataItem @@ -223,9 +228,9 @@ protected: struct Cache { int mFrameNo{-1}; + float mRoundness; VPointF mPos; VPointF mSize; - float mRoundness; }; Cache mCache; @@ -365,7 +370,6 @@ protected: inline float parentAlpha() const {return mParentAlpha;} public: float mParentAlpha; - VMatrix mParentMatrix; VPath mPath; DirtyFlag mFlag; int mFrameNo;