lottie/perf: Avoid triggering render of a paint node when final opacity is zero submit/tizen/20191013.215822
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 11 Oct 2019 06:05:13 +0000 (15:05 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 13 Oct 2019 21:29:10 +0000 (06:29 +0900)
src/lottie/lottieitem.cpp
src/lottie/lottieitem.h
src/vector/vglobal.h

index f8ec21a5282a3567125f7de5586086fc3972fe52..e195750f6cbc60c1e7a54c51b5d2c0b0e6d430cd 100644 (file)
@@ -1094,7 +1094,7 @@ void LOTPaintDataItem::update(int   frameNo, const VMatrix & parentMatrix,
                               float parentAlpha, const DirtyFlag &/*flag*/)
 {
     mRenderNodeUpdate = true;
-    updateContent(frameNo, parentMatrix, parentAlpha);
+    mContentToRender = updateContent(frameNo, parentMatrix, parentAlpha);
 }
 
 void LOTPaintDataItem::updateRenderNode()
@@ -1107,7 +1107,7 @@ void LOTPaintDataItem::updateRenderNode()
         }
     }
 
-    if (dirty) {
+    if (dirty || mPath.empty()) {
         mPath.reset();
 
         for (auto &i : mPathItems) {
@@ -1122,6 +1122,8 @@ void LOTPaintDataItem::updateRenderNode()
 
 void LOTPaintDataItem::renderList(std::vector<VDrawable *> &list)
 {
+    if (!mContentToRender) return;
+
     if (mRenderNodeUpdate) {
         updateRenderNode();
         mRenderNodeUpdate = false;
@@ -1141,13 +1143,18 @@ LOTFillItem::LOTFillItem(LOTFillData *data)
 {
 }
 
-void LOTFillItem::updateContent(int frameNo, const VMatrix &, float alpha)
+bool LOTFillItem::updateContent(int frameNo, const VMatrix &, float alpha)
 {
-    auto color = mModel.color(frameNo).toColor(mModel.opacity(frameNo));
-    color.setAlpha(uchar(color.a * alpha));
+    auto combinedAlpha = alpha * mModel.opacity(frameNo);
+    auto color = mModel.color(frameNo).toColor(combinedAlpha);
+
+    if (color.isTransparent()) return false;
+
     VBrush brush(color);
     mDrawable.setBrush(brush);
     mDrawable.setFillRule(mModel.fillRule());
+
+    return true;
 }
 
 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
@@ -1155,13 +1162,18 @@ LOTGFillItem::LOTGFillItem(LOTGFillData *data)
 {
 }
 
-void LOTGFillItem::updateContent(int frameNo, const VMatrix &matrix, float alpha)
+bool LOTGFillItem::updateContent(int frameNo, const VMatrix &matrix, float alpha)
 {
+    float combinedAlpha = alpha * mData->opacity(frameNo);
+    if (vIsZero(combinedAlpha)) return false;
+
     mData->update(mGradient, frameNo);
-    mGradient->setAlpha(mData->opacity(frameNo) * alpha);
+    mGradient->setAlpha(combinedAlpha);
     mGradient->mMatrix = matrix;
     mDrawable.setBrush(VBrush(mGradient.get()));
     mDrawable.setFillRule(mData->fillRule());
+
+    return true;
 }
 
 LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
@@ -1169,10 +1181,13 @@ LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
 
 static thread_local std::vector<float> Dash_Vector;
 
-void LOTStrokeItem::updateContent(int frameNo, const VMatrix &matrix, float alpha)
+bool LOTStrokeItem::updateContent(int frameNo, const VMatrix &matrix, float alpha)
 {
-    VColor color = mModel.color(frameNo).toColor(mModel.opacity(frameNo));;
-    color.setAlpha(uchar(color.a * alpha));
+    auto combinedAlpha = alpha * mModel.opacity(frameNo);
+    auto color = mModel.color(frameNo).toColor(combinedAlpha);
+
+    if (color.isTransparent()) return false;
+
     VBrush brush(color);
     mDrawable.setBrush(brush);
     float scale = matrix.scale();
@@ -1187,15 +1202,20 @@ void LOTStrokeItem::updateContent(int frameNo, const VMatrix &matrix, float alph
             mDrawable.setDashInfo(Dash_Vector);
         }
     }
+
+    return true;
 }
 
 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
     : LOTPaintDataItem(data->isStatic()), mData(data){}
 
-void LOTGStrokeItem::updateContent(int frameNo, const VMatrix &matrix, float alpha)
+bool LOTGStrokeItem::updateContent(int frameNo, const VMatrix &matrix, float alpha)
 {
+    float combinedAlpha = alpha * mData->opacity(frameNo);
+    if (vIsZero(combinedAlpha)) return false;
+
     mData->update(mGradient, frameNo);
-    mGradient->setAlpha(mData->opacity(frameNo) * alpha);
+    mGradient->setAlpha(combinedAlpha);
     mGradient->mMatrix = matrix;
     auto scale = mGradient->mMatrix.scale();
     mDrawable.setBrush(VBrush(mGradient.get()));
@@ -1210,6 +1230,8 @@ void LOTGStrokeItem::updateContent(int frameNo, const VMatrix &matrix, float alp
             mDrawable.setDashInfo(Dash_Vector);
         }
     }
+
+    return true;
 }
 
 LOTTrimItem::LOTTrimItem(LOTTrimData *data)
index 4662b59095091efe010b3c91d498f29f15c4b696..6b155ecad272fea0a1c284912d27eb7344009f9c 100644 (file)
@@ -412,7 +412,7 @@ public:
    void renderList(std::vector<VDrawable *> &list) final;
    ContentType type() const final {return ContentType::Paint;}
 protected:
-   virtual void updateContent(int frameNo, const VMatrix &matrix, float alpha) = 0;
+   virtual bool updateContent(int frameNo, const VMatrix &matrix, float alpha) = 0;
 private:
    void updateRenderNode();
 protected:
@@ -422,6 +422,7 @@ protected:
    DirtyFlag                        mFlag;
    bool                             mStaticContent;
    bool                             mRenderNodeUpdate{true};
+   bool                             mContentToRender{true};
 };
 
 class LOTFillItem : public LOTPaintDataItem
@@ -429,7 +430,7 @@ class LOTFillItem : public LOTPaintDataItem
 public:
    explicit LOTFillItem(LOTFillData *data);
 protected:
-   void updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
+   bool updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
    bool resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value) final;
 private:
    LOTProxyModel<LOTFillData> mModel;
@@ -440,7 +441,7 @@ class LOTGFillItem : public LOTPaintDataItem
 public:
    explicit LOTGFillItem(LOTGFillData *data);
 protected:
-   void updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
+   bool updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
 private:
    LOTGFillData                 *mData;
    std::unique_ptr<VGradient>    mGradient;
@@ -451,7 +452,7 @@ class LOTStrokeItem : public LOTPaintDataItem
 public:
    explicit LOTStrokeItem(LOTStrokeData *data);
 protected:
-   void updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
+   bool updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
    bool resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value) final;
 private:
    LOTProxyModel<LOTStrokeData> mModel;
@@ -462,7 +463,7 @@ class LOTGStrokeItem : public LOTPaintDataItem
 public:
    explicit LOTGStrokeItem(LOTGStrokeData *data);
 protected:
-   void updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
+   bool updateContent(int frameNo, const VMatrix &matrix, float alpha) final;
 private:
    LOTGStrokeData               *mData;
    std::unique_ptr<VGradient>    mGradient;
index 75c947c66efa2b64d524579f8eb0e9b5424998cc..945bc1550526576ae2306bc5bed3522586a49478 100644 (file)
@@ -272,6 +272,7 @@ public:
     inline void setBlue(uchar blue) noexcept { b = blue; }
     inline void setAlpha(uchar alpha) noexcept { a = alpha; }
     inline bool isOpaque() const { return a == 255; }
+    inline bool isTransparent() const { return a == 0; }
     inline bool operator==(const VColor &o) const
     {
         return ((a == o.a) && (r == o.r) && (g == o.g) && (b == o.b));