diff options
author | Kai Ahrens <ka@openoffice.org> | 2001-05-08 08:09:18 +0000 |
---|---|---|
committer | Kai Ahrens <ka@openoffice.org> | 2001-05-08 08:09:18 +0000 |
commit | b791b13f7b07344f43ebee2bb137eec506585853 (patch) | |
tree | 4630d53581222bb5a4fc58b09e2c1c508fb3365e /goodies/source/graphic | |
parent | 14d1b152bb29ff08015459cb715fcd1cefb4c6a3 (diff) |
#81229#: added cache timeout mechanism
Diffstat (limited to 'goodies/source/graphic')
-rw-r--r-- | goodies/source/graphic/grfcache.cxx | 124 | ||||
-rw-r--r-- | goodies/source/graphic/grfcache.hxx | 13 | ||||
-rw-r--r-- | goodies/source/graphic/grfmgr.cxx | 18 | ||||
-rw-r--r-- | goodies/source/graphic/grfmgr2.cxx | 18 |
4 files changed, 148 insertions, 25 deletions
diff --git a/goodies/source/graphic/grfcache.cxx b/goodies/source/graphic/grfcache.cxx index 2f512d3224a0..3b4ea7e6e45b 100644 --- a/goodies/source/graphic/grfcache.cxx +++ b/goodies/source/graphic/grfcache.cxx @@ -2,9 +2,9 @@ * * $RCSfile: grfcache.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: ka $ $Date: 2001-04-10 16:06:27 $ + * last change: $Author: ka $ $Date: 2001-05-08 09:09:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,12 +59,19 @@ * ************************************************************************/ +#include <vos/timer.hxx> #include <tools/debug.hxx> #include <vcl/outdev.hxx> #include <vcl/poly.hxx> #include "grfcache.hxx" // ----------- +// - Defines - +// ----------- + +#define RELEASE_TIMEOUT 10000 + +// ----------- // - statics - // ----------- @@ -437,6 +444,7 @@ class GraphicDisplayCacheEntry { private: + ::vos::TTimeValue maReleaseTime; const GraphicCacheEntry* mpRefCacheEntry; GDIMetaFile* mpMtf; BitmapEx* mpBmpEx; @@ -458,7 +466,9 @@ public: mpRefCacheEntry( pRefCacheEntry ), mpMtf( NULL ), mpBmpEx( new BitmapEx( rBmpEx ) ), maAttr( rAttr ), maOutSizePix( pOut->LogicToPixel( rSz ) ), - mnCacheSize( GetNeededSize( pOut, rPt, rSz, rObj, rAttr ) ) {} + mnCacheSize( GetNeededSize( pOut, rPt, rSz, rObj, rAttr ) ) + { + } GraphicDisplayCacheEntry( const GraphicCacheEntry* pRefCacheEntry, OutputDevice* pOut, const Point& rPt, const Size& rSz, @@ -467,7 +477,10 @@ public: mpRefCacheEntry( pRefCacheEntry ), mpMtf( new GDIMetaFile( rMtf ) ), mpBmpEx( NULL ), maAttr( rAttr ), maOutSizePix( pOut->LogicToPixel( rSz ) ), - mnCacheSize( GetNeededSize( pOut, rPt, rSz, rObj, rAttr ) ) {} + mnCacheSize( GetNeededSize( pOut, rPt, rSz, rObj, rAttr ) ) + { + } + ~GraphicDisplayCacheEntry(); @@ -476,6 +489,9 @@ public: const ULONG GetCacheSize() const { return mnCacheSize; } const GraphicCacheEntry* GetReferencedCacheEntry() const { return mpRefCacheEntry; } + void SetReleaseTime( const ::vos::TTimeValue& rReleaseTime ) { maReleaseTime = rReleaseTime; } + const ::vos::TTimeValue& GetReleaseTime() const { return maReleaseTime; } + BOOL Matches( OutputDevice* pOut, const Point& rPtPixel, const Size& rSzPixel, const GraphicCacheEntry* pCacheEntry, const GraphicAttr& rAttr ) const { @@ -558,11 +574,15 @@ void GraphicDisplayCacheEntry::Draw( OutputDevice* pOut, const Point& rPt, const // ----------------------- GraphicCache::GraphicCache( GraphicManager& rMgr, ULONG nDisplayCacheSize, ULONG nMaxObjDisplayCacheSize ) : - mrMgr ( rMgr ), - mnMaxDisplaySize ( nDisplayCacheSize ), - mnMaxObjDisplaySize ( nMaxObjDisplayCacheSize ), - mnUsedDisplaySize ( 0UL ) + mrMgr ( rMgr ), + mnMaxDisplaySize ( nDisplayCacheSize ), + mnMaxObjDisplaySize ( nMaxObjDisplayCacheSize ), + mnUsedDisplaySize ( 0UL ), + mnReleaseTimeoutSeconds ( 0UL ) { + maReleaseTimer.SetTimeoutHdl( LINK( this, GraphicCache, ReleaseTimeoutHdl ) ); + maReleaseTimer.SetTimeout( RELEASE_TIMEOUT ); + maReleaseTimer.Start(); } // ----------------------------------------------------------------------------- @@ -743,6 +763,29 @@ void GraphicCache::SetMaxObjDisplayCacheSize( ULONG nNewMaxObjSize, BOOL bDestro // ----------------------------------------------------------------------------- +void GraphicCache::SetCacheTimeout( ULONG nTimeoutSeconds ) +{ + if( mnReleaseTimeoutSeconds != nTimeoutSeconds ) + { + GraphicDisplayCacheEntry* pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.First(); + ::vos::TTimeValue aReleaseTime; + + if( ( mnReleaseTimeoutSeconds = nTimeoutSeconds ) != 0 ) + { + osl_getSystemTime( &aReleaseTime ); + aReleaseTime.addTime( ::vos::TTimeValue( nTimeoutSeconds, 0 ) ); + } + + while( pDisplayEntry ) + { + pDisplayEntry->SetReleaseTime( aReleaseTime ); + pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.Next(); + } + } +} + +// ----------------------------------------------------------------------------- + void GraphicCache::ClearDisplayCache() { for( void* pObj = maDisplayCache.First(); pObj; pObj = maDisplayCache.Next() ) @@ -816,8 +859,16 @@ BOOL GraphicCache::CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, GraphicDisplayCacheEntry* pNewEntry = new GraphicDisplayCacheEntry( ImplGetCacheEntry( rObj ), pOut, rPt, rSz, rObj, rAttr, rBmpEx ); + if( GetCacheTimeout() ) + { + ::vos::TTimeValue aReleaseTime; - maDisplayCache.Insert( pNewEntry, (ULONG) 0 ); + osl_getSystemTime( &aReleaseTime ); + aReleaseTime.addTime( ::vos::TTimeValue( GetCacheTimeout(), 0 ) ); + pNewEntry->SetReleaseTime( aReleaseTime ); + } + + maDisplayCache.Insert( pNewEntry, LIST_APPEND ); mnUsedDisplaySize += pNewEntry->GetCacheSize(); bRet = TRUE; } @@ -842,8 +893,16 @@ BOOL GraphicCache::CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, GraphicDisplayCacheEntry* pNewEntry = new GraphicDisplayCacheEntry( ImplGetCacheEntry( rObj ), pOut, rPt, rSz, rObj, rAttr, rMtf ); + if( GetCacheTimeout() ) + { + ::vos::TTimeValue aReleaseTime; + + osl_getSystemTime( &aReleaseTime ); + aReleaseTime.addTime( ::vos::TTimeValue( GetCacheTimeout(), 0 ) ); + pNewEntry->SetReleaseTime( aReleaseTime ); + } - maDisplayCache.Insert( pNewEntry, (ULONG) 0 ); + maDisplayCache.Insert( pNewEntry, LIST_APPEND ); mnUsedDisplaySize += pNewEntry->GetCacheSize(); bRet = TRUE; } @@ -866,8 +925,18 @@ BOOL GraphicCache::DrawDisplayCacheObj( OutputDevice* pOut, const Point& rPt, co { if( pDisplayCacheEntry->Matches( pOut, aPtPixel, aSzPixel, pCacheEntry, rAttr ) ) { + ::vos::TTimeValue aReleaseTime; + // put found object at last used position maDisplayCache.Insert( maDisplayCache.Remove( pDisplayCacheEntry ), LIST_APPEND ); + + if( GetCacheTimeout() ) + { + osl_getSystemTime( &aReleaseTime ); + aReleaseTime.addTime( ::vos::TTimeValue( GetCacheTimeout(), 0 ) ); + } + + pDisplayCacheEntry->SetReleaseTime( aReleaseTime ); bRet = TRUE; } else @@ -886,10 +955,13 @@ BOOL GraphicCache::ImplFreeDisplayCacheSpace( ULONG nSizeToFree ) { ULONG nFreedSize = 0UL; - if( nSizeToFree && ( nSizeToFree <= mnMaxDisplaySize ) ) + if( nSizeToFree ) { void* pObj = maDisplayCache.First(); + if( nSizeToFree > mnUsedDisplaySize ) + nSizeToFree = mnUsedDisplaySize; + while( pObj ) { GraphicDisplayCacheEntry* pCacheObj = (GraphicDisplayCacheEntry*) pObj; @@ -922,3 +994,33 @@ GraphicCacheEntry* GraphicCache::ImplGetCacheEntry( const GraphicObject& rObj ) return pRet; } +// ----------------------------------------------------------------------------- + +IMPL_LINK( GraphicCache, ReleaseTimeoutHdl, Timer*, pTimer ) +{ + pTimer->Stop(); + + ::vos::TTimeValue aCurTime; + GraphicDisplayCacheEntry* pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.First(); + + osl_getSystemTime( &aCurTime ); + + while( pDisplayEntry ) + { + const ::vos::TTimeValue& rReleaseTime = pDisplayEntry->GetReleaseTime(); + + if( !rReleaseTime.isEmpty() && ( rReleaseTime < aCurTime ) ) + { + mnUsedDisplaySize -= pDisplayEntry->GetCacheSize(); + maDisplayCache.Remove( pDisplayEntry ); + delete pDisplayEntry; + pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.GetCurObject(); + } + else + pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.Next(); + } + + pTimer->Start(); + + return 0; +} diff --git a/goodies/source/graphic/grfcache.hxx b/goodies/source/graphic/grfcache.hxx index 508ec2e15206..3cc9eae8536a 100644 --- a/goodies/source/graphic/grfcache.hxx +++ b/goodies/source/graphic/grfcache.hxx @@ -2,9 +2,9 @@ * * $RCSfile: grfcache.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 16:30:16 $ + * last change: $Author: ka $ $Date: 2001-05-08 09:09:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -64,6 +64,7 @@ #include <tools/list.hxx> #include <vcl/graph.hxx> +#include <vcl/timer.hxx> #include "grfmgr.hxx" // ----------------------- @@ -77,8 +78,10 @@ class GraphicCache private: GraphicManager& mrMgr; + Timer maReleaseTimer; List maGraphicCache; List maDisplayCache; + ULONG mnReleaseTimeoutSeconds; ULONG mnMaxDisplaySize; ULONG mnMaxObjDisplaySize; ULONG mnUsedDisplaySize; @@ -86,6 +89,9 @@ private: BOOL ImplFreeDisplayCacheSpace( ULONG nSizeToFree ); GraphicCacheEntry* ImplGetCacheEntry( const GraphicObject& rObj ); + + DECL_LINK( ReleaseTimeoutHdl, Timer* pTimer ); + public: GraphicCache( GraphicManager& rMgr, @@ -115,6 +121,9 @@ public: ULONG GetUsedDisplayCacheSize() const { return mnUsedDisplaySize; } ULONG GetFreeDisplayCacheSize() const { return( mnMaxDisplaySize - mnUsedDisplaySize ); } + void SetCacheTimeout( ULONG nTimeoutSeconds ); + ULONG GetCacheTimeout() const { return mnReleaseTimeoutSeconds; } + void ClearDisplayCache(); BOOL IsDisplayCacheable( OutputDevice* pOut, const Point& rPt, const Size& rSz, const GraphicObject& rObj, const GraphicAttr& rAttr ) const; diff --git a/goodies/source/graphic/grfmgr.cxx b/goodies/source/graphic/grfmgr.cxx index 7116dd95c063..c66ed19c4a35 100644 --- a/goodies/source/graphic/grfmgr.cxx +++ b/goodies/source/graphic/grfmgr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: grfmgr.cxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: ka $ $Date: 2001-02-15 11:48:22 $ + * last change: $Author: ka $ $Date: 2001-05-08 09:09:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,16 +70,13 @@ #include <vcl/metaact.hxx> #include <vcl/virdev.hxx> #include <vcl/salbtype.hxx> +#include <svtools/cacheoptions.hxx> #include "grfmgr.hxx" // ----------- // - Defines - // ----------- -#define GRFMGR_CACHESIZE_STANDARD 10000000UL -#define GRFMGR_OBJCACHESIZE_STANDARD 2500000UL -#define GRFMGR_CACHESIZE_APPSERVER 10000000UL -#define GRFMGR_OBJCACHESIZE_APPSERVER 2500000UL #define WATERMARK_LUM_OFFSET 50 #define WATERMARK_CON_OFFSET -70 @@ -247,10 +244,11 @@ void GraphicObject::ImplSetGraphicManager( const GraphicManager* pMgr, const Byt { if( !mpGlobalMgr ) { - if( Application::IsRemoteServer() ) - mpGlobalMgr = new GraphicManager( GRFMGR_CACHESIZE_APPSERVER, GRFMGR_OBJCACHESIZE_APPSERVER ); - else - mpGlobalMgr = new GraphicManager( GRFMGR_CACHESIZE_STANDARD, GRFMGR_OBJCACHESIZE_STANDARD ); + SvtCacheOptions aCacheOptions; + + mpGlobalMgr = new GraphicManager( aCacheOptions.GetGraphicManagerTotalCacheSize(), + aCacheOptions.GetGraphicManagerObjectCacheSize() ); + mpGlobalMgr->SetCacheTimeout( aCacheOptions.GetGraphicManagerObjectReleaseTime() ); } mpMgr = mpGlobalMgr; diff --git a/goodies/source/graphic/grfmgr2.cxx b/goodies/source/graphic/grfmgr2.cxx index 511c3191299a..82b09311c865 100644 --- a/goodies/source/graphic/grfmgr2.cxx +++ b/goodies/source/graphic/grfmgr2.cxx @@ -2,9 +2,9 @@ * * $RCSfile: grfmgr2.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: ka $ $Date: 2000-11-24 09:35:47 $ + * last change: $Author: ka $ $Date: 2001-05-08 09:09:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -142,6 +142,20 @@ ULONG GraphicManager::GetFreeCacheSize() const // ----------------------------------------------------------------------------- +void GraphicManager::SetCacheTimeout( ULONG nTimeoutSeconds ) +{ + mpCache->SetCacheTimeout( nTimeoutSeconds ); +} + +// ----------------------------------------------------------------------------- + +ULONG GraphicManager::GetCacheTimeout() const +{ + return mpCache->GetCacheTimeout(); +} + +// ----------------------------------------------------------------------------- + void GraphicManager::ClearCache() { mpCache->ClearDisplayCache(); |