lottie/mask: refactored mask drawing to take care of nested layer. 63/184263/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 17 Jul 2018 01:12:26 +0000 (10:12 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Tue, 17 Jul 2018 01:12:26 +0000 (10:12 +0900)
Change-Id: I287d27bcdebb6eda43243e6514bc1167b1e86dbf

src/lottie/lottieitem.cpp
src/lottie/lottieitem.h
src/vector/vrle.cpp

index cd30aa8..12ccec0 100644 (file)
@@ -289,9 +289,10 @@ bool LOTCompItem::render(const LOTBuffer &buffer)
                    buffer.bytesPerLine, VBitmap::Format::ARGB32_Premultiplied, nullptr, nullptr);
 
     VPainter painter(&bitmap);
+    VRle mask;
     for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
        LOTLayerItem *layer = *i;
-       layer->render(&painter);
+       layer->render(&painter, mask);
     }
 
 //    for(auto i : mRenderList) {
@@ -367,16 +368,22 @@ void LOTMaskItem::update(int frameNo, const VMatrix &parentMatrix,
     }
 }
 
-void LOTLayerItem::render(VPainter *painter)
+void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask)
 {
     std::vector<VDrawable *> list;
     renderList(list);
-    VRle mask = maskRle();
+    VRle mask = inheritMask;
+    if (hasMask()) {
+        if (mask.isEmpty())
+            mask = maskRle();
+        else
+            mask = mask & inheritMask;
+    }
     for(auto i : list) {
         i->preprocess();
         painter->setBrush(i->mBrush);
         if (!mask.isEmpty()) {
-            VRle rle = i->mRle + mask;
+            VRle rle = i->mRle & mask;
             painter->drawRle(VPoint(), rle);
         } else {
             painter->drawRle(VPoint(), i->mRle);
@@ -394,6 +401,8 @@ VRle LOTLayerItem::maskRle()
                 break;
             }
             case LOTMaskData::Mode::Substarct: {
+                if (rle.isEmpty() && !mBoundingRect.isEmpty())
+                    rle = VRle::toRle(mBoundingRect);
                 rle = rle - i->mRle;
                 break;
             }
@@ -529,6 +538,22 @@ void LOTCompLayerItem::updateStaticProperty()
     }
 }
 
+void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask)
+{
+    VRle mask = inheritMask;
+
+    if (hasMask()) {
+        if (mask.isEmpty())
+            mask = maskRle();
+        else
+            mask = mask & inheritMask;
+    }
+
+    for(auto i : mLayers) {
+       i->render(painter, mask);
+    }
+}
+
 LOTCompLayerItem::~LOTCompLayerItem()
 {
     for(auto i : mLayers) {
index 6fd6f32..58f302d 100644 (file)
@@ -64,7 +64,7 @@ public:
    VMatrix matrix(int frameNo) const;
    virtual void renderList(std::vector<VDrawable *> &list){}
    virtual void updateStaticProperty();
-   void render(VPainter *painter);
+   virtual void render(VPainter *painter, const VRle &mask);
 protected:
    virtual void updateContent() = 0;
    inline VMatrix combinedMatrix() const {return mCombinedMatrix;}
@@ -85,6 +85,7 @@ protected:
    float                                       mCombinedAlpha;
    int                                         mFrameNo;
    DirtyFlag                                   mDirtyFlag;
+   VRectF                                      mBoundingRect;
    bool                                        mVisible;
    bool                                        mStatic;
 };
@@ -96,6 +97,7 @@ public:
    LOTCompLayerItem(LOTLayerData *layerData);
    void renderList(std::vector<VDrawable *> &list)final;
    void updateStaticProperty() final;
+   void render(VPainter *painter, const VRle &mask) final;
 protected:
    void updateContent() final;
 private:
index df0f24e..4435e8e 100644 (file)
@@ -782,6 +782,8 @@ const VRle::Span* VRle::data() const
 
 VRle VRle::toRle(const VRectF &rect)
 {
+    if (rect.isEmpty()) return VRle();
+
     VRle result;
     result.detach();
     int x = rect.left();