[Libreoffice-commits] core.git: vcl/inc vcl/skia

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Mon Jan 6 10:15:42 UTC 2020


 vcl/inc/skia/salbmp.hxx |    4 +++-
 vcl/skia/salbmp.cxx     |   12 ++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

New commits:
commit 364cdd314fb4d6168990a469bfb10fc935dfc649
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Dec 20 11:40:59 2019 +0100
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Jan 6 11:15:08 2020 +0100

    use boost::shared_ptr for allocating an array
    
    Using make_shared() results in just one allocation instead of having
    one for the data and one for the shared_ptr's control block. But
    std::shared_ptr supports make_shared() for arrays only in C++20.
    
    Change-Id: If2d1223ebcc54ccfdccb15601d69a3563bd4f6c0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85589
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index 78b864104a2c..40cbb62104d1 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -24,6 +24,8 @@
 
 #include <SkImage.h>
 
+#include <boost/smart_ptr/shared_ptr.hpp>
+
 class VCL_PLUGIN_PUBLIC SkiaSalBitmap final : public SalBitmap
 {
 public:
@@ -114,7 +116,7 @@ private:
     // mBitmap/mBuffer must be filled from it on demand if necessary by EnsureBitmapData().
     SkBitmap mBitmap;
     sk_sp<SkImage> mImage; // possibly GPU-backed
-    std::shared_ptr<sal_uInt8[]> mBuffer;
+    boost::shared_ptr<sal_uInt8[]> mBuffer;
     int mScanlineSize; // size of one row in mBuffer
     sk_sp<SkImage> mAlphaImage; // cached contents as alpha image, possibly GPU-backed
 #ifdef DBG_UTIL
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 4430d7f672cd..172b7c37ef92 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -21,6 +21,7 @@
 
 #include <o3tl/safeint.hxx>
 #include <tools/helpers.hxx>
+#include <boost/smart_ptr/make_shared.hpp>
 
 #include <salgdi.hxx>
 #include <salinst.hxx>
@@ -140,22 +141,21 @@ bool SkiaSalBitmap::CreateBitmapData()
             return false;
         }
         mScanlineSize = AlignedWidth4Bytes(bitScanlineWidth);
-        sal_uInt8* buffer = nullptr;
         if (mScanlineSize != 0 && mSize.Height() != 0)
         {
             size_t allocate = mScanlineSize * mSize.Height();
 #ifdef DBG_UTIL
             allocate += sizeof(CANARY);
 #endif
-            buffer = new sal_uInt8[allocate];
+            mBuffer = boost::make_shared<sal_uInt8[]>(allocate);
 #ifdef DBG_UTIL
             // fill with random garbage
+            sal_uInt8* buffer = mBuffer.get();
             for (size_t i = 0; i < allocate; i++)
                 buffer[i] = (i & 0xFF);
             memcpy(buffer + allocate - sizeof(CANARY), CANARY, sizeof(CANARY));
 #endif
         }
-        mBuffer.reset(buffer);
     }
     return true;
 }
@@ -613,9 +613,9 @@ void SkiaSalBitmap::EnsureBitmapUniqueData()
         assert(memcmp(mBuffer.get() + allocate, CANARY, sizeof(CANARY)) == 0);
         allocate += sizeof(CANARY);
 #endif
-        sal_uInt8* newBuffer = new sal_uInt8[allocate];
-        memcpy(newBuffer, mBuffer.get(), allocate);
-        mBuffer.reset(newBuffer);
+        boost::shared_ptr<sal_uInt8[]> newBuffer = boost::make_shared<sal_uInt8[]>(allocate);
+        memcpy(newBuffer.get(), mBuffer.get(), allocate);
+        mBuffer = newBuffer;
     }
 }
 


More information about the Libreoffice-commits mailing list