From f595e70cfee85a423f592190c607231cb00e3180 Mon Sep 17 00:00:00 2001 From: Mark Page Date: Tue, 31 May 2016 12:26:28 +0100 Subject: Simplify GfxLink using smart pointers Uses std::shared_ptr for sharing graphic data Changed constructor to std::unique_ptr to ensure the delete[] operator is called when GfxLink internals takes ownership of the data Change-Id: I4edd4634df8d6ba4d94953260c1a7ac560ccf04a Reviewed-on: https://gerrit.libreoffice.org/25402 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/vcl/gfxlink.hxx | 100 +++++++++++++++--------------------------------- 1 file changed, 31 insertions(+), 69 deletions(-) (limited to 'include') diff --git a/include/vcl/gfxlink.hxx b/include/vcl/gfxlink.hxx index 864d1d6863a6..0fc6e0c26293 100644 --- a/include/vcl/gfxlink.hxx +++ b/include/vcl/gfxlink.hxx @@ -25,56 +25,10 @@ #include #include #include +#include class SvStream; - -struct ImpBuffer -{ - sal_uLong mnRefCount; - sal_uInt8* mpBuffer; - - ImpBuffer( sal_uInt8* pBuf ) { mnRefCount = 1UL; mpBuffer = pBuf; } - - ~ImpBuffer() { delete[] mpBuffer; } -}; - - -struct ImpSwap -{ - OUString maURL; - sal_uLong mnDataSize; - sal_uLong mnRefCount; - - ImpSwap( sal_uInt8* pData, sal_uLong nDataSize ); - ~ImpSwap(); - - sal_uInt8* GetData() const; - - bool IsSwapped() const { return maURL.getLength() > 0; } - - void WriteTo( SvStream& rOStm ) const; -}; - - -struct ImpGfxLink -{ - MapMode maPrefMapMode; - Size maPrefSize; - bool mbPrefMapModeValid; - bool mbPrefSizeValid; - - ImpGfxLink() : - maPrefMapMode(), - maPrefSize(), - mbPrefMapModeValid( false ), - mbPrefSizeValid( false ) - {} -}; - -//#endif // __PRIVATE - - enum class GfxLinkType { NONE = 0, @@ -88,56 +42,64 @@ enum class GfxLinkType NativePct = 8, // Don't forget to update the following defines NativeSvg = 9, // Don't forget to update the following defines NativeMov = 10, // Don't forget to update the following defines - // #i15508# added BMP type support NativeBmp = 11 // Don't forget to update the following defines }; #define GFX_LINK_FIRST_NATIVE_ID GfxLinkType::NativeGif #define GFX_LINK_LAST_NATIVE_ID GfxLinkType::NativeBmp - -struct ImpBuffer; -struct ImpSwap; -struct ImpGfxLink; class Graphic; class VCL_DLLPUBLIC GfxLink { private: - GfxLinkType meType; - ImpBuffer* mpBuf; - ImpSwap* mpSwap; - sal_uInt32 mnBufSize; - sal_uInt32 mnUserId; - ImpGfxLink* mpImpData; + struct SwapOutData + { + SwapOutData(const OUString &aURL); + ~SwapOutData(); - SAL_DLLPRIVATE void ImplCopy( const GfxLink& rGfxLink ); + OUString maURL; // File is removed in the destructor + }; + + GfxLinkType meType = GfxLinkType::NONE; + sal_uInt32 mnUserId = 0; + + std::shared_ptr mpSwapInData; + std::shared_ptr mpSwapOutData; + + sal_uInt32 mnSwapInDataSize = 0; + MapMode maPrefMapMode; + Size maPrefSize; + bool mbPrefMapModeValid = false; + bool mbPrefSizeValid = false; + + SAL_DLLPRIVATE std::shared_ptr GetSwapInData() const; public: GfxLink(); - GfxLink( const GfxLink& ); - GfxLink( sal_uInt8* pBuf, sal_uInt32 nBufSize, GfxLinkType nType ); + + // pBuff = The Graphic data. This class takes ownership of this + GfxLink( std::unique_ptr pBuf, sal_uInt32 nBufSize, GfxLinkType nType ); ~GfxLink(); - GfxLink& operator=( const GfxLink& ); - bool IsEqual( const GfxLink& ) const; + bool IsEqual( const GfxLink& ) const; GfxLinkType GetType() const { return meType;} void SetUserId( sal_uInt32 nUserId ) { mnUserId = nUserId; } sal_uInt32 GetUserId() const { return mnUserId; } - sal_uInt32 GetDataSize() const { return mnBufSize;} + sal_uInt32 GetDataSize() const { return mnSwapInDataSize;} const sal_uInt8* GetData() const; - const Size& GetPrefSize() const { return mpImpData->maPrefSize;} + const Size& GetPrefSize() const { return maPrefSize;} void SetPrefSize( const Size& rPrefSize ); - bool IsPrefSizeValid() { return mpImpData->mbPrefSizeValid;} + bool IsPrefSizeValid() { return mbPrefSizeValid;} - const MapMode& GetPrefMapMode() const { return mpImpData->maPrefMapMode;} + const MapMode& GetPrefMapMode() const { return maPrefMapMode;} void SetPrefMapMode( const MapMode& rPrefMapMode ); - bool IsPrefMapModeValid() { return mpImpData->mbPrefMapModeValid;} + bool IsPrefMapModeValid() { return mbPrefMapModeValid;} bool IsNative() const; @@ -147,7 +109,7 @@ public: void SwapOut(); void SwapIn(); - bool IsSwappedOut() const { return( mpSwap != nullptr ); } + bool IsSwappedOut() const { return( bool(mpSwapOutData) ); } public: -- cgit