summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-01-26 14:12:21 +0100
committerMichael Stahl <mstahl@redhat.com>2016-01-26 17:51:29 +0100
commitbde86f8074842585e2964b3157e97672fb25e63d (patch)
treea6d93942677d9d8e374761449ddeac838e73cd1a
parentvcl: actually that shared_array was a scam (diff)
downloadcore-bde86f8074842585e2964b3157e97672fb25e63d.tar.gz
core-bde86f8074842585e2964b3157e97672fb25e63d.zip
vcl: replace boost::shared_array with std::shared_ptr
Add o3tl::make_shared_array() to create the shared_ptr with the right deleter. The main difference then is that shared_array has operator[], but this code didn't even use it. Change-Id: I500ffc2f92b99c2a3924c0cdcdaa101956b69add
-rw-r--r--include/o3tl/make_shared.hxx33
-rw-r--r--vcl/inc/opengl/salbmp.hxx4
-rw-r--r--vcl/opengl/salbmp.cxx44
-rw-r--r--vcl/opengl/scale.cxx2
4 files changed, 59 insertions, 24 deletions
diff --git a/include/o3tl/make_shared.hxx b/include/o3tl/make_shared.hxx
new file mode 100644
index 000000000000..d42783c301fa
--- /dev/null
+++ b/include/o3tl/make_shared.hxx
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_O3TL_MAKE_SHARED_HXX
+#define INCLUDED_O3TL_MAKE_SHARED_HXX
+
+#include <memory>
+#include <type_traits>
+
+namespace o3tl {
+
+/** Allocate an array stored in a shared_ptr, calling operator delete[].
+ Note that this is only allowed for arithmetic types because shared_ptr
+ implicitly converts to sub-types.
+ */
+template<typename T>
+std::shared_ptr<T> make_shared_array(size_t const size)
+{
+ static_assert(std::is_arithmetic<T>::value, "only arrays of arithmetic types allowed");
+ return std::shared_ptr<T>(new T[size], std::default_delete<T[]>());
+}
+
+} // namespace o3tl
+
+#endif // INCLUDED_O3TL_MAKE_SHARED_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx
index f5a618abc93f..98e09b3c16eb 100644
--- a/vcl/inc/opengl/salbmp.hxx
+++ b/vcl/inc/opengl/salbmp.hxx
@@ -29,7 +29,7 @@
#include <salbmp.hxx>
#include <deque>
-#include <boost/shared_array.hpp>
+#include <memory>
struct BitmapBuffer;
class BitmapPalette;
@@ -40,7 +40,7 @@ private:
OpenGLTexture maTexture;
bool mbDirtyTexture;
BitmapPalette maPalette;
- boost::shared_array<sal_uInt8> maUserBuffer;
+ std::shared_ptr<sal_uInt8> mpUserBuffer;
sal_uInt16 mnBits;
sal_uInt16 mnBytesPerRow;
int mnWidth;
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index e8cbc313a3a4..703aedc10b98 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -30,6 +30,8 @@
#include "vcleventlisteners.hxx"
#include "vcl/lazydelete.hxx"
+#include <o3tl/make_shared.hxx>
+
#include "opengl/zone.hxx"
#include "opengl/program.hxx"
#include "opengl/salbmp.hxx"
@@ -202,12 +204,12 @@ bool OpenGLSalBitmap::Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount
mbDirtyTexture = false;
// be careful here, we are share & reference-count the
- // maUserBuffer, BUT this Create() is called from
+ // mpUserBuffer, BUT this Create() is called from
// Bitmap::ImplMakeUnique().
// Consequently, there might be cases when this needs to be made
// unique later (when we don't do that right away here), like when
// using the BitmapWriteAccess.
- maUserBuffer = rSourceBitmap.maUserBuffer;
+ mpUserBuffer = rSourceBitmap.mpUserBuffer;
return true;
}
@@ -238,7 +240,7 @@ void OpenGLSalBitmap::Destroy()
VCL_GL_INFO("Destroy OpenGLSalBitmap texture:" << maTexture.Id());
maPendingOps.clear();
maTexture = OpenGLTexture();
- maUserBuffer.reset();
+ mpUserBuffer.reset();
}
bool OpenGLSalBitmap::AllocateUserData()
@@ -256,7 +258,7 @@ bool OpenGLSalBitmap::AllocateUserData()
{
try
{
- maUserBuffer.reset( new sal_uInt8[static_cast<sal_uInt32>(mnBytesPerRow) * mnHeight] );
+ mpUserBuffer = o3tl::make_shared_array<sal_uInt8>(static_cast<sal_uInt32>(mnBytesPerRow) * mnHeight);
alloc = true;
}
catch (const std::bad_alloc &) {}
@@ -264,18 +266,18 @@ bool OpenGLSalBitmap::AllocateUserData()
if (!alloc)
{
SAL_WARN("vcl.opengl", "bad alloc " << mnBytesPerRow << "x" << mnHeight);
- maUserBuffer.reset( static_cast<sal_uInt8*>(nullptr) );
+ mpUserBuffer.reset();
mnBytesPerRow = 0;
}
#ifdef DBG_UTIL
else
{
for (size_t i = 0; i < size_t(mnBytesPerRow * mnHeight); i++)
- maUserBuffer.get()[i] = (i & 0xFF);
+ mpUserBuffer.get()[i] = (i & 0xFF);
}
#endif
- return maUserBuffer.get() != nullptr;
+ return mpUserBuffer.get() != nullptr;
}
namespace {
@@ -436,19 +438,19 @@ GLuint OpenGLSalBitmap::CreateTexture()
sal_uInt8* pData( nullptr );
bool bAllocated( false );
- if( maUserBuffer.get() != nullptr )
+ if (mpUserBuffer.get() != nullptr)
{
if( mnBits == 16 || mnBits == 24 || mnBits == 32 )
{
// no conversion needed for truecolor
- pData = maUserBuffer.get();
+ pData = mpUserBuffer.get();
determineTextureFormat(mnBits, nFormat, nType);
}
else if( mnBits == 8 && maPalette.IsGreyPalette() )
{
// no conversion needed for grayscale
- pData = maUserBuffer.get();
+ pData = mpUserBuffer.get();
nFormat = GL_LUMINANCE;
nType = GL_UNSIGNED_BYTE;
}
@@ -463,7 +465,7 @@ GLuint OpenGLSalBitmap::CreateTexture()
std::unique_ptr<ImplPixelFormat> pSrcFormat(ImplPixelFormat::GetFormat(mnBits, maPalette));
- sal_uInt8* pSrcData = maUserBuffer.get();
+ sal_uInt8* pSrcData = mpUserBuffer.get();
sal_uInt8* pDstData = pData;
sal_uInt32 nY = mnBufHeight;
@@ -516,7 +518,7 @@ GLuint OpenGLSalBitmap::CreateTexture()
bool OpenGLSalBitmap::ReadTexture()
{
- sal_uInt8* pData = maUserBuffer.get();
+ sal_uInt8* pData = mpUserBuffer.get();
GLenum nFormat = GL_RGBA;
GLenum nType = GL_UNSIGNED_BYTE;
@@ -707,7 +709,7 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode )
if( nMode != BITMAP_INFO_ACCESS )
{
- if( !maUserBuffer.get() )
+ if (!mpUserBuffer.get())
{
if( !AllocateUserData() )
return nullptr;
@@ -723,14 +725,14 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode )
}
}
- // maUserBuffer must be unique when we are doing the write access
- if (nMode == BITMAP_WRITE_ACCESS && maUserBuffer && !maUserBuffer.unique())
+ // mpUserBuffer must be unique when we are doing the write access
+ if (nMode == BITMAP_WRITE_ACCESS && mpUserBuffer && !mpUserBuffer.unique())
{
- boost::shared_array<sal_uInt8> aBuffer(maUserBuffer);
+ std::shared_ptr<sal_uInt8> aBuffer(mpUserBuffer);
- maUserBuffer.reset();
+ mpUserBuffer.reset();
AllocateUserData();
- memcpy(maUserBuffer.get(), aBuffer.get(), static_cast<sal_uInt32>(mnBytesPerRow) * mnHeight);
+ memcpy(mpUserBuffer.get(), aBuffer.get(), static_cast<sal_uInt32>(mnBytesPerRow) * mnHeight);
}
BitmapBuffer* pBuffer = new BitmapBuffer;
@@ -738,7 +740,7 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode )
pBuffer->mnHeight = mnHeight;
pBuffer->maPalette = maPalette;
pBuffer->mnScanlineSize = mnBytesPerRow;
- pBuffer->mpBits = maUserBuffer.get();
+ pBuffer->mpBits = mpUserBuffer.get();
pBuffer->mnBitCount = mnBits;
switch (mnBits)
@@ -847,7 +849,7 @@ bool OpenGLSalBitmap::GetSystemData( BitmapSystemData& /*rData*/ )
if( pBuffer == NULL )
return false;
- if( !maUserBuffer.get() )
+ if (!mpUserBuffer.get())
{
if( !AllocateUserData() || !ReadTexture() )
{
@@ -858,7 +860,7 @@ bool OpenGLSalBitmap::GetSystemData( BitmapSystemData& /*rData*/ )
// TODO Might be more efficient to add a static method to SalBitmap
// to get system data from a buffer
- memcpy( pBuffer->mpBits, maUserBuffer.get(), mnBytesPerRow * mnHeight );
+ memcpy( pBuffer->mpBits, mpUserBuffer.get(), mnBytesPerRow * mnHeight );
rBitmap.ReleaseBuffer( pBuffer, false );
return rBitmap.GetSystemData( rData );
diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx
index 80bbdd6d521a..9ba74323c8c1 100644
--- a/vcl/opengl/scale.cxx
+++ b/vcl/opengl/scale.cxx
@@ -265,7 +265,7 @@ bool OpenGLSalBitmap::ImplScale( const double& rScaleX, const double& rScaleY, B
{
VCL_GL_INFO( "::ImplScale" );
- maUserBuffer.reset();
+ mpUserBuffer.reset();
OpenGLVCLContextZone aContextZone;
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();