diff options
Diffstat (limited to 'vcl/source/gdi/impgraph.cxx')
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index d32f93eab3b4..13f09ee2bb9c 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -175,7 +175,8 @@ ImpGraphic::ImpGraphic() : meType ( GraphicType::NONE ), mnSizeBytes ( 0 ), mbSwapOut ( false ), - mbDummyContext ( false ) + mbDummyContext ( false ), + maLastUsed (std::chrono::high_resolution_clock::now()) { } @@ -192,6 +193,7 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic) , maVectorGraphicData(rImpGraphic.maVectorGraphicData) , maPdfData(rImpGraphic.maPdfData) , maGraphicExternalLink(rImpGraphic.maGraphicExternalLink) + , maLastUsed (std::chrono::high_resolution_clock::now()) { if( rImpGraphic.mpGfxLink ) mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink ); @@ -218,6 +220,7 @@ ImpGraphic::ImpGraphic(ImpGraphic&& rImpGraphic) , maVectorGraphicData(std::move(rImpGraphic.maVectorGraphicData)) , maPdfData(std::move(rImpGraphic.maPdfData)) , maGraphicExternalLink(rImpGraphic.maGraphicExternalLink) + , maLastUsed (std::chrono::high_resolution_clock::now()) { rImpGraphic.ImplClear(); rImpGraphic.mbDummyContext = false; @@ -228,7 +231,8 @@ ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) : meType ( !rBitmap.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ), mnSizeBytes ( 0 ), mbSwapOut ( false ), - mbDummyContext ( false ) + mbDummyContext ( false ), + maLastUsed (std::chrono::high_resolution_clock::now()) { } @@ -237,7 +241,8 @@ ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) : meType ( !rBitmapEx.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ), mnSizeBytes ( 0 ), mbSwapOut ( false ), - mbDummyContext ( false ) + mbDummyContext ( false ), + maLastUsed (std::chrono::high_resolution_clock::now()) { } @@ -246,7 +251,8 @@ ImpGraphic::ImpGraphic(const VectorGraphicDataPtr& rVectorGraphicDataPtr) mnSizeBytes( 0 ), mbSwapOut( false ), mbDummyContext ( false ), - maVectorGraphicData(rVectorGraphicDataPtr) + maVectorGraphicData(rVectorGraphicDataPtr), + maLastUsed (std::chrono::high_resolution_clock::now()) { } @@ -256,7 +262,8 @@ ImpGraphic::ImpGraphic( const Animation& rAnimation ) : meType ( GraphicType::Bitmap ), mnSizeBytes ( 0 ), mbSwapOut ( false ), - mbDummyContext ( false ) + mbDummyContext ( false ), + maLastUsed (std::chrono::high_resolution_clock::now()) { } @@ -265,18 +272,22 @@ ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) : meType ( GraphicType::GdiMetafile ), mnSizeBytes ( 0 ), mbSwapOut ( false ), - mbDummyContext ( false ) + mbDummyContext ( false ), + maLastUsed (std::chrono::high_resolution_clock::now()) { } ImpGraphic::~ImpGraphic() { + vcl::graphic::Manager::get().unregisterGraphic(this); } ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic ) { if( &rImpGraphic != this ) { + sal_Int64 aOldSizeBytes = mnSizeBytes; + maMetaFile = rImpGraphic.maMetaFile; meType = rImpGraphic.meType; mnSizeBytes = rImpGraphic.mnSizeBytes; @@ -308,6 +319,9 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic ) maVectorGraphicData = rImpGraphic.maVectorGraphicData; maPdfData = rImpGraphic.maPdfData; + maLastUsed = std::chrono::high_resolution_clock::now(); + + vcl::graphic::Manager::get().changeExisting(this, aOldSizeBytes); } return *this; @@ -315,6 +329,8 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic ) ImpGraphic& ImpGraphic::operator=(ImpGraphic&& rImpGraphic) { + sal_Int64 aOldSizeBytes = mnSizeBytes; + maMetaFile = std::move(rImpGraphic.maMetaFile); meType = rImpGraphic.meType; mnSizeBytes = rImpGraphic.mnSizeBytes; @@ -332,6 +348,9 @@ ImpGraphic& ImpGraphic::operator=(ImpGraphic&& rImpGraphic) rImpGraphic.ImplClear(); rImpGraphic.mbDummyContext = false; + maLastUsed = std::chrono::high_resolution_clock::now(); + + vcl::graphic::Manager::get().changeExisting(this, aOldSizeBytes); return *this; } @@ -462,7 +481,9 @@ void ImpGraphic::ImplClear() // cleanup ImplClearGraphics(); meType = GraphicType::NONE; + sal_Int64 nOldSize = mnSizeBytes; mnSizeBytes = 0; + vcl::graphic::Manager::get().changeExisting(this, nOldSize); maGraphicExternalLink.msURL.clear(); } @@ -481,6 +502,8 @@ bool ImpGraphic::ImplIsTransparent() const { bool bRet(true); + ensureAvailable(); + if( meType == GraphicType::Bitmap && !maVectorGraphicData.get()) { bRet = ( mpAnimation ? mpAnimation->IsTransparent() : maEx.IsTransparent() ); @@ -493,6 +516,8 @@ bool ImpGraphic::ImplIsAlpha() const { bool bRet(false); + ensureAvailable(); + if(maVectorGraphicData.get()) { bRet = true; @@ -507,11 +532,14 @@ bool ImpGraphic::ImplIsAlpha() const bool ImpGraphic::ImplIsAnimated() const { + ensureAvailable(); return( mpAnimation != nullptr ); } bool ImpGraphic::ImplIsEPS() const { + ensureAvailable(); + return( ( meType == GraphicType::GdiMetafile ) && ( maMetaFile.GetActionSize() > 0 ) && ( maMetaFile.GetAction( 0 )->GetType() == MetaActionType::EPS ) ); @@ -521,6 +549,8 @@ Bitmap ImpGraphic::ImplGetBitmap(const GraphicConversionParameters& rParameters) { Bitmap aRetBmp; + ensureAvailable(); + if( meType == GraphicType::Bitmap ) { if(maVectorGraphicData.get() && maEx.IsEmpty()) @@ -629,6 +659,8 @@ BitmapEx ImpGraphic::ImplGetBitmapEx(const GraphicConversionParameters& rParamet { BitmapEx aRetBmpEx; + ensureAvailable(); + if( meType == GraphicType::Bitmap ) { if(maVectorGraphicData.get() && maEx.IsEmpty()) @@ -666,6 +698,7 @@ Animation ImpGraphic::ImplGetAnimation() const { Animation aAnimation; + ensureAvailable(); if( mpAnimation ) aAnimation = *mpAnimation; @@ -674,11 +707,13 @@ Animation ImpGraphic::ImplGetAnimation() const const BitmapEx& ImpGraphic::ImplGetBitmapExRef() const { + ensureAvailable(); return maEx; } const GDIMetaFile& ImpGraphic::ImplGetGDIMetaFile() const { + ensureAvailable(); if (!maMetaFile.GetActionSize() && maVectorGraphicData.get() && (VectorGraphicDataType::Emf == maVectorGraphicData->getVectorGraphicDataType() @@ -938,6 +973,7 @@ sal_uLong ImpGraphic::ImplGetSizeBytes() const void ImpGraphic::ImplDraw( OutputDevice* pOutDev, const Point& rDestPt ) const { + ensureAvailable(); if( ImplIsSupportedGraphic() && !ImplIsSwapOut() ) { switch( meType ) @@ -974,6 +1010,7 @@ void ImpGraphic::ImplDraw( OutputDevice* pOutDev, const Point& rDestPt ) const void ImpGraphic::ImplDraw( OutputDevice* pOutDev, const Point& rDestPt, const Size& rDestSize ) const { + ensureAvailable(); if( ImplIsSupportedGraphic() && !ImplIsSwapOut() ) { switch( meType ) @@ -1015,6 +1052,8 @@ void ImpGraphic::ImplStartAnimation( OutputDevice* pOutDev, const Point& rDestPt const Size& rDestSize, long nExtraData, OutputDevice* pFirstFrameOutDev ) { + ensureAvailable(); + if( ImplIsSupportedGraphic() && !ImplIsSwapOut() && mpAnimation ) mpAnimation->Start( pOutDev, rDestPt, rDestSize, nExtraData, pFirstFrameOutDev ); } @@ -1043,6 +1082,7 @@ Link<Animation*,void> ImpGraphic::ImplGetAnimationNotifyHdl() const sal_uInt32 ImpGraphic::ImplGetAnimationLoopCount() const { + ensureAvailable(); return( mpAnimation ? mpAnimation->GetLoopCount() : 0 ); } @@ -1187,6 +1227,8 @@ bool ImpGraphic::ImplWriteEmbedded( SvStream& rOStm ) { bool bRet = false; + ensureAvailable(); + if( ( meType != GraphicType::NONE ) && ( meType != GraphicType::Default ) && !ImplIsSwapOut() ) { const MapMode aMapMode( ImplGetPrefMapMode() ); @@ -1317,6 +1359,8 @@ bool ImpGraphic::ImplSwapOut() } } + if (bRet) + vcl::graphic::Manager::get().swappedOut(this); return bRet; } @@ -1348,6 +1392,15 @@ bool ImpGraphic::ImplSwapOut( SvStream* xOStm ) return bRet; } +bool ImpGraphic::ensureAvailable() const +{ + auto pThis = const_cast<ImpGraphic*>(this); + pThis->maLastUsed = std::chrono::high_resolution_clock::now(); + if (ImplIsSwapOut()) + return pThis->ImplSwapIn(); + return true; +} + bool ImpGraphic::ImplSwapIn() { bool bRet = false; @@ -1383,6 +1436,9 @@ bool ImpGraphic::ImplSwapIn() } } + if (bRet) + vcl::graphic::Manager::get().swappedIn(this); + return bRet; } @@ -1429,6 +1485,8 @@ bool ImpGraphic::ImplSwapIn( SvStream* xIStm ) void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink ) { + ensureAvailable(); + mpGfxLink = o3tl::make_unique<GfxLink>( rGfxLink ); if( mpGfxLink->IsNative() ) @@ -1437,6 +1495,8 @@ void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink ) GfxLink ImpGraphic::ImplGetLink() { + ensureAvailable(); + return( mpGfxLink ? *mpGfxLink : GfxLink() ); } @@ -1449,6 +1509,8 @@ BitmapChecksum ImpGraphic::ImplGetChecksum() const { BitmapChecksum nRet = 0; + ensureAvailable(); + if( ImplIsSupportedGraphic() && !ImplIsSwapOut() ) { switch( meType ) @@ -1493,6 +1555,8 @@ bool ImpGraphic::ImplExportNative( SvStream& rOStm ) const { bool bResult = false; + ensureAvailable(); + if( !rOStm.GetError() ) { if( !ImplIsSwapOut() ) |