diff options
Diffstat (limited to 'sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx')
-rw-r--r--[-rwxr-xr-x] | sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx | 150 |
1 files changed, 111 insertions, 39 deletions
diff --git a/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx b/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx index 1bbecbef3d66..ddb50ea878e0 100755..100644 --- a/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx +++ b/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx @@ -33,7 +33,6 @@ #include "SlsBitmapCompressor.hxx" #include "SlsCacheConfiguration.hxx" -#include "taskpane/SlideSorterCacheDisplay.hxx" #include "sdpage.hxx" #include "drawdoc.hxx" @@ -55,8 +54,7 @@ namespace sd { namespace slidesorter { namespace cache { class BitmapCache::CacheEntry { public: - CacheEntry(const ::boost::shared_ptr<BitmapEx>& rpBitmap, - sal_Int32 nLastAccessTime, bool bIsPrecious); + CacheEntry(const Bitmap& rBitmap, sal_Int32 nLastAccessTime, bool bIsPrecious); CacheEntry(sal_Int32 nLastAccessTime, bool bIsPrecious); ~CacheEntry (void) {}; inline void Recycle (const CacheEntry& rEntry); @@ -68,18 +66,26 @@ public: void SetUpToDate (bool bIsUpToDate) { mbIsUpToDate = bIsUpToDate; } sal_Int32 GetAccessTime (void) const { return mnLastAccessTime; } void SetAccessTime (sal_Int32 nAccessTime) { mnLastAccessTime = nAccessTime; } - ::boost::shared_ptr<BitmapEx> GetPreview (void) const { return mpPreview; } - inline void SetPreview (const ::boost::shared_ptr<BitmapEx>& rpPreview); + + Bitmap GetPreview (void) const { return maPreview; } + inline void SetPreview (const Bitmap& rPreview); bool HasPreview (void) const; + + Bitmap GetMarkedPreview (void) const { return maMarkedPreview; } + inline void SetMarkedPreview (const Bitmap& rMarkePreview); + bool HasMarkedPreview (void) const; + bool HasReplacement (void) const { return (mpReplacement.get() != NULL); } inline bool HasLosslessReplacement (void) const; - void Clear (void) { mpPreview.reset(); mpReplacement.reset(); mpCompressor.reset(); } + void Clear (void) { maPreview.SetEmpty(); maMarkedPreview.SetEmpty(); + mpReplacement.reset(); mpCompressor.reset(); } void Invalidate (void) { mpReplacement.reset(); mpCompressor.reset(); mbIsUpToDate = false; } bool IsPrecious (void) const { return mbIsPrecious; } void SetPrecious (bool bIsPrecious) { mbIsPrecious = bIsPrecious; } private: - ::boost::shared_ptr<BitmapEx> mpPreview; + Bitmap maPreview; + Bitmap maMarkedPreview; ::boost::shared_ptr<BitmapReplacement> mpReplacement; ::boost::shared_ptr<BitmapCompressor> mpCompressor; Size maBitmapSize; @@ -221,7 +227,7 @@ bool BitmapCache::BitmapIsUpToDate (const CacheKey& rKey) -::boost::shared_ptr<BitmapEx> BitmapCache::GetBitmap (const CacheKey& rKey) +Bitmap BitmapCache::GetBitmap (const CacheKey& rKey) { ::osl::MutexGuard aGuard (maMutex); @@ -230,10 +236,9 @@ bool BitmapCache::BitmapIsUpToDate (const CacheKey& rKey) { // Create an empty bitmap for the given key that acts as placeholder // until we are given the real one. Mark it as not being up to date. - SetBitmap (rKey, ::boost::shared_ptr<BitmapEx>(new BitmapEx()), false); + SetBitmap(rKey, Bitmap(), false); iEntry = mpBitmapContainer->find(rKey); iEntry->second.SetUpToDate(false); - SSCD_SET_UPTODATE(iEntry->first,false); } else { @@ -253,7 +258,39 @@ bool BitmapCache::BitmapIsUpToDate (const CacheKey& rKey) -void BitmapCache::InvalidateBitmap (const CacheKey& rKey) +Bitmap BitmapCache::GetMarkedBitmap (const CacheKey& rKey) +{ + ::osl::MutexGuard aGuard (maMutex); + + CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey)); + if (iEntry != mpBitmapContainer->end()) + { + iEntry->second.SetAccessTime(mnCurrentAccessTime++); + return iEntry->second.GetMarkedPreview(); + } + else + return Bitmap(); +} + + + + +void BitmapCache::ReleaseBitmap (const CacheKey& rKey) +{ + ::osl::MutexGuard aGuard (maMutex); + + CacheBitmapContainer::iterator aIterator (mpBitmapContainer->find(rKey)); + if (aIterator != mpBitmapContainer->end()) + { + UpdateCacheSize(aIterator->second, REMOVE); + mpBitmapContainer->erase(aIterator); + } +} + + + + +bool BitmapCache::InvalidateBitmap (const CacheKey& rKey) { ::osl::MutexGuard aGuard (maMutex); @@ -261,7 +298,6 @@ void BitmapCache::InvalidateBitmap (const CacheKey& rKey) if (iEntry != mpBitmapContainer->end()) { iEntry->second.SetUpToDate(false); - SSCD_SET_UPTODATE(iEntry->first,false); // When there is a preview then we release the replacement. The // preview itself is kept until a new one is created. @@ -269,10 +305,12 @@ void BitmapCache::InvalidateBitmap (const CacheKey& rKey) { UpdateCacheSize(iEntry->second, REMOVE); iEntry->second.Invalidate(); - SSCD_SET_UPTODATE(iEntry->first,false); UpdateCacheSize(iEntry->second, ADD); } + return true; } + else + return false; } @@ -286,7 +324,6 @@ void BitmapCache::InvalidateCache (void) for (iEntry=mpBitmapContainer->begin(); iEntry!=mpBitmapContainer->end(); ++iEntry) { iEntry->second.Invalidate(); - SSCD_SET_UPTODATE(iEntry->first,false); } ReCalculateTotalCacheSize(); } @@ -296,7 +333,7 @@ void BitmapCache::InvalidateCache (void) void BitmapCache::SetBitmap ( const CacheKey& rKey, - const ::boost::shared_ptr<BitmapEx>& rpPreview, + const Bitmap& rPreview, bool bIsPrecious) { ::osl::MutexGuard aGuard (maMutex); @@ -305,16 +342,15 @@ void BitmapCache::SetBitmap ( if (iEntry != mpBitmapContainer->end()) { UpdateCacheSize(iEntry->second, REMOVE); - iEntry->second.SetPreview(rpPreview); + iEntry->second.SetPreview(rPreview); iEntry->second.SetUpToDate(true); - SSCD_SET_UPTODATE(iEntry->first,true); iEntry->second.SetAccessTime(mnCurrentAccessTime++); } else { iEntry = mpBitmapContainer->insert(CacheBitmapContainer::value_type ( rKey, - CacheEntry (rpPreview, mnCurrentAccessTime++, bIsPrecious)) + CacheEntry(rPreview, mnCurrentAccessTime++, bIsPrecious)) ).first; } @@ -325,6 +361,25 @@ void BitmapCache::SetBitmap ( +void BitmapCache::SetMarkedBitmap ( + const CacheKey& rKey, + const Bitmap& rPreview) +{ + ::osl::MutexGuard aGuard (maMutex); + + CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey)); + if (iEntry != mpBitmapContainer->end()) + { + UpdateCacheSize(iEntry->second, REMOVE); + iEntry->second.SetMarkedPreview(rPreview); + iEntry->second.SetAccessTime(mnCurrentAccessTime++); + UpdateCacheSize(iEntry->second, ADD); + } +} + + + + void BitmapCache::SetPrecious (const CacheKey& rKey, bool bIsPrecious) { ::osl::MutexGuard aGuard (maMutex); @@ -343,9 +398,7 @@ void BitmapCache::SetPrecious (const CacheKey& rKey, bool bIsPrecious) { iEntry = mpBitmapContainer->insert(CacheBitmapContainer::value_type ( rKey, - CacheEntry ( - ::boost::shared_ptr<BitmapEx>(), - mnCurrentAccessTime++, bIsPrecious)) + CacheEntry(Bitmap(), mnCurrentAccessTime++, bIsPrecious)) ).first; UpdateCacheSize(iEntry->second, ADD); } @@ -503,7 +556,8 @@ void BitmapCache::UpdateCacheSize (const CacheEntry& rEntry, CacheOperation eOpe BitmapCache::CacheEntry::CacheEntry( sal_Int32 nLastAccessTime, bool bIsPrecious) - : mpPreview(), + : maPreview(), + maMarkedPreview(), mbIsUpToDate(true), mnLastAccessTime(nLastAccessTime), mbIsPrecious(bIsPrecious) @@ -514,10 +568,11 @@ BitmapCache::CacheEntry::CacheEntry( BitmapCache::CacheEntry::CacheEntry( - const ::boost::shared_ptr<BitmapEx>& rpPreview, + const Bitmap& rPreview, sal_Int32 nLastAccessTime, bool bIsPrecious) - : mpPreview(rpPreview), + : maPreview(rPreview), + maMarkedPreview(), mbIsUpToDate(true), mnLastAccessTime(nLastAccessTime), mbIsPrecious(bIsPrecious) @@ -532,7 +587,8 @@ inline void BitmapCache::CacheEntry::Recycle (const CacheEntry& rEntry) if ((rEntry.HasPreview() || rEntry.HasLosslessReplacement()) && ! (HasPreview() || HasLosslessReplacement())) { - mpPreview = rEntry.mpPreview; + maPreview = rEntry.maPreview; + maMarkedPreview = rEntry.maMarkedPreview; mpReplacement = rEntry.mpReplacement; mpCompressor = rEntry.mpCompressor; mnLastAccessTime = rEntry.mnLastAccessTime; @@ -546,8 +602,8 @@ inline void BitmapCache::CacheEntry::Recycle (const CacheEntry& rEntry) inline sal_Int32 BitmapCache::CacheEntry::GetMemorySize (void) const { sal_Int32 nSize (0); - if (mpPreview.get() != NULL) - nSize += mpPreview->GetSizeBytes(); + nSize += maPreview.GetSizeBytes(); + nSize += maMarkedPreview.GetSizeBytes(); if (mpReplacement.get() != NULL) nSize += mpReplacement->GetMemorySize(); return nSize; @@ -558,14 +614,14 @@ inline sal_Int32 BitmapCache::CacheEntry::GetMemorySize (void) const void BitmapCache::CacheEntry::Compress (const ::boost::shared_ptr<BitmapCompressor>& rpCompressor) { - if (mpPreview.get() != NULL) + if ( ! maPreview.IsEmpty()) { if (mpReplacement.get() == NULL) { - mpReplacement = rpCompressor->Compress(mpPreview); + mpReplacement = rpCompressor->Compress(maPreview); #ifdef VERBOSE - sal_uInt32 nOldSize (mpPreview->GetSizeBytes()); + sal_uInt32 nOldSize (maPreview.GetSizeBytes()); sal_uInt32 nNewSize (mpReplacement.get()!=NULL ? mpReplacement->GetMemorySize() : 0); if (nOldSize == 0) nOldSize = 1; @@ -580,7 +636,8 @@ void BitmapCache::CacheEntry::Compress (const ::boost::shared_ptr<BitmapCompress mpCompressor = rpCompressor; } - mpPreview.reset(); + maPreview.SetEmpty(); + maMarkedPreview.SetEmpty(); } } @@ -589,9 +646,10 @@ void BitmapCache::CacheEntry::Compress (const ::boost::shared_ptr<BitmapCompress inline void BitmapCache::CacheEntry::Decompress (void) { - if (mpReplacement.get()!=NULL && mpCompressor.get()!=NULL && mpPreview.get()==NULL) + if (mpReplacement.get()!=NULL && mpCompressor.get()!=NULL && maPreview.IsEmpty()) { - mpPreview = mpCompressor->Decompress(*mpReplacement); + maPreview = mpCompressor->Decompress(*mpReplacement); + maMarkedPreview.SetEmpty(); if ( ! mpCompressor->IsLossless()) mbIsUpToDate = false; } @@ -599,9 +657,10 @@ inline void BitmapCache::CacheEntry::Decompress (void) -inline void BitmapCache::CacheEntry::SetPreview (const ::boost::shared_ptr<BitmapEx>& rpPreview) +inline void BitmapCache::CacheEntry::SetPreview (const Bitmap& rPreview) { - mpPreview = rpPreview; + maPreview = rPreview; + maMarkedPreview.SetEmpty(); mpReplacement.reset(); mpCompressor.reset(); } @@ -611,10 +670,23 @@ inline void BitmapCache::CacheEntry::SetPreview (const ::boost::shared_ptr<Bitma bool BitmapCache::CacheEntry::HasPreview (void) const { - if (mpPreview.get() != NULL) - return mpPreview->GetSizePixel().Width()>0 && mpPreview->GetSizePixel().Height()>0; - else - return false; + return ! maPreview.IsEmpty(); +} + + + + +inline void BitmapCache::CacheEntry::SetMarkedPreview (const Bitmap& rMarkedPreview) +{ + maMarkedPreview = rMarkedPreview; +} + + + + +bool BitmapCache::CacheEntry::HasMarkedPreview (void) const +{ + return ! maMarkedPreview.IsEmpty(); } |