lottie/render: Support rendering lottie image object. 78/197678/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 15 Jan 2019 07:06:52 +0000 (16:06 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Tue, 15 Jan 2019 08:04:50 +0000 (17:04 +0900)
Change-Id: I1b15263cd27248ccef57eff1d771b627cf0f59d8

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

index b57833a..aa88896 100644 (file)
@@ -23,6 +23,7 @@
 #include "vdasher.h"
 #include "vpainter.h"
 #include "vraster.h"
+#include "vimageloader.h"
 
 /* Lottie Layer Rules
  * 1. time stretch is pre calculated and applied to all the properties of the
@@ -60,6 +61,10 @@ LOTCompItem::createLayerItem(LOTLayerData *layerData)
         return std::make_unique<LOTNullLayerItem>(layerData);
         break;
     }
+    case LayerType::Image: {
+        return std::make_unique<LOTImageLayerItem>(layerData);
+        break;
+    }
     default:
         return nullptr;
         break;
@@ -684,6 +689,66 @@ void LOTSolidLayerItem::renderList(std::vector<VDrawable *> &list)
     list.push_back(mRenderNode.get());
 }
 
+LOTImageLayerItem::LOTImageLayerItem(LOTLayerData *layerData)
+    : LOTLayerItem(layerData)
+{
+}
+
+void LOTImageLayerItem::updateContent()
+{
+    if (!mRenderNode) {
+        mRenderNode = std::make_unique<LOTDrawable>();
+        mRenderNode->mType = VDrawable::Type::Fill;
+        mRenderNode->mFlag |= VDrawable::DirtyState::All;
+        // load image
+        //@TODO find a better way to load
+        // so that can be shared by multiple layers
+        if (!mLayerData->mAsset->mImagePath.empty()) {
+            VBitmap img = VImageLoader::instance().load(mLayerData->mAsset->mImagePath.c_str());
+            VBrush brush(img);
+            mRenderNode->setBrush(brush);
+        }
+    }
+
+    if (flag() & DirtyFlagBit::Matrix) {
+        VPath path;
+        path.addRect(
+            VRectF(0, 0, mLayerData->mAsset->mWidth, mLayerData->mAsset->mHeight));
+        path.transform(combinedMatrix());
+        mRenderNode->mFlag |= VDrawable::DirtyState::Path;
+        mRenderNode->mPath = path;
+        mRenderNode->mBrush.setMatrix(combinedMatrix());
+    }
+
+    if (flag() & DirtyFlagBit::Alpha) {
+        //@TODO handle alpha with the image.
+    }
+}
+
+void LOTImageLayerItem::renderList(std::vector<VDrawable *> &list)
+{
+    if (!visible()) return;
+
+    list.push_back(mRenderNode.get());
+}
+
+void LOTImageLayerItem::buildLayerNode()
+{
+    LOTLayerItem::buildLayerNode();
+
+    mDrawableList.clear();
+    renderList(mDrawableList);
+
+    mCNodeList.clear();
+    for (auto &i : mDrawableList) {
+        LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
+        lotDrawable->sync();
+        mCNodeList.push_back(lotDrawable->mCNode.get());
+    }
+    layerNode()->mNodeList.ptr = mCNodeList.data();
+    layerNode()->mNodeList.size = mCNodeList.size();
+}
+
 LOTNullLayerItem::LOTNullLayerItem(LOTLayerData *layerData)
     : LOTLayerItem(layerData)
 {
index 339473e..d225699 100644 (file)
@@ -182,6 +182,19 @@ protected:
    void updateContent() final;
 };
 
+class LOTImageLayerItem: public LOTLayerItem
+{
+public:
+   LOTImageLayerItem(LOTLayerData *layerData);
+   void buildLayerNode() final;
+protected:
+   void updateContent() final;
+   void renderList(std::vector<VDrawable *> &list) final;
+private:
+   std::vector<LOTNode *>       mCNodeList;
+   std::unique_ptr<VDrawable>   mRenderNode;
+};
+
 class LOTMaskItem
 {
 public: