diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-05-24 08:56:15 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-05-24 10:12:17 +0200 |
commit | 2c8e66129f14c6d0b9174d27546e233b3995d8d4 (patch) | |
tree | a9c64f91b5d6e0fcc2c6696a3a9367d919b5d736 /include/vcl/gfxlink.hxx | |
parent | tdf#89329: use unique_ptr for pImpl in filedlghelper (diff) | |
download | core-2c8e66129f14c6d0b9174d27546e233b3995d8d4.tar.gz core-2c8e66129f14c6d0b9174d27546e233b3995d8d4.zip |
Revert "Simplify GfxLink using std::shared_ptr to clarify ownership"
This reverts commit d64431ac5a7bede7661c64e0bd6d46805841e704, which caused ASan
to complain about "alloc-dealloc-mismatch (operator new [] vs operator delete)"
(while e.g. building Gallery_arrows), as GfxLink::mpSwpInData is a
std::shared_ptr<sal_uInt8> holding a pointer to an array of sal_uInt8.
Diffstat (limited to 'include/vcl/gfxlink.hxx')
-rw-r--r-- | include/vcl/gfxlink.hxx | 98 |
1 files changed, 68 insertions, 30 deletions
diff --git a/include/vcl/gfxlink.hxx b/include/vcl/gfxlink.hxx index aa0e8fea37a2..3bdb4b79595a 100644 --- a/include/vcl/gfxlink.hxx +++ b/include/vcl/gfxlink.hxx @@ -25,10 +25,56 @@ #include <tools/solar.h> #include <vcl/dllapi.h> #include <vcl/mapmod.hxx> -#include <memory> 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 GfxLinkType { GFX_LINK_TYPE_NONE = 0, @@ -42,6 +88,7 @@ enum GfxLinkType GFX_LINK_TYPE_NATIVE_PCT = 8, // Don't forget to update the following defines GFX_LINK_TYPE_NATIVE_SVG = 9, // Don't forget to update the following defines GFX_LINK_TYPE_NATIVE_MOV = 10, // Don't forget to update the following defines + // #i15508# added BMP type support GFX_LINK_TYPE_NATIVE_BMP = 11, // Don't forget to update the following defines GFX_LINK_TYPE_USER = 0xffff }; @@ -49,58 +96,49 @@ enum GfxLinkType #define GFX_LINK_FIRST_NATIVE_ID GFX_LINK_TYPE_NATIVE_GIF #define GFX_LINK_LAST_NATIVE_ID GFX_LINK_TYPE_NATIVE_BMP + +struct ImpBuffer; +struct ImpSwap; +struct ImpGfxLink; class Graphic; class VCL_DLLPUBLIC GfxLink { private: - struct SwapOutData - { - SwapOutData(const OUString &aURL); - ~SwapOutData(); + GfxLinkType meType; + ImpBuffer* mpBuf; + ImpSwap* mpSwap; + sal_uInt32 mnBufSize; + sal_uInt32 mnUserId; + ImpGfxLink* mpImpData; - OUString maURL; // File is removed in the destructor + SAL_DLLPRIVATE void ImplCopy( const GfxLink& rGfxLink ); - }; - - GfxLinkType meType = GFX_LINK_TYPE_NONE; - sal_uInt32 mnUserId = 0; - - std::shared_ptr<sal_uInt8> mpSwapInData; - std::shared_ptr<SwapOutData> mpSwapOutData; - - sal_uInt32 mnSwapInDataSize = 0; - MapMode maPrefMapMode; - Size maPrefSize; - bool mbPrefMapModeValid = false; - bool mbPrefSizeValid = false; - - SAL_DLLPRIVATE std::shared_ptr<sal_uInt8> GetSwapInData() const; public: GfxLink(); - - // pBuff = The Graphic data. This class takes ownership of this + GfxLink( const GfxLink& ); GfxLink( sal_uInt8* pBuf, sal_uInt32 nBufSize, GfxLinkType nType ); ~GfxLink(); - bool IsEqual( const GfxLink& ) const; + GfxLink& operator=( const GfxLink& ); + 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 mnSwapInDataSize;} + sal_uInt32 GetDataSize() const { return mnBufSize;} const sal_uInt8* GetData() const; - const Size& GetPrefSize() const { return maPrefSize;} + const Size& GetPrefSize() const { return mpImpData->maPrefSize;} void SetPrefSize( const Size& rPrefSize ); - bool IsPrefSizeValid() { return mbPrefSizeValid;} + bool IsPrefSizeValid() { return mpImpData->mbPrefSizeValid;} - const MapMode& GetPrefMapMode() const { return maPrefMapMode;} + const MapMode& GetPrefMapMode() const { return mpImpData->maPrefMapMode;} void SetPrefMapMode( const MapMode& rPrefMapMode ); - bool IsPrefMapModeValid() { return mbPrefMapModeValid;} + bool IsPrefMapModeValid() { return mpImpData->mbPrefMapModeValid;} bool IsNative() const; @@ -110,7 +148,7 @@ public: void SwapOut(); void SwapIn(); - bool IsSwappedOut() const { return( bool(mpSwapOutData) ); } + bool IsSwappedOut() const { return( mpSwap != nullptr ); } public: |