Kaydet (Commit) 2c8e6612 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Revert "Simplify GfxLink using std::shared_ptr to clarify ownership"

This reverts commit d64431ac, 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.
üst 3c91b8d8
......@@ -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:
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment