LibreOffice Module sd (master) 1
SlsBitmapCache.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <vcl/bitmapex.hxx>
23#include <mutex>
24#include <memory>
25
26class SdrPage;
27
29{
30class CacheCompactor;
31class BitmapCompressor;
32
45{
46public:
53 typedef const SdrPage* CacheKey;
54 class CacheEntry;
56 typedef ::std::vector<CacheKey> CacheIndex;
57
63 explicit BitmapCache();
64
68
72 void Clear();
73
77 bool IsFull() const { return mbIsFull; }
78
82 sal_Int32 GetSize() const { return mnNormalCacheSize; }
83
86 bool HasBitmap(const CacheKey& rKey);
87
91 bool BitmapIsUpToDate(const CacheKey& rKey);
92
95 BitmapEx GetBitmap(const CacheKey& rKey);
96
100
104 void ReleaseBitmap(const CacheKey& rKey);
105
113 bool InvalidateBitmap(const CacheKey& rKey);
114
117 void InvalidateCache();
118
121 void SetBitmap(const CacheKey& rKey, const BitmapEx& rPreview, bool bIsPrecious);
122
125 void SetMarkedBitmap(const CacheKey& rKey, const BitmapEx& rPreview);
126
130 void SetPrecious(const CacheKey& rKey, bool bIsPrecious);
131
137
140 void Recycle(const BitmapCache& rCache);
141
149
154 void Compress(const CacheKey& rKey, const std::shared_ptr<BitmapCompressor>& rpCompressor);
155
156private:
157 mutable std::mutex maMutex;
158
159 std::unique_ptr<CacheBitmapContainer> mpBitmapContainer;
160
165
170
176
182
186 ::std::unique_ptr<CacheCompactor> mpCacheCompactor;
187
193
199 {
201 REMOVE
202 };
203 void UpdateCacheSize(std::unique_lock<std::mutex>& rGuard, const CacheEntry& rKey,
204 CacheOperation eOperation);
205
206 void ReCalculateTotalCacheSize(std::unique_lock<std::mutex>& rGuard);
207
208 void SetBitmap(std::unique_lock<std::mutex>& rGuard, const CacheKey& rKey,
209 const BitmapEx& rPreview, bool bIsPrecious);
210};
211
212} // end of namespace ::sd::slidesorter::cache
213
214/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This low level cache is the actual bitmap container.
void ReCalculateTotalCacheSize()
Calculate the cache size.
void Recycle(const BitmapCache &rCache)
Use the previews in the given cache to initialize missing previews.
bool InvalidateBitmap(const CacheKey &rKey)
Mark the specified preview bitmap as not being up-to-date anymore.
sal_Int32 mnMaximalNormalCacheSize
The maximal cache size for the off-screen preview bitmaps.
void SetPrecious(const CacheKey &rKey, bool bIsPrecious)
Mark the specified preview bitmap as precious, i.e.
::std::vector< CacheKey > CacheIndex
std::unique_ptr< CacheBitmapContainer > mpBitmapContainer
::std::unique_ptr< CacheCompactor > mpCacheCompactor
The cache compactor is used to reduce the number of bytes used by off-screen preview bitmaps.
BitmapEx GetBitmap(const CacheKey &rKey)
Return the preview bitmap for the given contact object.
void SetMarkedBitmap(const CacheKey &rKey, const BitmapEx &rPreview)
Add or replace a marked bitmap for the given key.
void Compress(const CacheKey &rKey, const std::shared_ptr< BitmapCompressor > &rpCompressor)
Compress the specified preview bitmap with the given bitmap compressor.
bool IsFull() const
Return <TRUE> when the cache is full, i.e.
bool HasBitmap(const CacheKey &rKey)
Return <TRUE> when a preview bitmap exists for the given key.
void SetBitmap(const CacheKey &rKey, const BitmapEx &rPreview, bool bIsPrecious)
Add or replace a bitmap for the given key.
sal_Int32 mnNormalCacheSize
Total size of bytes that are occupied by bitmaps in the cache for whom the slides are currently not i...
void Clear()
Remove all preview bitmaps from the cache.
CacheIndex GetCacheIndex() const
Return a list of sorted cache keys that represent an index into (a part of) the cache.
sal_Int32 GetSize() const
Return the memory size that is occupied by all non-precious bitmaps in the cache.
void ReleaseBitmap(const CacheKey &rKey)
Release the reference to the preview bitmap that is associated with the given key.
bool BitmapIsUpToDate(const CacheKey &rKey)
Return <TRUE> when a preview bitmap exists for the given key and when it is up-to-date.
const SdrPage * CacheKey
The key for looking up preview bitmaps is a pointer to an SdrPage object.
~BitmapCache()
The destructor clears the cache and releases all bitmaps still in it.
CacheOperation
Update mnNormalCacheSize or mnPreciousCacheSize according to the precious flag of the specified previ...
BitmapCache()
Create a new cache for bitmap objects.
bool mbIsFull
This flag stores if the cache is or recently was full, i.e.
void UpdateCacheSize(std::unique_lock< std::mutex > &rGuard, const CacheEntry &rKey, CacheOperation eOperation)
BitmapEx GetMarkedBitmap(const CacheKey &rKey)
Return the marked preview bitmap for the given contact object.
void InvalidateCache()
Mark all preview bitmaps as not being up-to-date anymore.
sal_Int32 mnCurrentAccessTime
At the moment the access time is not an actual time or date value but a counter that is increased wit...
sal_Int32 mnPreciousCacheSize
Total size of bytes that are occupied by bitmaps in the cache for whom the slides are currently visib...