vector: refcator VBrush to reduce memory footprint
authorsubhransu mohanty <sub.mohanty@samsung.com>
Thu, 10 Oct 2019 06:42:18 +0000 (15:42 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Thu, 10 Oct 2019 21:43:55 +0000 (06:43 +0900)
src/lottie/lottieitem.cpp
src/lottie/lottieitem.h
src/lottie/lottieitem_capi.cpp
src/vector/vbrush.cpp
src/vector/vbrush.h
src/vector/vdrawhelper.cpp

index 092f9fce61d93495295e80136b232bc01c10cb06..7a59b2df83a8f10079f4592e33d3bc78f2b5168c 100644 (file)
@@ -651,7 +651,8 @@ LOTImageLayerItem::LOTImageLayerItem(LOTLayerData *layerData)
 {
     if (!mLayerData->asset()) return;
 
-    VBrush brush(mLayerData->asset()->bitmap());
+    mTexture.mBitmap = mLayerData->asset()->bitmap();
+    VBrush brush(&mTexture);
     mRenderNode.setBrush(brush);
 }
 
@@ -666,7 +667,7 @@ void LOTImageLayerItem::updateContent()
         path.transform(combinedMatrix());
         mRenderNode.mFlag |= VDrawable::DirtyState::Path;
         mRenderNode.mPath = path;
-        mRenderNode.mBrush.setMatrix(combinedMatrix());
+        mTexture.mMatrix = combinedMatrix();
     }
 
     if (flag() & DirtyFlagBit::Alpha) {
index 1c046c55a26ad31c52edd7f6bac68cfe3efa5be6..4662b59095091efe010b3c91d498f29f15c4b696 100644 (file)
@@ -222,6 +222,7 @@ protected:
    void renderList(std::vector<VDrawable *> &list) final;
 private:
    LOTDrawable                  mRenderNode;
+   VTexture                     mTexture;
 };
 
 class LOTMaskItem
index 178af4e8a72938dd99e1f08ece7b6b984bdd0b25..f09395859c7050ae65402389189d75ed770301d0 100644 (file)
@@ -178,11 +178,11 @@ void LOTImageLayerItem::buildLayerNode()
         lotDrawable->sync();
 
         lotDrawable->mCNode->mImageInfo.data =
-            lotDrawable->mBrush.mTexture.data();
+            lotDrawable->mBrush.mTexture->mBitmap.data();
         lotDrawable->mCNode->mImageInfo.width =
-            int(lotDrawable->mBrush.mTexture.width());
+            int(lotDrawable->mBrush.mTexture->mBitmap.width());
         lotDrawable->mCNode->mImageInfo.height =
-            int(lotDrawable->mBrush.mTexture.height());
+            int(lotDrawable->mBrush.mTexture->mBitmap.height());
 
         lotDrawable->mCNode->mImageInfo.mMatrix.m11 = combinedMatrix().m_11();
         lotDrawable->mCNode->mImageInfo.mMatrix.m12 = combinedMatrix().m_12();
index 7d761faa05c2895613a93e26f6d65ab99021c1ec..26c828187c1ccaaf91a6969509307a5b07b3d769 100644 (file)
@@ -58,17 +58,8 @@ VBrush::VBrush(const VGradient *gradient)
     }
 }
 
-VBrush::VBrush(const VBitmap &texture)
+VBrush::VBrush(const VTexture *texture):mType(VBrush::Type::Texture), mTexture(texture)
 {
-    if (!texture.valid()) return;
-
-    mType = VBrush::Type::Texture;
-    mTexture = texture;
-}
-
-void VBrush::setMatrix(const VMatrix &m)
-{
-    mMatrix = m;
 }
 
 V_END_NAMESPACE
index 8869ec0c8bcf4b7167921c08f6b56b60c5ff71a8..f45f6cccc99746d7444bf17a378fd3008d1ad868 100644 (file)
@@ -59,22 +59,27 @@ public:
     VMatrix mMatrix;
 };
 
+struct VTexture {
+    VBitmap  mBitmap;
+    VMatrix  mMatrix;
+};
+
 class VBrush {
 public:
     enum class Type { NoBrush, Solid, LinearGradient, RadialGradient, Texture };
-    VBrush() = default;
+    VBrush():mType(Type::NoBrush),mColor(){};
     explicit VBrush(const VColor &color);
     explicit VBrush(const VGradient *gradient);
     explicit VBrush(uchar r, uchar g, uchar b, uchar a);
-    explicit VBrush(const VBitmap &texture);
+    explicit VBrush(const VTexture *texture);
     inline VBrush::Type type() const { return mType; }
-    void setMatrix(const VMatrix &m);
 public:
     VBrush::Type     mType{Type::NoBrush};
-    VColor           mColor;
-    const VGradient *mGradient{nullptr};
-    VBitmap          mTexture;
-    VMatrix          mMatrix;
+    union {
+        VColor           mColor{};
+        const VGradient *mGradient;
+        const VTexture  *mTexture;
+    };
 };
 
 V_END_NAMESPACE
index e3ae7a846b96b960fc6fa2198b19b7a8dcf70788..43050f291ccb5c376eb6093b879e8b210be325eb 100644 (file)
@@ -795,9 +795,9 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
     case VBrush::Type::Texture: {
         mType = VSpanData::Type::Texture;
         initTexture(
-            &brush.mTexture, 255, VBitmapData::Plain,
-            brush.mTexture.rect());
-        setupMatrix(brush.mMatrix);
+            &brush.mTexture->mBitmap, 255, VBitmapData::Plain,
+            brush.mTexture->mBitmap.rect());
+        setupMatrix(brush.mTexture->mMatrix);
         break;
     }
     default: