lottie/vector: Added reset api to VBitmap class 53/208153/1 accepted/tizen/unified/20190620.071909 submit/tizen/20190619.051039
authorsubhransu mohanty <sub.mohanty@samsung.com>
Wed, 12 Jun 2019 07:45:32 +0000 (16:45 +0900)
committerHermet Park <hermetpark@gmail.com>
Wed, 19 Jun 2019 04:40:48 +0000 (13:40 +0900)
Change-Id: Idec04c77350bf2ae33cf03b5a1f92cb060d639da

src/vector/vbitmap.cpp
src/vector/vbitmap.h

index 370c69c..84493da 100644 (file)
@@ -40,6 +40,13 @@ struct VBitmap::Impl {
         mOwnData(true),
         mRoData(false)
     {
+        reset(width, height, format);
+    }
+
+    void reset(uint width, uint height, VBitmap::Format format)
+    {
+        if (mOwnData && mData) delete(mData);
+
         mDepth = depth(format);
         uint stride = ((width * mDepth + 31) >> 5) << 2; // bytes per scanline (must be multiple of 4)
 
@@ -49,11 +56,6 @@ struct VBitmap::Impl {
         mStride = stride;
         mBytes = mStride * mHeight;
         mData = reinterpret_cast<uchar *>(::operator new(mBytes));
-
-        if (!mData) {
-            // handle malloc failure
-            ;
-        }
     }
 
     Impl(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format):
@@ -150,6 +152,20 @@ VBitmap::VBitmap(uchar *data, uint width, uint height, uint bytesPerLine,
     mImpl = std::make_shared<Impl>(data, width, height, bytesPerLine, format);
 }
 
+void VBitmap::reset(uint w, uint h, VBitmap::Format format)
+{
+    if (mImpl) {
+        if (w == mImpl->width() &&
+            h == mImpl->height() &&
+            format == mImpl->format()) {
+            return;
+        }
+        mImpl->reset(w, h, format);
+    } else {
+        mImpl = std::make_shared<Impl>(w, h, format);
+    }
+}
+
 uint VBitmap::stride() const
 {
     return mImpl ? mImpl->stride() : 0;
index c7f4702..a21c680 100644 (file)
@@ -37,6 +37,7 @@ public:
     VBitmap(uint w, uint h, VBitmap::Format format);
     VBitmap(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format);
 
+    void reset(uint w, uint h, VBitmap::Format format=Format::ARGB32_Premultiplied);
     uint          stride() const;
     uint          width() const;
     uint          height() const;