summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-12-20 11:40:59 +0100
committerLuboš Luňák <l.lunak@collabora.com>2020-01-06 11:15:08 +0100
commit364cdd314fb4d6168990a469bfb10fc935dfc649 (patch)
tree574ab446c214682e52185fc5bd0a8f2c68611525
parentad88df7e924f2be11187b15085b0764771546abe (diff)
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@collabora.com>
-rw-r--r--vcl/inc/skia/salbmp.hxx4
-rw-r--r--vcl/skia/salbmp.cxx12
2 files changed, 9 insertions, 7 deletions
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;
}
}