LibreOffice Module sd (master) 1
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
sd::slidesorter::cache::BitmapCache Class Reference

This low level cache is the actual bitmap container. More...

#include <SlsBitmapCache.hxx>

Classes

class  CacheBitmapContainer
 
class  CacheEntry
 

Public Types

typedef const SdrPageCacheKey
 The key for looking up preview bitmaps is a pointer to an SdrPage object. More...
 
typedef ::std::vector< CacheKeyCacheIndex
 

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< CacheBitmapContainermpBitmapContainer
 
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< CacheCompactormpCacheCompactor
 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...
 

Detailed Description

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.

Member Typedef Documentation

◆ CacheIndex

Definition at line 56 of file SlsBitmapCache.hxx.

◆ 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.

Member Enumeration Documentation

◆ CacheOperation

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.

Constructor & Destructor Documentation

◆ BitmapCache()

sd::slidesorter::cache::BitmapCache::BitmapCache ( )
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.

◆ ~BitmapCache()

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().

Member Function Documentation

◆ BitmapIsUpToDate()

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.

◆ Clear()

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().

◆ Compress()

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().

◆ GetBitmap()

BitmapEx sd::slidesorter::cache::BitmapCache::GetBitmap ( const CacheKey rKey)

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().

◆ GetCacheIndex()

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.

◆ GetMarkedBitmap()

BitmapEx sd::slidesorter::cache::BitmapCache::GetMarkedBitmap ( const CacheKey rKey)

Return the marked preview bitmap for the given contact object.

Definition at line 200 of file SlsBitmapCache.cxx.

References maMutex, mnCurrentAccessTime, and mpBitmapContainer.

◆ GetSize()

sal_Int32 sd::slidesorter::cache::BitmapCache::GetSize ( ) const
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.

◆ HasBitmap()

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.

◆ InvalidateBitmap()

bool sd::slidesorter::cache::BitmapCache::InvalidateBitmap ( const CacheKey rKey)

Mark the specified preview bitmap as not being up-to-date anymore.

Returns
When the key references a page in the cache then return <TRUE>. When the key is not known then <FALSE> is returned.

Definition at line 226 of file SlsBitmapCache.cxx.

References ADD, maMutex, mpBitmapContainer, REMOVE, and UpdateCacheSize().

◆ InvalidateCache()

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().

◆ IsFull()

bool sd::slidesorter::cache::BitmapCache::IsFull ( ) const
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.

◆ ReCalculateTotalCacheSize() [1/2]

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().

◆ ReCalculateTotalCacheSize() [2/2]

void sd::slidesorter::cache::BitmapCache::ReCalculateTotalCacheSize ( std::unique_lock< std::mutex > &  rGuard)
private

◆ Recycle()

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().

◆ ReleaseBitmap()

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().

◆ SetBitmap() [1/2]

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().

◆ SetBitmap() [2/2]

void sd::slidesorter::cache::BitmapCache::SetBitmap ( std::unique_lock< std::mutex > &  rGuard,
const CacheKey rKey,
const BitmapEx rPreview,
bool  bIsPrecious 
)
private

Definition at line 269 of file SlsBitmapCache.cxx.

References ADD, mnCurrentAccessTime, mpBitmapContainer, REMOVE, and UpdateCacheSize().

◆ SetMarkedBitmap()

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().

◆ SetPrecious()

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().

◆ UpdateCacheSize()

void sd::slidesorter::cache::BitmapCache::UpdateCacheSize ( std::unique_lock< std::mutex > &  rGuard,
const CacheEntry rKey,
CacheOperation  eOperation 
)
private

Member Data Documentation

◆ maMutex

std::mutex sd::slidesorter::cache::BitmapCache::maMutex
mutableprivate

◆ mbIsFull

bool sd::slidesorter::cache::BitmapCache::mbIsFull
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().

◆ mnCurrentAccessTime

sal_Int32 sd::slidesorter::cache::BitmapCache::mnCurrentAccessTime
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().

◆ mnMaximalNormalCacheSize

sal_Int32 sd::slidesorter::cache::BitmapCache::mnMaximalNormalCacheSize
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().

◆ mnNormalCacheSize

sal_Int32 sd::slidesorter::cache::BitmapCache::mnNormalCacheSize
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().

◆ mnPreciousCacheSize

sal_Int32 sd::slidesorter::cache::BitmapCache::mnPreciousCacheSize
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().

◆ mpBitmapContainer

std::unique_ptr<CacheBitmapContainer> sd::slidesorter::cache::BitmapCache::mpBitmapContainer
private

◆ mpCacheCompactor

::std::unique_ptr<CacheCompactor> sd::slidesorter::cache::BitmapCache::mpCacheCompactor
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().


The documentation for this class was generated from the following files: