lottie: refactor the viewitems to have a parent, to optimize the size of the structure. 65/187565/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 24 Aug 2018 06:44:51 +0000 (15:44 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Fri, 24 Aug 2018 06:44:51 +0000 (15:44 +0900)
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

src/lottie/lottieitem.cpp
src/lottie/lottieitem.h

index 35be998c610de794d215b20c1ef2f6416f73b5c9..992009b5e2c4ebdb73525584044e190f70c7b002 100644 (file)
@@ -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<LOTContentGroupItem *>(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<LOTContentGroupItem *>(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<LOTContentGroupItem *>(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<LOTContentGroupItem *>(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);
index b2d8a8ff6d4434eef6ddf42ffa9e2dac75cf4fcd..139631185010d4c441e73ade9569e62cadd5cfa4 100644 (file)
@@ -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<VDrawable *> &){}
+   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<LOTPathDataItem *> &list);
    void processPaintItems(std::vector<LOTPathDataItem *> &list);
    void renderList(std::vector<VDrawable *> &list) final;
+   const VMatrix & matrix() const { return mMatrix;}
 private:
    LOTShapeGroupData                             *mData;
    std::vector<std::unique_ptr<LOTContentItem>>   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;