use std to impl this resource sharing

Change-Id: I41ea7bf672040089ccca5cf2bc449a0d0e78b903
Reviewed-on: https://gerrit.libreoffice.org/29219
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara
2016-09-23 11:27:02 +01:00
parent 04f50946de
commit 7adb5c683c
4 changed files with 74 additions and 103 deletions

View File

@@ -106,12 +106,12 @@ class VCL_DLLPUBLIC Graphic : public SvDataCopyStream
{
private:
ImpGraphic* mpImpGraphic;
std::shared_ptr<ImpGraphic> mxImpGraphic;
public:
SAL_DLLPRIVATE void ImplTestRefCount();
SAL_DLLPRIVATE ImpGraphic* ImplGetImpGraphic() const { return mpImpGraphic; }
SAL_DLLPRIVATE ImpGraphic* ImplGetImpGraphic() const { return mxImpGraphic.get(); }
public:
Graphic();

View File

@@ -46,7 +46,6 @@ private:
std::unique_ptr<GfxLink> mpGfxLink;
GraphicType meType;
mutable sal_uLong mnSizeBytes;
sal_uLong mnRefCount;
bool mbSwapOut;
bool mbSwapUnderway;
bool mbDummyContext;
@@ -62,7 +61,9 @@ private:
ImpGraphic(const SvgDataPtr& rSvgDataPtr);
ImpGraphic( const Animation& rAnimation );
ImpGraphic( const GDIMetaFile& rMtf );
public:
virtual ~ImpGraphic();
private:
ImpGraphic& operator=( const ImpGraphic& rImpGraphic );
bool operator==( const ImpGraphic& rImpGraphic ) const;

View File

@@ -179,45 +179,42 @@ static void ImplDrawDefault( OutputDevice* pOutDev, const OUString* pText,
}
Graphic::Graphic()
: mxImpGraphic(new ImpGraphic)
{
mpImpGraphic = new ImpGraphic;
}
Graphic::Graphic( const Graphic& rGraphic ) :
SvDataCopyStream()
{
if( rGraphic.IsAnimated() )
mpImpGraphic = new ImpGraphic( *rGraphic.mpImpGraphic );
mxImpGraphic.reset(new ImpGraphic(*rGraphic.mxImpGraphic));
else
{
mpImpGraphic = rGraphic.mpImpGraphic;
mpImpGraphic->mnRefCount++;
}
mxImpGraphic = rGraphic.mxImpGraphic;
}
Graphic::Graphic( const Bitmap& rBmp )
Graphic::Graphic(const Bitmap& rBmp)
: mxImpGraphic(new ImpGraphic(rBmp))
{
mpImpGraphic = new ImpGraphic( rBmp );
}
Graphic::Graphic( const BitmapEx& rBmpEx )
Graphic::Graphic(const BitmapEx& rBmpEx)
: mxImpGraphic(new ImpGraphic(rBmpEx))
{
mpImpGraphic = new ImpGraphic( rBmpEx );
}
Graphic::Graphic(const SvgDataPtr& rSvgDataPtr)
: mxImpGraphic(new ImpGraphic(rSvgDataPtr))
{
mpImpGraphic = new ImpGraphic(rSvgDataPtr);
}
Graphic::Graphic( const Animation& rAnimation )
Graphic::Graphic(const Animation& rAnimation)
: mxImpGraphic(new ImpGraphic(rAnimation))
{
mpImpGraphic = new ImpGraphic( rAnimation );
}
Graphic::Graphic( const GDIMetaFile& rMtf )
Graphic::Graphic(const GDIMetaFile& rMtf)
: mxImpGraphic(new ImpGraphic(rMtf))
{
mpImpGraphic = new ImpGraphic( rMtf );
}
Graphic::Graphic( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic )
@@ -229,32 +226,24 @@ Graphic::Graphic( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic
if( pGraphic )
{
if( pGraphic->IsAnimated() )
mpImpGraphic = new ImpGraphic( *pGraphic->mpImpGraphic );
if (pGraphic->IsAnimated())
mxImpGraphic.reset(new ImpGraphic(*pGraphic->mxImpGraphic));
else
{
mpImpGraphic = pGraphic->mpImpGraphic;
mpImpGraphic->mnRefCount++;
}
mxImpGraphic = pGraphic->mxImpGraphic;
}
else
mpImpGraphic = new ImpGraphic;
mxImpGraphic.reset(new ImpGraphic);
}
Graphic::~Graphic()
{
if( mpImpGraphic->mnRefCount == 1UL )
delete mpImpGraphic;
else
mpImpGraphic->mnRefCount--;
}
void Graphic::ImplTestRefCount()
{
if( mpImpGraphic->mnRefCount > 1UL )
if (!mxImpGraphic.unique())
{
mpImpGraphic->mnRefCount--;
mpImpGraphic = new ImpGraphic( *mpImpGraphic );
mxImpGraphic.reset(new ImpGraphic(*mxImpGraphic));
}
}
@@ -264,23 +253,11 @@ Graphic& Graphic::operator=( const Graphic& rGraphic )
{
if( rGraphic.IsAnimated() )
{
if( mpImpGraphic->mnRefCount == 1UL )
delete mpImpGraphic;
else
mpImpGraphic->mnRefCount--;
mpImpGraphic = new ImpGraphic( *rGraphic.mpImpGraphic );
mxImpGraphic.reset(new ImpGraphic(*rGraphic.mxImpGraphic));
}
else
{
rGraphic.mpImpGraphic->mnRefCount++;
if( mpImpGraphic->mnRefCount == 1UL )
delete mpImpGraphic;
else
mpImpGraphic->mnRefCount--;
mpImpGraphic = rGraphic.mpImpGraphic;
mxImpGraphic = rGraphic.mxImpGraphic;
}
}
@@ -289,79 +266,79 @@ Graphic& Graphic::operator=( const Graphic& rGraphic )
bool Graphic::operator==( const Graphic& rGraphic ) const
{
return( *mpImpGraphic == *rGraphic.mpImpGraphic );
return (*mxImpGraphic == *rGraphic.mxImpGraphic);
}
bool Graphic::operator!=( const Graphic& rGraphic ) const
{
return( *mpImpGraphic != *rGraphic.mpImpGraphic );
return (*mxImpGraphic != *rGraphic.mxImpGraphic);
}
bool Graphic::operator!() const
{
return( GraphicType::NONE == mpImpGraphic->ImplGetType() );
return (GraphicType::NONE == mxImpGraphic->ImplGetType());
}
void Graphic::Clear()
{
ImplTestRefCount();
mpImpGraphic->ImplClear();
mxImpGraphic->ImplClear();
}
GraphicType Graphic::GetType() const
{
return mpImpGraphic->ImplGetType();
return mxImpGraphic->ImplGetType();
}
void Graphic::SetDefaultType()
{
ImplTestRefCount();
mpImpGraphic->ImplSetDefaultType();
mxImpGraphic->ImplSetDefaultType();
}
bool Graphic::IsSupportedGraphic() const
{
return mpImpGraphic->ImplIsSupportedGraphic();
return mxImpGraphic->ImplIsSupportedGraphic();
}
bool Graphic::IsTransparent() const
{
return mpImpGraphic->ImplIsTransparent();
return mxImpGraphic->ImplIsTransparent();
}
bool Graphic::IsAlpha() const
{
return mpImpGraphic->ImplIsAlpha();
return mxImpGraphic->ImplIsAlpha();
}
bool Graphic::IsAnimated() const
{
return mpImpGraphic->ImplIsAnimated();
return mxImpGraphic->ImplIsAnimated();
}
bool Graphic::IsEPS() const
{
return mpImpGraphic->ImplIsEPS();
return mxImpGraphic->ImplIsEPS();
}
Bitmap Graphic::GetBitmap(const GraphicConversionParameters& rParameters) const
{
return mpImpGraphic->ImplGetBitmap(rParameters);
return mxImpGraphic->ImplGetBitmap(rParameters);
}
BitmapEx Graphic::GetBitmapEx(const GraphicConversionParameters& rParameters) const
{
return mpImpGraphic->ImplGetBitmapEx(rParameters);
return mxImpGraphic->ImplGetBitmapEx(rParameters);
}
Animation Graphic::GetAnimation() const
{
return mpImpGraphic->ImplGetAnimation();
return mxImpGraphic->ImplGetAnimation();
}
const GDIMetaFile& Graphic::GetGDIMetaFile() const
{
return mpImpGraphic->ImplGetGDIMetaFile();
return mxImpGraphic->ImplGetGDIMetaFile();
}
uno::Reference< graphic::XGraphic > Graphic::GetXGraphic() const
@@ -387,24 +364,24 @@ uno::Reference< graphic::XGraphic > Graphic::GetXGraphic() const
Size Graphic::GetPrefSize() const
{
return mpImpGraphic->ImplGetPrefSize();
return mxImpGraphic->ImplGetPrefSize();
}
void Graphic::SetPrefSize( const Size& rPrefSize )
{
ImplTestRefCount();
mpImpGraphic->ImplSetPrefSize( rPrefSize );
mxImpGraphic->ImplSetPrefSize( rPrefSize );
}
MapMode Graphic::GetPrefMapMode() const
{
return mpImpGraphic->ImplGetPrefMapMode();
return mxImpGraphic->ImplGetPrefMapMode();
}
void Graphic::SetPrefMapMode( const MapMode& rPrefMapMode )
{
ImplTestRefCount();
mpImpGraphic->ImplSetPrefMapMode( rPrefMapMode );
mxImpGraphic->ImplSetPrefMapMode( rPrefMapMode );
}
basegfx::B2DSize Graphic::GetPPI() const
@@ -433,8 +410,8 @@ Size Graphic::GetSizePixel( const OutputDevice* pRefDevice ) const
{
Size aRet;
if( GraphicType::Bitmap == mpImpGraphic->ImplGetType() )
aRet = mpImpGraphic->ImplGetBitmapEx(GraphicConversionParameters()).GetSizePixel();
if( GraphicType::Bitmap == mxImpGraphic->ImplGetType() )
aRet = mxImpGraphic->ImplGetBitmapEx(GraphicConversionParameters()).GetSizePixel();
else
aRet = ( pRefDevice ? pRefDevice : Application::GetDefaultDevice() )->LogicToPixel( GetPrefSize(), GetPrefMapMode() );
@@ -443,21 +420,21 @@ Size Graphic::GetSizePixel( const OutputDevice* pRefDevice ) const
sal_uLong Graphic::GetSizeBytes() const
{
return mpImpGraphic->ImplGetSizeBytes();
return mxImpGraphic->ImplGetSizeBytes();
}
void Graphic::Draw( OutputDevice* pOutDev, const Point& rDestPt ) const
{
mpImpGraphic->ImplDraw( pOutDev, rDestPt );
mxImpGraphic->ImplDraw( pOutDev, rDestPt );
}
void Graphic::Draw( OutputDevice* pOutDev,
const Point& rDestPt, const Size& rDestSz ) const
{
if( GraphicType::Default == mpImpGraphic->ImplGetType() )
if( GraphicType::Default == mxImpGraphic->ImplGetType() )
ImplDrawDefault( pOutDev, nullptr, nullptr, nullptr, nullptr, rDestPt, rDestSz );
else
mpImpGraphic->ImplDraw( pOutDev, rDestPt, rDestSz );
mxImpGraphic->ImplDraw( pOutDev, rDestPt, rDestSz );
}
void Graphic::DrawEx( OutputDevice* pOutDev, const OUString& rText,
@@ -472,136 +449,136 @@ void Graphic::StartAnimation( OutputDevice* pOutDev, const Point& rDestPt,
OutputDevice* pFirstFrameOutDev )
{
ImplTestRefCount();
mpImpGraphic->ImplStartAnimation( pOutDev, rDestPt, rDestSz, nExtraData, pFirstFrameOutDev );
mxImpGraphic->ImplStartAnimation( pOutDev, rDestPt, rDestSz, nExtraData, pFirstFrameOutDev );
}
void Graphic::StopAnimation( OutputDevice* pOutDev, long nExtraData )
{
ImplTestRefCount();
mpImpGraphic->ImplStopAnimation( pOutDev, nExtraData );
mxImpGraphic->ImplStopAnimation( pOutDev, nExtraData );
}
void Graphic::SetAnimationNotifyHdl( const Link<Animation*,void>& rLink )
{
mpImpGraphic->ImplSetAnimationNotifyHdl( rLink );
mxImpGraphic->ImplSetAnimationNotifyHdl( rLink );
}
Link<Animation*,void> Graphic::GetAnimationNotifyHdl() const
{
return mpImpGraphic->ImplGetAnimationNotifyHdl();
return mxImpGraphic->ImplGetAnimationNotifyHdl();
}
sal_uLong Graphic::GetAnimationLoopCount() const
{
return mpImpGraphic->ImplGetAnimationLoopCount();
return mxImpGraphic->ImplGetAnimationLoopCount();
}
std::shared_ptr<GraphicReader>& Graphic::GetContext()
{
return mpImpGraphic->ImplGetContext();
return mxImpGraphic->ImplGetContext();
}
void Graphic::SetContext( const std::shared_ptr<GraphicReader> &pReader )
{
mpImpGraphic->ImplSetContext( pReader );
mxImpGraphic->ImplSetContext( pReader );
}
void Graphic::SetDummyContext( bool value )
{
mpImpGraphic->ImplSetDummyContext( value );
mxImpGraphic->ImplSetDummyContext( value );
}
bool Graphic::IsDummyContext()
{
return mpImpGraphic->ImplIsDummyContext();
return mxImpGraphic->ImplIsDummyContext();
}
bool Graphic::SwapOut()
{
ImplTestRefCount();
return mpImpGraphic->ImplSwapOut();
return mxImpGraphic->ImplSwapOut();
}
void Graphic::SwapOutAsLink()
{
ImplTestRefCount();
mpImpGraphic->ImplSwapOutAsLink();
mxImpGraphic->ImplSwapOutAsLink();
}
bool Graphic::SwapOut( SvStream* pOStream )
{
ImplTestRefCount();
return mpImpGraphic->ImplSwapOut( pOStream );
return mxImpGraphic->ImplSwapOut( pOStream );
}
bool Graphic::SwapIn()
{
ImplTestRefCount();
return mpImpGraphic->ImplSwapIn();
return mxImpGraphic->ImplSwapIn();
}
bool Graphic::SwapIn( SvStream* pStrm )
{
ImplTestRefCount();
return mpImpGraphic->ImplSwapIn( pStrm );
return mxImpGraphic->ImplSwapIn( pStrm );
}
bool Graphic::IsSwapOut() const
{
return mpImpGraphic->ImplIsSwapOut();
return mxImpGraphic->ImplIsSwapOut();
}
void Graphic::SetLink( const GfxLink& rGfxLink )
{
ImplTestRefCount();
mpImpGraphic->ImplSetLink( rGfxLink );
mxImpGraphic->ImplSetLink( rGfxLink );
}
GfxLink Graphic::GetLink() const
{
return mpImpGraphic->ImplGetLink();
return mxImpGraphic->ImplGetLink();
}
bool Graphic::IsLink() const
{
return mpImpGraphic->ImplIsLink();
return mxImpGraphic->ImplIsLink();
}
BitmapChecksum Graphic::GetChecksum() const
{
return mpImpGraphic->ImplGetChecksum();
return mxImpGraphic->ImplGetChecksum();
}
bool Graphic::ExportNative( SvStream& rOStream ) const
{
return mpImpGraphic->ImplExportNative( rOStream );
return mxImpGraphic->ImplExportNative( rOStream );
}
SvStream& ReadGraphic( SvStream& rIStream, Graphic& rGraphic )
{
rGraphic.ImplTestRefCount();
return ReadImpGraphic( rIStream, *rGraphic.mpImpGraphic );
return ReadImpGraphic(rIStream, *rGraphic.mxImpGraphic);
}
SvStream& WriteGraphic( SvStream& rOStream, const Graphic& rGraphic )
{
return WriteImpGraphic( rOStream, *rGraphic.mpImpGraphic );
return WriteImpGraphic(rOStream, *rGraphic.mxImpGraphic);
}
const SvgDataPtr& Graphic::getSvgData() const
{
return mpImpGraphic->getSvgData();
return mxImpGraphic->getSvgData();
}
void Graphic::setPdfData(const uno::Sequence<sal_Int8>& rPdfData)
{
ImplTestRefCount();
mpImpGraphic->maPdfData = rPdfData;
mxImpGraphic->maPdfData = rPdfData;
}
const uno::Sequence<sal_Int8>& Graphic::getPdfData() const
{
return mpImpGraphic->maPdfData;
return mxImpGraphic->maPdfData;
}
namespace {

View File

@@ -97,7 +97,6 @@ Size GraphicReader::GetPreviewSize() const
ImpGraphic::ImpGraphic() :
meType ( GraphicType::NONE ),
mnSizeBytes ( 0UL ),
mnRefCount ( 1UL ),
mbSwapOut ( false ),
mbSwapUnderway ( false ),
mbDummyContext ( false )
@@ -110,7 +109,6 @@ ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) :
mpSwapFile ( rImpGraphic.mpSwapFile ),
meType ( rImpGraphic.meType ),
mnSizeBytes ( rImpGraphic.mnSizeBytes ),
mnRefCount ( 1UL ),
mbSwapOut ( rImpGraphic.mbSwapOut ),
mbSwapUnderway ( false ),
mbDummyContext ( rImpGraphic.mbDummyContext )
@@ -132,7 +130,6 @@ ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) :
maEx ( rBitmap ),
meType ( !rBitmap.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ),
mnSizeBytes ( 0UL ),
mnRefCount ( 1UL ),
mbSwapOut ( false ),
mbSwapUnderway ( false ),
mbDummyContext ( false )
@@ -143,7 +140,6 @@ ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) :
maEx ( rBitmapEx ),
meType ( !rBitmapEx.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ),
mnSizeBytes ( 0UL ),
mnRefCount ( 1UL ),
mbSwapOut ( false ),
mbSwapUnderway ( false ),
mbDummyContext ( false )
@@ -153,7 +149,6 @@ ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) :
ImpGraphic::ImpGraphic(const SvgDataPtr& rSvgDataPtr)
: meType( rSvgDataPtr.get() ? GraphicType::Bitmap : GraphicType::NONE ),
mnSizeBytes( 0UL ),
mnRefCount( 1UL ),
mbSwapOut( false ),
mbSwapUnderway( false ),
mbDummyContext ( false ),
@@ -166,7 +161,6 @@ ImpGraphic::ImpGraphic( const Animation& rAnimation ) :
mpAnimation ( o3tl::make_unique<Animation>( rAnimation ) ),
meType ( GraphicType::Bitmap ),
mnSizeBytes ( 0UL ),
mnRefCount ( 1UL ),
mbSwapOut ( false ),
mbSwapUnderway ( false ),
mbDummyContext ( false )
@@ -177,7 +171,6 @@ ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) :
maMetaFile ( rMtf ),
meType ( GraphicType::GdiMetafile ),
mnSizeBytes ( 0UL ),
mnRefCount ( 1UL ),
mbSwapOut ( false ),
mbSwapUnderway ( false ),
mbDummyContext ( false )