LibreOffice Module sd (master) 1
|
This low level cache is the actual bitmap container. More...
#include <SlsBitmapCache.hxx>
Classes | |
class | CacheBitmapContainer |
class | CacheEntry |
Public Types | |
typedef const SdrPage * | CacheKey |
The key for looking up preview bitmaps is a pointer to an SdrPage object. More... | |
typedef ::std::vector< CacheKey > | CacheIndex |
Public Member Functions | |
BitmapCache () | |
Create a new cache for bitmap objects. More... | |
~BitmapCache () | |
The destructor clears the cache and releases all bitmaps still in it. More... | |
void | Clear () |
Remove all preview bitmaps from the cache. More... | |
bool | IsFull () const |
Return <TRUE> when the cache is full, i.e. More... | |
sal_Int32 | GetSize () const |
Return the memory size that is occupied by all non-precious bitmaps in the cache. More... | |
bool | HasBitmap (const CacheKey &rKey) |
Return <TRUE> when a preview bitmap exists for the given key. More... | |
bool | BitmapIsUpToDate (const CacheKey &rKey) |
Return <TRUE> when a preview bitmap exists for the given key and when it is up-to-date. More... | |
BitmapEx | GetBitmap (const CacheKey &rKey) |
Return the preview bitmap for the given contact object. More... | |
BitmapEx | GetMarkedBitmap (const CacheKey &rKey) |
Return the marked preview bitmap for the given contact object. More... | |
void | ReleaseBitmap (const CacheKey &rKey) |
Release the reference to the preview bitmap that is associated with the given key. More... | |
bool | InvalidateBitmap (const CacheKey &rKey) |
Mark the specified preview bitmap as not being up-to-date anymore. More... | |
void | InvalidateCache () |
Mark all preview bitmaps as not being up-to-date anymore. More... | |
void | SetBitmap (const CacheKey &rKey, const BitmapEx &rPreview, bool bIsPrecious) |
Add or replace a bitmap for the given key. More... | |
void | SetMarkedBitmap (const CacheKey &rKey, const BitmapEx &rPreview) |
Add or replace a marked bitmap for the given key. More... | |
void | SetPrecious (const CacheKey &rKey, bool bIsPrecious) |
Mark the specified preview bitmap as precious, i.e. More... | |
void | ReCalculateTotalCacheSize () |
Calculate the cache size. More... | |
void | Recycle (const BitmapCache &rCache) |
Use the previews in the given cache to initialize missing previews. More... | |
CacheIndex | GetCacheIndex () const |
Return a list of sorted cache keys that represent an index into (a part of) the cache. More... | |
void | Compress (const CacheKey &rKey, const std::shared_ptr< BitmapCompressor > &rpCompressor) |
Compress the specified preview bitmap with the given bitmap compressor. More... | |
Private Types | |
enum | CacheOperation { ADD , REMOVE } |
Update mnNormalCacheSize or mnPreciousCacheSize according to the precious flag of the specified preview bitmap and the specified operation. More... | |
Private Member Functions | |
void | UpdateCacheSize (std::unique_lock< std::mutex > &rGuard, const CacheEntry &rKey, CacheOperation eOperation) |
void | ReCalculateTotalCacheSize (std::unique_lock< std::mutex > &rGuard) |
void | SetBitmap (std::unique_lock< std::mutex > &rGuard, const CacheKey &rKey, const BitmapEx &rPreview, bool bIsPrecious) |
Private Attributes | |
std::mutex | maMutex |
std::unique_ptr< CacheBitmapContainer > | mpBitmapContainer |
sal_Int32 | mnNormalCacheSize |
Total size of bytes that are occupied by bitmaps in the cache for whom the slides are currently not inside the visible area. More... | |
sal_Int32 | mnPreciousCacheSize |
Total size of bytes that are occupied by bitmaps in the cache for whom the slides are currently visible. More... | |
sal_Int32 | mnCurrentAccessTime |
At the moment the access time is not an actual time or date value but a counter that is increased with every access. More... | |
sal_Int32 | mnMaximalNormalCacheSize |
The maximal cache size for the off-screen preview bitmaps. More... | |
::std::unique_ptr< CacheCompactor > | mpCacheCompactor |
The cache compactor is used to reduce the number of bytes used by off-screen preview bitmaps. More... | |
bool | mbIsFull |
This flag stores if the cache is or recently was full, i.e. More... | |
This low level cache is the actual bitmap container.
It supports a precious flag for every preview bitmap and keeps track of total sizes for all previews with/without this flag. The precious flag is used by compaction algorithms to determine which previews may be compressed or even discarded and which have to remain in their original form. The precious flag is usually set for the visible previews.
Additionally to the actual preview there is an optional marked preview. This is used for slides excluded from the slide show which have a preview that shows a mark (some sort of bitmap overlay) to that effect.
Definition at line 44 of file SlsBitmapCache.hxx.
typedef ::std::vector<CacheKey> sd::slidesorter::cache::BitmapCache::CacheIndex |
Definition at line 56 of file SlsBitmapCache.hxx.
typedef const SdrPage* sd::slidesorter::cache::BitmapCache::CacheKey |
The key for looking up preview bitmaps is a pointer to an SdrPage object.
The prior use of PageObjectViewObjectContact objects (which ultimately use them) turned out to be less suitable because their life time is shorter then that of the page objects. Frequent destruction and re-creation of the preview bitmaps was the result.
Definition at line 53 of file SlsBitmapCache.hxx.
|
private |
Update mnNormalCacheSize or mnPreciousCacheSize according to the precious flag of the specified preview bitmap and the specified operation.
Enumerator | |
---|---|
ADD | |
REMOVE |
Definition at line 198 of file SlsBitmapCache.hxx.
|
explicit |
Create a new cache for bitmap objects.
The default value from the configuration is used. When that does not exist then an internal default value is used.
Definition at line 121 of file SlsBitmapCache.cxx.
References Any, sd::slidesorter::cache::CacheCompactor::Create(), GetValue, sd::slidesorter::cache::CacheConfiguration::Instance(), mnMaximalNormalCacheSize, and mpCacheCompactor.
sd::slidesorter::cache::BitmapCache::~BitmapCache | ( | ) |
The destructor clears the cache and releases all bitmaps still in it.
Definition at line 136 of file SlsBitmapCache.cxx.
References Clear().
bool sd::slidesorter::cache::BitmapCache::BitmapIsUpToDate | ( | const CacheKey & | rKey | ) |
Return <TRUE> when a preview bitmap exists for the given key and when it is up-to-date.
Definition at line 160 of file SlsBitmapCache.cxx.
References maMutex, and mpBitmapContainer.
void sd::slidesorter::cache::BitmapCache::Clear | ( | ) |
Remove all preview bitmaps from the cache.
After this call the cache is empty.
Definition at line 141 of file SlsBitmapCache.cxx.
References maMutex, mnCurrentAccessTime, mnNormalCacheSize, mnPreciousCacheSize, and mpBitmapContainer.
Referenced by ~BitmapCache().
void sd::slidesorter::cache::BitmapCache::Compress | ( | const CacheKey & | rKey, |
const std::shared_ptr< BitmapCompressor > & | rpCompressor | ||
) |
Compress the specified preview bitmap with the given bitmap compressor.
A reference to the compressor is stored for later decompression.
Definition at line 412 of file SlsBitmapCache.cxx.
References ADD, maMutex, mpBitmapContainer, REMOVE, and UpdateCacheSize().
Return the preview bitmap for the given contact object.
Definition at line 172 of file SlsBitmapCache.cxx.
References ADD, maMutex, mnCurrentAccessTime, mpBitmapContainer, REMOVE, SetBitmap(), and UpdateCacheSize().
BitmapCache::CacheIndex sd::slidesorter::cache::BitmapCache::GetCacheIndex | ( | ) | const |
Return a list of sorted cache keys that represent an index into (a part of) the cache.
The entries of the index are sorted according to last access times with the least recently access time first. Entries with the precious flag set are omitted. Entries with that have no preview bitmaps are omitted.
Definition at line 381 of file SlsBitmapCache.cxx.
References aIndex, maMutex, and mpBitmapContainer.
Return the marked preview bitmap for the given contact object.
Definition at line 200 of file SlsBitmapCache.cxx.
References maMutex, mnCurrentAccessTime, and mpBitmapContainer.
|
inline |
Return the memory size that is occupied by all non-precious bitmaps in the cache.
Definition at line 82 of file SlsBitmapCache.hxx.
References mnNormalCacheSize.
bool sd::slidesorter::cache::BitmapCache::HasBitmap | ( | const CacheKey & | rKey | ) |
Return <TRUE> when a preview bitmap exists for the given key.
Definition at line 151 of file SlsBitmapCache.cxx.
References maMutex, and mpBitmapContainer.
bool sd::slidesorter::cache::BitmapCache::InvalidateBitmap | ( | const CacheKey & | rKey | ) |
Mark the specified preview bitmap as not being up-to-date anymore.
Definition at line 226 of file SlsBitmapCache.cxx.
References ADD, maMutex, mpBitmapContainer, REMOVE, and UpdateCacheSize().
void sd::slidesorter::cache::BitmapCache::InvalidateCache | ( | ) |
Mark all preview bitmaps as not being up-to-date anymore.
Definition at line 249 of file SlsBitmapCache.cxx.
References maMutex, mpBitmapContainer, and ReCalculateTotalCacheSize().
|
inline |
Return <TRUE> when the cache is full, i.e.
the cache compactor had to be run.
Definition at line 77 of file SlsBitmapCache.hxx.
References mbIsFull.
void sd::slidesorter::cache::BitmapCache::ReCalculateTotalCacheSize | ( | ) |
Calculate the cache size.
This should rarely be necessary because the cache size is tracked with each modification of preview bitmaps.
Definition at line 335 of file SlsBitmapCache.cxx.
References maMutex, and ReCalculateTotalCacheSize().
Referenced by InvalidateCache(), and ReCalculateTotalCacheSize().
|
private |
Definition at line 341 of file SlsBitmapCache.cxx.
References mbIsFull, mnMaximalNormalCacheSize, mnNormalCacheSize, mnPreciousCacheSize, mpBitmapContainer, and SAL_INFO.
void sd::slidesorter::cache::BitmapCache::Recycle | ( | const BitmapCache & | rCache | ) |
Use the previews in the given cache to initialize missing previews.
Definition at line 357 of file SlsBitmapCache.cxx.
References ADD, maMutex, mnCurrentAccessTime, mpBitmapContainer, REMOVE, and UpdateCacheSize().
void sd::slidesorter::cache::BitmapCache::ReleaseBitmap | ( | const CacheKey & | rKey | ) |
Release the reference to the preview bitmap that is associated with the given key.
Definition at line 214 of file SlsBitmapCache.cxx.
References maMutex, mpBitmapContainer, REMOVE, and UpdateCacheSize().
void sd::slidesorter::cache::BitmapCache::SetBitmap | ( | const CacheKey & | rKey, |
const BitmapEx & | rPreview, | ||
bool | bIsPrecious | ||
) |
Add or replace a bitmap for the given key.
Definition at line 260 of file SlsBitmapCache.cxx.
References maMutex, and SetBitmap().
Referenced by GetBitmap(), and SetBitmap().
|
private |
Definition at line 269 of file SlsBitmapCache.cxx.
References ADD, mnCurrentAccessTime, mpBitmapContainer, REMOVE, and UpdateCacheSize().
void sd::slidesorter::cache::BitmapCache::SetMarkedBitmap | ( | const CacheKey & | rKey, |
const BitmapEx & | rPreview | ||
) |
Add or replace a marked bitmap for the given key.
Definition at line 295 of file SlsBitmapCache.cxx.
References ADD, maMutex, mnCurrentAccessTime, mpBitmapContainer, REMOVE, and UpdateCacheSize().
void sd::slidesorter::cache::BitmapCache::SetPrecious | ( | const CacheKey & | rKey, |
bool | bIsPrecious | ||
) |
Mark the specified preview bitmap as precious, i.e.
that it must not be compressed or otherwise removed from the cache.
Definition at line 311 of file SlsBitmapCache.cxx.
References ADD, maMutex, mnCurrentAccessTime, mpBitmapContainer, REMOVE, and UpdateCacheSize().
|
private |
Definition at line 427 of file SlsBitmapCache.cxx.
References ADD, sd::slidesorter::cache::BitmapCache::CacheEntry::GetMemorySize(), sd::slidesorter::cache::BitmapCache::CacheEntry::IsPrecious(), mbIsFull, mnMaximalNormalCacheSize, mnNormalCacheSize, mnPreciousCacheSize, mpCacheCompactor, REMOVE, and SAL_INFO.
Referenced by Compress(), GetBitmap(), InvalidateBitmap(), Recycle(), ReleaseBitmap(), SetBitmap(), SetMarkedBitmap(), and SetPrecious().
|
mutableprivate |
Definition at line 157 of file SlsBitmapCache.hxx.
Referenced by BitmapIsUpToDate(), Clear(), Compress(), GetBitmap(), GetCacheIndex(), GetMarkedBitmap(), HasBitmap(), InvalidateBitmap(), InvalidateCache(), ReCalculateTotalCacheSize(), Recycle(), ReleaseBitmap(), SetBitmap(), SetMarkedBitmap(), and SetPrecious().
|
private |
This flag stores if the cache is or recently was full, i.e.
the cache compactor has or had to be run in order to reduce the cache size to the allowed value.
Definition at line 192 of file SlsBitmapCache.hxx.
Referenced by IsFull(), ReCalculateTotalCacheSize(), and UpdateCacheSize().
|
private |
At the moment the access time is not an actual time or date value but a counter that is increased with every access.
It thus defines the same ordering as a true time.
Definition at line 175 of file SlsBitmapCache.hxx.
Referenced by Clear(), GetBitmap(), GetMarkedBitmap(), Recycle(), SetBitmap(), SetMarkedBitmap(), and SetPrecious().
|
private |
The maximal cache size for the off-screen preview bitmaps.
When mnNormalCacheSize grows larger than this value then the mpCacheCompactor member is used to reduce the cache size.
Definition at line 181 of file SlsBitmapCache.hxx.
Referenced by BitmapCache(), ReCalculateTotalCacheSize(), and UpdateCacheSize().
|
private |
Total size of bytes that are occupied by bitmaps in the cache for whom the slides are currently not inside the visible area.
Definition at line 164 of file SlsBitmapCache.hxx.
Referenced by Clear(), GetSize(), ReCalculateTotalCacheSize(), and UpdateCacheSize().
|
private |
Total size of bytes that are occupied by bitmaps in the cache for whom the slides are currently visible.
Definition at line 169 of file SlsBitmapCache.hxx.
Referenced by Clear(), ReCalculateTotalCacheSize(), and UpdateCacheSize().
|
private |
Definition at line 159 of file SlsBitmapCache.hxx.
Referenced by BitmapIsUpToDate(), Clear(), Compress(), GetBitmap(), GetCacheIndex(), GetMarkedBitmap(), HasBitmap(), InvalidateBitmap(), InvalidateCache(), ReCalculateTotalCacheSize(), Recycle(), ReleaseBitmap(), SetBitmap(), SetMarkedBitmap(), and SetPrecious().
|
private |
The cache compactor is used to reduce the number of bytes used by off-screen preview bitmaps.
Definition at line 186 of file SlsBitmapCache.hxx.
Referenced by BitmapCache(), and UpdateCacheSize().