diff options
author | Mark Page <aptitude@btconnect.com> | 2016-07-05 14:33:20 +0100 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-07-11 06:32:00 +0000 |
commit | b8c8b0d0c2bb2a1ce61e4d94d0a3e0636db658fa (patch) | |
tree | 922591d03f342f5585e935cd54edae14f533d252 /vcl | |
parent | a4d40892b78070c9e54e0c8a30ed20d3395e68cd (diff) |
Modify ImpGraphic class, GraphicReader context to use unique ptr
Change-Id: I51c3995f4a6e940a5235524eb94dd356b27ae8d7
Reviewed-on: https://gerrit.libreoffice.org/26955
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/impgraph.hxx | 6 | ||||
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 22 | ||||
-rw-r--r-- | vcl/source/filter/igif/gifread.cxx | 17 | ||||
-rw-r--r-- | vcl/source/filter/ixbm/xbmread.cxx | 24 | ||||
-rw-r--r-- | vcl/source/filter/ixpm/xpmread.cxx | 24 | ||||
-rw-r--r-- | vcl/source/filter/jpeg/jpeg.cxx | 23 | ||||
-rw-r--r-- | vcl/source/gdi/graph.cxx | 4 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 13 |
8 files changed, 61 insertions, 72 deletions
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx index bb67c66522fd..817b9cf9b4f4 100644 --- a/vcl/inc/impgraph.hxx +++ b/vcl/inc/impgraph.hxx @@ -41,7 +41,7 @@ private: BitmapEx maEx; ImpSwapInfo maSwapInfo; std::unique_ptr<Animation> mpAnimation; - GraphicReader* mpContext; + std::shared_ptr<GraphicReader> mpContext; std::shared_ptr<ImpSwapFile> mpSwapFile; std::unique_ptr<GfxLink> mpGfxLink; GraphicType meType; @@ -114,8 +114,8 @@ private: private: - GraphicReader* ImplGetContext() { return mpContext;} - void ImplSetContext( GraphicReader* pReader ); + std::shared_ptr<GraphicReader>& ImplGetContext() { return mpContext;} + void ImplSetContext( const std::shared_ptr<GraphicReader>& pReader ); void ImplSetDummyContext( bool value ) { mbDummyContext = value; } bool ImplReadEmbedded( SvStream& rIStream ); bool ImplWriteEmbedded( SvStream& rOStream ); diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index b65a8a02ea78..27fb8a20a23b 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -1330,17 +1330,17 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat css::uno::Sequence< css::beans::PropertyValue >* pFilterData, WMF_EXTERNALHEADER *pExtHeader ) { - OUString aFilterName; - OUString aExternalFilterName; - sal_uLong nStreamBegin; - sal_uInt16 nStatus; - GraphicReader* pContext = rGraphic.GetContext(); - GfxLinkType eLinkType = GfxLinkType::NONE; - bool bDummyContext = rGraphic.IsDummyContext(); - const bool bLinkSet = rGraphic.IsLink(); - FilterConfigItem* pFilterConfigItem = nullptr; - - Size aPreviewSizeHint( 0, 0 ); + OUString aFilterName; + OUString aExternalFilterName; + sal_uLong nStreamBegin; + sal_uInt16 nStatus; + std::shared_ptr<GraphicReader> pContext = rGraphic.GetContext(); + GfxLinkType eLinkType = GfxLinkType::NONE; + bool bDummyContext = rGraphic.IsDummyContext(); + const bool bLinkSet = rGraphic.IsLink(); + FilterConfigItem* pFilterConfigItem = nullptr; + + Size aPreviewSizeHint( 0, 0 ); bool bAllowPartialStreamRead = false; bool bCreateNativeLink = true; diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx index 0609314924c7..47fbce964ee0 100644 --- a/vcl/source/filter/igif/gifread.cxx +++ b/vcl/source/filter/igif/gifread.cxx @@ -885,18 +885,21 @@ ReadState GIFReader::ReadGIF( Graphic& rGraphic ) VCL_DLLPUBLIC bool ImportGIF( SvStream & rStm, Graphic& rGraphic ) { - std::unique_ptr<GIFReader> xGIFReader(static_cast<GIFReader*>(rGraphic.GetContext())); + std::shared_ptr<GraphicReader> pContext = rGraphic.GetContext(); rGraphic.SetContext(nullptr); + GIFReader* pGIFReader = dynamic_cast<GIFReader*>( pContext.get() ); + if (!pGIFReader) + { + pContext = std::make_shared<GIFReader>( rStm ); + pGIFReader = static_cast<GIFReader*>( pContext.get() ); + } SvStreamEndian nOldFormat = rStm.GetEndian(); rStm.SetEndian( SvStreamEndian::LITTLE ); - if (!xGIFReader) - xGIFReader.reset(new GIFReader(rStm)); - bool bRet = true; - ReadState eReadState = xGIFReader->ReadGIF(rGraphic); + ReadState eReadState = pGIFReader->ReadGIF(rGraphic); if (eReadState == GIFREAD_ERROR) { @@ -904,8 +907,8 @@ VCL_DLLPUBLIC bool ImportGIF( SvStream & rStm, Graphic& rGraphic ) } else if (eReadState == GIFREAD_NEED_MORE) { - rGraphic = xGIFReader->GetIntermediateGraphic(); - rGraphic.SetContext(xGIFReader.release()); + rGraphic = pGIFReader->GetIntermediateGraphic(); + rGraphic.SetContext(pContext); } rStm.SetEndian(nOldFormat); diff --git a/vcl/source/filter/ixbm/xbmread.cxx b/vcl/source/filter/ixbm/xbmread.cxx index a8a59a741891..4053f056d53e 100644 --- a/vcl/source/filter/ixbm/xbmread.cxx +++ b/vcl/source/filter/ixbm/xbmread.cxx @@ -381,25 +381,25 @@ ReadState XBMReader::ReadXBM( Graphic& rGraphic ) VCL_DLLPUBLIC bool ImportXBM( SvStream& rStm, Graphic& rGraphic ) { - XBMReader* pXBMReader = static_cast<XBMReader*>( rGraphic.GetContext() ); - ReadState eReadState; - bool bRet = true; + std::shared_ptr<GraphicReader> pContext = rGraphic.GetContext(); + rGraphic.SetContext(nullptr); + XBMReader* pXBMReader = dynamic_cast<XBMReader*>( pContext.get() ); + if (!pXBMReader) + { + pContext = std::make_shared<XBMReader>( rStm ); + pXBMReader = static_cast<XBMReader*>( pContext.get() ); + } - if( !pXBMReader ) - pXBMReader = new XBMReader( rStm ); + bool bRet = true; - rGraphic.SetContext( nullptr ); - eReadState = pXBMReader->ReadXBM( rGraphic ); + ReadState eReadState = pXBMReader->ReadXBM( rGraphic ); if( eReadState == XBMREAD_ERROR ) { bRet = false; - delete pXBMReader; } - else if( eReadState == XBMREAD_OK ) - delete pXBMReader; - else - rGraphic.SetContext( pXBMReader ); + else if( eReadState == XBMREAD_NEED_MORE ) + rGraphic.SetContext( pContext ); return bRet; } diff --git a/vcl/source/filter/ixpm/xpmread.cxx b/vcl/source/filter/ixpm/xpmread.cxx index ef4ef3d1d953..382efb7f3769 100644 --- a/vcl/source/filter/ixpm/xpmread.cxx +++ b/vcl/source/filter/ixpm/xpmread.cxx @@ -723,25 +723,25 @@ bool XPMReader::ImplGetString() VCL_DLLPUBLIC bool ImportXPM( SvStream& rStm, Graphic& rGraphic ) { - XPMReader* pXPMReader = static_cast<XPMReader*>(rGraphic.GetContext()); - ReadState eReadState; - bool bRet = true; + std::shared_ptr<GraphicReader> pContext = rGraphic.GetContext(); + rGraphic.SetContext(nullptr); + XPMReader* pXPMReader = dynamic_cast<XPMReader*>( pContext.get() ); + if (!pXPMReader) + { + pContext = std::make_shared<XPMReader>( rStm ); + pXPMReader = static_cast<XPMReader*>( pContext.get() ); + } - if( !pXPMReader ) - pXPMReader = new XPMReader( rStm ); + bool bRet = true; - rGraphic.SetContext( nullptr ); - eReadState = pXPMReader->ReadXPM( rGraphic ); + ReadState eReadState = pXPMReader->ReadXPM( rGraphic ); if( eReadState == XPMREAD_ERROR ) { bRet = false; - delete pXPMReader; } - else if( eReadState == XPMREAD_OK ) - delete pXPMReader; - else - rGraphic.SetContext( pXPMReader ); + else if( eReadState == XPMREAD_NEED_MORE ) + rGraphic.SetContext( pContext ); return bRet; } diff --git a/vcl/source/filter/jpeg/jpeg.cxx b/vcl/source/filter/jpeg/jpeg.cxx index c3769870aa3f..ca780f1c6bcc 100644 --- a/vcl/source/filter/jpeg/jpeg.cxx +++ b/vcl/source/filter/jpeg/jpeg.cxx @@ -27,14 +27,15 @@ VCL_DLLPUBLIC bool ImportJPEG( SvStream& rInputStream, Graphic& rGraphic, void* pCallerData, GraphicFilterImportFlags nImportFlags ) { - ReadState eReadState; bool bReturn = true; - JPEGReader* pJPEGReader = static_cast<JPEGReader*>( rGraphic.GetContext() ); - - if( !pJPEGReader ) + std::shared_ptr<GraphicReader> pContext = rGraphic.GetContext(); + rGraphic.SetContext(nullptr); + JPEGReader* pJPEGReader = dynamic_cast<JPEGReader*>( pContext.get() ); + if (!pJPEGReader) { - pJPEGReader = new JPEGReader( rInputStream, pCallerData, bool( nImportFlags & GraphicFilterImportFlags::SetLogsizeForJpeg ) ); + pContext = std::make_shared<JPEGReader>( rInputStream, pCallerData, bool( nImportFlags & GraphicFilterImportFlags::SetLogsizeForJpeg ) ); + pJPEGReader = static_cast<JPEGReader*>( pContext.get() ); } if( nImportFlags & GraphicFilterImportFlags::ForPreview ) @@ -46,21 +47,15 @@ VCL_DLLPUBLIC bool ImportJPEG( SvStream& rInputStream, Graphic& rGraphic, void* pJPEGReader->DisablePreviewMode(); } - rGraphic.SetContext( nullptr ); - eReadState = pJPEGReader->Read( rGraphic ); + ReadState eReadState = pJPEGReader->Read( rGraphic ); if( eReadState == JPEGREAD_ERROR ) { bReturn = false; - delete pJPEGReader; - } - else if( eReadState == JPEGREAD_OK ) - { - delete pJPEGReader; } - else + else if( eReadState == JPEGREAD_NEED_MORE ) { - rGraphic.SetContext( pJPEGReader ); + rGraphic.SetContext( pContext ); } return bReturn; diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index 7a61594e1b42..67511af59297 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -496,12 +496,12 @@ sal_uLong Graphic::GetAnimationLoopCount() const return mpImpGraphic->ImplGetAnimationLoopCount(); } -GraphicReader* Graphic::GetContext() +std::shared_ptr<GraphicReader>& Graphic::GetContext() { return mpImpGraphic->ImplGetContext(); } -void Graphic::SetContext( GraphicReader* pReader ) +void Graphic::SetContext( const std::shared_ptr<GraphicReader> &pReader ) { mpImpGraphic->ImplSetContext( pReader ); } diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 5478305f6397..4d7a14fe64b3 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -95,7 +95,6 @@ Size GraphicReader::GetPreviewSize() const } ImpGraphic::ImpGraphic() : - mpContext ( nullptr ), meType ( GraphicType::NONE ), mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), @@ -108,7 +107,6 @@ ImpGraphic::ImpGraphic() : ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) : maMetaFile ( rImpGraphic.maMetaFile ), maEx ( rImpGraphic.maEx ), - mpContext ( nullptr ), mpSwapFile ( rImpGraphic.mpSwapFile ), meType ( rImpGraphic.meType ), mnSizeBytes ( rImpGraphic.mnSizeBytes ), @@ -132,7 +130,6 @@ ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) : ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) : maEx ( rBitmap ), - mpContext ( nullptr ), meType ( !rBitmap.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ), mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), @@ -144,7 +141,6 @@ ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) : ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) : maEx ( rBitmapEx ), - mpContext ( nullptr ), meType ( !rBitmapEx.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ), mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), @@ -155,8 +151,7 @@ ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) : } ImpGraphic::ImpGraphic(const SvgDataPtr& rSvgDataPtr) -: mpContext( nullptr ), - meType( rSvgDataPtr.get() ? GraphicType::Bitmap : GraphicType::NONE ), +: meType( rSvgDataPtr.get() ? GraphicType::Bitmap : GraphicType::NONE ), mnSizeBytes( 0UL ), mnRefCount( 1UL ), mbSwapOut( false ), @@ -169,7 +164,6 @@ ImpGraphic::ImpGraphic(const SvgDataPtr& rSvgDataPtr) ImpGraphic::ImpGraphic( const Animation& rAnimation ) : maEx ( rAnimation.GetBitmapEx() ), mpAnimation ( o3tl::make_unique<Animation>( rAnimation ) ), - mpContext ( nullptr ), meType ( GraphicType::Bitmap ), mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), @@ -181,7 +175,6 @@ ImpGraphic::ImpGraphic( const Animation& rAnimation ) : ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) : maMetaFile ( rMtf ), - mpContext ( nullptr ), meType ( GraphicType::GdiMetafile ), mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), @@ -194,7 +187,6 @@ ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) : ImpGraphic::~ImpGraphic() { ImplClear(); - delete mpContext; } ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic ) @@ -908,9 +900,8 @@ sal_uLong ImpGraphic::ImplGetAnimationLoopCount() const } -void ImpGraphic::ImplSetContext( GraphicReader* pReader ) +void ImpGraphic::ImplSetContext( const std::shared_ptr<GraphicReader>& pReader ) { - assert(!mpContext); mpContext = pReader; mbDummyContext = false; } |