lottie: pass matteSource and bitmap to layer's render function 73/186773/10
authorYoungbok Shin <youngb.shin@samsung.com>
Tue, 14 Aug 2018 08:14:20 +0000 (17:14 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Thu, 16 Aug 2018 04:16:46 +0000 (04:16 +0000)
matteSource layer has to be handled in other way.
For now, matteSource layer does not be applied to layers.
But, matteSource layer will be invisible.
In some test cases, it helps to check other layers which are overlayed by
a wrongly drawn matteSource layer. Anyway, the matte feature will be implemented soon.

Change-Id: Ib1e47e7ce9012b73a1729341d130defa561061c6

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

index 9f206841c675adaa7110f59cab1d1125133ac010..25056cf4b357ad9f8a2f1e031d5a8d0aaba32784 100644 (file)
@@ -119,7 +119,7 @@ bool LOTCompItem::render(const LOTBuffer &buffer)
 
     VPainter painter(&bitmap);
     VRle     mask;
-    mRootLayer->render(&painter, mask);
+    mRootLayer->render(&painter, mask, nullptr);
 
     return true;
 }
@@ -156,8 +156,16 @@ VRle LOTMaskItem::rle()
     return mRle;
 }
 
-void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask)
+void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask, LOTLayerItem *matteSource)
 {
+    VRle matteRle;
+    if (matteSource) {
+        std::vector<VDrawable *> matteList;
+        matteSource->renderList(matteList);
+        for (auto &i : matteList) {
+            matteRle = matteRle + i->rle();
+        }
+    }
     std::vector<VDrawable *> list;
     renderList(list);
     VRle mask = inheritMask;
@@ -170,12 +178,17 @@ void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask)
 
     for (auto &i : list) {
         painter->setBrush(i->mBrush);
-        if (!mask.isEmpty()) {
-            VRle rle = i->rle() & mask;
-            painter->drawRle(VPoint(), rle);
-        } else {
-            painter->drawRle(VPoint(), i->rle());
+        VRle rle = i->rle();
+        if (!mask.isEmpty()) rle = i->rle() & mask;
+
+        if (!matteRle.isEmpty()) {
+            if (mLayerData->mMatteType == MatteType::AlphaInv) {
+                rle = rle - matteRle;
+            } else {
+                rle = rle & matteRle;
+            }
         }
+        painter->drawRle(VPoint(), rle);
     }
 }
 
@@ -326,8 +339,17 @@ void LOTCompLayerItem::updateStaticProperty()
     }
 }
 
-void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask)
+void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, LOTLayerItem *matteSource)
 {
+    VRle matteRle;
+    if (matteSource) {
+        std::vector<VDrawable *> matteList;
+        matteSource->renderList(matteList);
+        for (auto &i : matteList) {
+            matteRle = matteRle + i->rle();
+        }
+    }
+
     VRle mask = inheritMask;
 
     if (hasMask()) {
@@ -337,9 +359,21 @@ void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask)
             mask = mask & inheritMask;
     }
 
+    LOTLayerItem *matteLayer = nullptr;
     for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
         LOTLayerItem *layer = *i;
-        layer->render(painter, mask);
+
+        if (!matteLayer && layer->hasMatte()) {
+            matteLayer = layer;
+            continue;
+        }
+
+        if (matteLayer) {
+            matteLayer->render(painter, mask, layer);
+            matteLayer = nullptr;
+        } else {
+            layer->render(painter, mask, nullptr);
+        }
     }
 }
 
index 42721ce6f048e9f9783522847105ef1b9b0a2af8..6c769e02b347ae14b7ba3688f49df074d01dd286 100644 (file)
@@ -64,7 +64,9 @@ public:
    VMatrix matrix(int frameNo) const;
    virtual void renderList(std::vector<VDrawable *> &list){}
    virtual void updateStaticProperty();
-   virtual void render(VPainter *painter, const VRle &mask);
+   virtual void render(VPainter *painter, const VRle &mask, LOTLayerItem *matteSource);
+   bool hasMatte() { if (mLayerData->mMatteType == MatteType::None) return false; return true; }
+
 protected:
    virtual void updateContent() = 0;
    inline VMatrix combinedMatrix() const {return mCombinedMatrix;}
@@ -96,7 +98,7 @@ public:
    LOTCompLayerItem(LOTLayerData *layerData);
    void renderList(std::vector<VDrawable *> &list)final;
    void updateStaticProperty() final;
-   void render(VPainter *painter, const VRle &mask) final;
+   void render(VPainter *painter, const VRle &mask, LOTLayerItem *matteSource) final;
 protected:
    void updateContent() final;
 private: