lottie/optimization: optimize reuse of vpath object to reduce memory alloc/dealloc 83/195183/2
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 11 Dec 2018 09:39:58 +0000 (18:39 +0900)
committerHermet Park <chuneon.park@samsung.com>
Wed, 12 Dec 2018 02:03:17 +0000 (02:03 +0000)
Change-Id: Ide35d3e56a77924a9706340c71091865125b016b

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

index 2494d360c95bfde5fa14347a1a4f5da4c447289f..9bb61e7fbdc4f52ab6c3a58b4590ea08796134b8 100644 (file)
@@ -151,8 +151,7 @@ void LOTMaskItem::update(int frameNo, const VMatrix &parentMatrix,
     opacity = opacity * parentAlpha;
     mCombinedAlpha = opacity;
 
-    mFinalPath.reset();
-    mFinalPath.addPath(mLocalPath);
+    mFinalPath.clone(mLocalPath);
     mFinalPath.transform(parentMatrix);
 
     VPath tmp = mFinalPath;
@@ -787,6 +786,18 @@ void LOTContentGroupItem::processTrimItems(
     }
 }
 
+/*
+ * LOTPathDataItem uses 3 path objects for path object reuse.
+ * mLocalPath -  keeps track of the local path of the item before
+ * applying path operation and transformation.
+ * mTemp - keeps a referece to the mLocalPath and can be updated by the
+ *          path operation objects(trim, merge path),
+ *  mFinalPath - it takes a deep copy of the intermediate path(mTemp) each time
+ *  when the path is dirty(so if path changes every frame we don't realloc just copy to the
+ *  final path).
+ * NOTE: As path objects are COW objects we have to be carefull about the refcount so that
+ * we don't generate deep copy while modifying the path objects.
+ */
 void LOTPathDataItem::update(int frameNo, const VMatrix &,
                              float, const DirtyFlag &flag)
 {
@@ -794,11 +805,17 @@ void LOTPathDataItem::update(int frameNo, const VMatrix &,
 
     // 1. update the local path if needed
     if (hasChanged(frameNo)) {
+        // loose the reference to mLocalPath if any
+        // from the last frame update.
+        mTemp = VPath();
+
         updatePath(mLocalPath, frameNo);
         mPathChanged = true;
         mNeedUpdate = true;
     }
-
+    // 2. keep a reference path in temp in case there is some
+    // path operation like trim which will update the path.
+    // we don't want to update the local path.
     mTemp = mLocalPath;
 
     // 3. compute the final path with parentMatrix
index 695ac451078c9f1450bf73c18648fe5a43667114..f2680c46c474701aec6766b78e2defdd362775e1 100644 (file)
@@ -222,7 +222,7 @@ public:
    bool dirty() const {return mPathChanged;}
    const VPath &localPath() const {return mTemp;}
    const VPath &finalPath();
-   void updatePath(const VPath &path) {mTemp.clone(path); mPathChanged = true; mNeedUpdate = true;}
+   void updatePath(const VPath &path) {mTemp = path; mPathChanged = true; mNeedUpdate = true;}
    bool staticPath() const { return mStaticPath; }
 protected:
    virtual void updatePath(VPath& path, int frameNo) = 0;