diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-11-03 22:46:59 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-11-04 08:15:56 +0000 |
commit | f4637c07c9ac87c2ad4b687263dfea50b5d4e0ef (patch) | |
tree | 80d321e2b92829e42448a65b14dcc08396288c24 /vcl/source/image | |
parent | 3e610f8496a0b6ef126426b807e0af366a98b8f3 (diff) |
convert Image manual refcounting with std::shader_ptr
Change-Id: I9a086d4a5d2f1b0d1afa3afd155eadcb2ae62ab5
Reviewed-on: https://gerrit.libreoffice.org/30543
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source/image')
-rw-r--r-- | vcl/source/image/Image.cxx | 83 | ||||
-rw-r--r-- | vcl/source/image/ImageList.cxx | 48 |
2 files changed, 37 insertions, 94 deletions
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx index 2aab6a890f28..bc767ce9c497 100644 --- a/vcl/source/image/Image.cxx +++ b/vcl/source/image/Image.cxx @@ -40,15 +40,12 @@ #include <rtl/strbuf.hxx> #endif -Image::Image() : - mpImplData( nullptr ) +Image::Image() { } -Image::Image( const ResId& rResId ) : - mpImplData( nullptr ) +Image::Image( const ResId& rResId ) { - rResId.SetRT( RSC_IMAGE ); ResMgr* pResMgr = rResId.GetResMgr(); @@ -70,78 +67,60 @@ Image::Image( const ResId& rResId ) : } } -Image::Image( const Image& rImage ) : - mpImplData( rImage.mpImplData ) +Image::Image(const Image& rImage) + : mpImplData(rImage.mpImplData) { - - if( mpImplData ) - ++mpImplData->mnRefCount; } -Image::Image( const BitmapEx& rBitmapEx ) : - mpImplData( nullptr ) +Image::Image(const BitmapEx& rBitmapEx) { - - ImplInit( rBitmapEx ); + ImplInit(rBitmapEx); } -Image::Image( const Bitmap& rBitmap ) : - mpImplData( nullptr ) +Image::Image(const Bitmap& rBitmap) { - - ImplInit( rBitmap ); + ImplInit(rBitmap); } -Image::Image( const Bitmap& rBitmap, const Bitmap& rMaskBitmap ) : - mpImplData( nullptr ) +Image::Image(const Bitmap& rBitmap, const Bitmap& rMaskBitmap) { - - const BitmapEx aBmpEx( rBitmap, rMaskBitmap ); - - ImplInit( aBmpEx ); + const BitmapEx aBitmapEx(rBitmap, rMaskBitmap); + ImplInit(aBitmapEx); } -Image::Image( const Bitmap& rBitmap, const Color& rColor ) : - mpImplData( nullptr ) +Image::Image(const Bitmap& rBitmap, const Color& rColor) { - - const BitmapEx aBmpEx( rBitmap, rColor ); - - ImplInit( aBmpEx ); + const BitmapEx aBitmapEx(rBitmap, rColor); + ImplInit(aBitmapEx); } -Image::Image( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic ) : - mpImplData( nullptr ) +Image::Image(const css::uno::Reference< css::graphic::XGraphic >& rxGraphic) { - - const Graphic aGraphic( rxGraphic ); - ImplInit( aGraphic.GetBitmapEx() ); + const Graphic aGraphic(rxGraphic); + ImplInit(aGraphic.GetBitmapEx()); } -Image::Image( const OUString &rFileUrl ) : - mpImplData( nullptr ) +Image::Image(const OUString & rFileUrl) { - OUString aTmp; - osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp ); + OUString aPath; + osl::FileBase::getSystemPathFromFileURL(rFileUrl, aPath); Graphic aGraphic; - const OUString aFilterName( IMP_PNG ); - if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) ) + const OUString aFilterName(IMP_PNG); + if (GRFILTER_OK == GraphicFilter::LoadGraphic(aPath, aFilterName, aGraphic)) { - ImplInit( aGraphic.GetBitmapEx() ); + ImplInit(aGraphic.GetBitmapEx()); } } Image::~Image() { - if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) - delete mpImplData; } void Image::ImplInit(const BitmapEx& rBitmapEx) { if (!rBitmapEx.IsEmpty()) { - mpImplData = new ImplImage; + mpImplData.reset(new ImplImage); mpImplData->mpBitmapEx.reset(new BitmapEx(rBitmapEx)); } } @@ -177,21 +156,13 @@ css::uno::Reference< css::graphic::XGraphic > Image::GetXGraphic() const return aGraphic.GetXGraphic(); } -Image& Image::operator=( const Image& rImage ) +Image& Image::operator=(const Image& rImage) { - - if( rImage.mpImplData ) - ++rImage.mpImplData->mnRefCount; - - if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) - delete mpImplData; - mpImplData = rImage.mpImplData; - return *this; } -Image& Image::operator=( Image&& rImage ) +Image& Image::operator=(Image&& rImage) { std::swap(mpImplData, rImage.mpImplData); return *this; @@ -213,7 +184,7 @@ bool Image::operator==(const Image& rImage) const void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize) { - if (mpImplData == nullptr || !mpImplData->mpBitmapEx || + if (!mpImplData || !mpImplData->mpBitmapEx || (!pOutDev->IsDeviceOutputNecessary() && pOutDev->GetConnectMetaFile() == nullptr)) return; diff --git a/vcl/source/image/ImageList.cxx b/vcl/source/image/ImageList.cxx index 9eeb9e874c7e..42def4e05efc 100644 --- a/vcl/source/image/ImageList.cxx +++ b/vcl/source/image/ImageList.cxx @@ -33,13 +33,11 @@ #include <vcl/implimagetree.hxx> #include <image.h> -ImageList::ImageList() : - mpImplData( nullptr ) +ImageList::ImageList() { } -ImageList::ImageList( const ResId& rResId ) : - mpImplData( nullptr ) +ImageList::ImageList(const ResId& rResId) { SAL_INFO( "vcl.gdi", "vcl: ImageList::ImageList( const ResId& rResId )" ); @@ -76,9 +74,8 @@ ImageList::ImageList( const ResId& rResId ) : } } -ImageList::ImageList( const std::vector< OUString >& rNameVector, - const OUString& rPrefix) : - mpImplData( nullptr ) +ImageList::ImageList(const std::vector< OUString >& rNameVector, + const OUString& rPrefix) { SAL_INFO( "vcl.gdi", "vcl: ImageList::ImageList(const vector< OUString >& ..." ); @@ -91,29 +88,24 @@ ImageList::ImageList( const std::vector< OUString >& rNameVector, } } -ImageList::ImageList( const ImageList& rImageList ) : - mpImplData( rImageList.mpImplData ) +ImageList::ImageList( const ImageList& rImageList ) + : mpImplData(rImageList.mpImplData) { - - if( mpImplData ) - ++mpImplData->mnRefCount; } -ImageList::ImageList( ImageList&& rImageList ) : - mpImplData( rImageList.mpImplData ) +ImageList::ImageList( ImageList&& rImageList ) + : mpImplData(rImageList.mpImplData) { - rImageList.mpImplData = nullptr; + rImageList.mpImplData.reset(); } ImageList::~ImageList() { - if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) - delete mpImplData; } void ImageList::ImplInit( sal_uInt16 nItems, const Size &rSize ) { - mpImplData = new ImplImageList; + mpImplData.reset(new ImplImageList); mpImplData->maImages.reserve( nItems ); mpImplData->maImageSize = rSize; } @@ -202,7 +194,6 @@ void ImageList::InsertFromHorizontalBitmap( const ResId& rResId, sal_uInt16 ImageList::ImplGetImageId( const OUString& rImageName ) const { - ImageAryData *pImg = mpImplData->maNameHash[ rImageName ]; if( pImg ) return pImg->mnId; @@ -236,7 +227,6 @@ void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage ) void ImageList::RemoveImage( sal_uInt16 nId ) { - for( size_t i = 0; i < mpImplData->maImages.size(); ++i ) { if( mpImplData->maImages[ i ]->mnId == nId ) @@ -294,7 +284,6 @@ Image ImageList::GetImage( const OUString& rImageName ) const sal_uInt16 ImageList::GetImageCount() const { - return mpImplData ? static_cast< sal_uInt16 >( mpImplData->maImages.size() ) : 0; } @@ -320,7 +309,6 @@ bool ImageList::HasImageAtPos( sal_uInt16 nId ) const sal_uInt16 ImageList::GetImagePos( const OUString& rImageName ) const { - if( mpImplData && !rImageName.isEmpty() ) { for( size_t i = 0; i < mpImplData->maImages.size(); i++ ) @@ -335,7 +323,6 @@ sal_uInt16 ImageList::GetImagePos( const OUString& rImageName ) const sal_uInt16 ImageList::GetImageId( sal_uInt16 nPos ) const { - if( mpImplData && (nPos < GetImageCount()) ) return mpImplData->maImages[ nPos ]->mnId; @@ -344,7 +331,6 @@ sal_uInt16 ImageList::GetImageId( sal_uInt16 nPos ) const OUString ImageList::GetImageName( sal_uInt16 nPos ) const { - if( mpImplData && (nPos < GetImageCount()) ) return mpImplData->maImages[ nPos ]->maName; @@ -370,7 +356,6 @@ void ImageList::GetImageNames( std::vector< OUString >& rNames ) const Size ImageList::GetImageSize() const { - Size aRet; if( mpImplData ) @@ -390,32 +375,19 @@ Size ImageList::GetImageSize() const ImageList& ImageList::operator=( const ImageList& rImageList ) { - - if( rImageList.mpImplData ) - ++rImageList.mpImplData->mnRefCount; - - if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) - delete mpImplData; - mpImplData = rImageList.mpImplData; - return *this; } ImageList& ImageList::operator=( ImageList&& rImageList ) { - if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) - delete mpImplData; - mpImplData = rImageList.mpImplData; rImageList.mpImplData = nullptr; - return *this; } bool ImageList::operator==( const ImageList& rImageList ) const { - bool bRet = false; if( rImageList.mpImplData == mpImplData ) |