diff options
-rw-r--r-- | include/o3tl/make_shared.hxx | 33 | ||||
-rw-r--r-- | vcl/inc/opengl/salbmp.hxx | 4 | ||||
-rw-r--r-- | vcl/opengl/salbmp.cxx | 44 | ||||
-rw-r--r-- | vcl/opengl/scale.cxx | 2 |
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(); |