24#include <officecfg/Office/Common.hxx>
33void setupConfigurationValuesIfPossible(sal_Int64& rMemoryLimit,
34 std::chrono::seconds& rAllowedIdleTime,
bool& bSwapEnabled)
41 using officecfg::Office::Common::Cache;
43 rMemoryLimit = Cache::GraphicManager::GraphicMemoryLimit::get();
45 = std::chrono::seconds(Cache::GraphicManager::GraphicAllowedIdleTime::get());
46 bSwapEnabled = Cache::GraphicManager::GraphicSwappingEnabled::get();
57 return gStaticManager;
61 : mnAllowedIdleTime(10)
63 , mbReducingGraphicMemory(false)
64 , mnMemoryLimit(300000000)
66 , maSwapOutTimer(
"graphic::Manager maSwapOutTimer")
86 for (
ImpGraphic* pEachImpGraphic : aImpGraphicList)
91 if (pEachImpGraphic->isSwappedOut())
95 if (nCurrentGraphicSize > 100000 || bDropAll)
97 if (!pEachImpGraphic->mpContext)
99 auto aCurrent = std::chrono::high_resolution_clock::now();
100 auto aDeltaTime = aCurrent - pEachImpGraphic->maLastUsed;
101 auto aSeconds = std::chrono::duration_cast<std::chrono::seconds>(aDeltaTime);
107 pEachImpGraphic->swapOut();
133 sal_Int64 calculatedSize = 0;
136 if (!pEachImpGraphic->isSwappedOut())
144 assert(rGuard.owns_lock() && rGuard.mutex() == &
maMutex);
154 std::unique_lock aGuard(
maMutex);
161 std::unique_lock aGuard(
maMutex);
163 rState.append(
"\nImage Manager items:\t");
165 rState.append(
"\tsize:\t");
166 rState.append(
static_cast<sal_Int64
>(
mnUsedSize / 1024));
167 rState.append(
"\tkb");
171 pEachImpGraphic->dumpState(rState);
184 std::unique_lock aGuard(
maMutex);
187 reduceGraphicMemory(aGuard);
193 std::unique_lock aGuard(
maMutex);
200 assert(aGuard.owns_lock() && aGuard.mutex() == &
maMutex);
206 sal_Int64 calculatedSize = 0;
209 if (!pEachImpGraphic->isSwappedOut())
218 "Calculated size mismatch. Variable size is '"
219 <<
mnUsedSize <<
"' but calculated size is '" << calculatedSize <<
"'");
226 std::scoped_lock aGuard(
maMutex);
232std::shared_ptr<ImpGraphic>
Manager::copy(std::shared_ptr<ImpGraphic>
const& rImpGraphicPtr)
234 auto pReturn = std::make_shared<ImpGraphic>(*rImpGraphicPtr);
241 auto pReturn = std::make_shared<ImpGraphic>();
247 sal_Int32 nPageIndex)
249 auto pReturn = std::make_shared<ImpGraphic>(rGfxLink, nPageIndex);
256 auto pReturn = std::make_shared<ImpGraphic>(rBitmapEx);
263 auto pReturn = std::make_shared<ImpGraphic>(rAnimation);
268std::shared_ptr<ImpGraphic>
271 auto pReturn = std::make_shared<ImpGraphic>(rVectorGraphicDataPtr);
278 auto pReturn = std::make_shared<ImpGraphic>(rMetaFile);
285 auto pReturn = std::make_shared<ImpGraphic>(rGraphicLink);
292 std::scoped_lock aGuard(
maMutex);
301 std::scoped_lock aGuard(
maMutex);
310 std::scoped_lock aGuard(
maMutex);
sal_uLong getSizeBytes() const
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
Schedules the task for execution.
size_type erase(const Value &x)
std::pair< const_iterator, bool > insert(Value &&x)
void changeExisting(const ImpGraphic *pImpGraphic, sal_Int64 nOldSize)
o3tl::sorted_vector< ImpGraphic * > m_pImpGraphicList
std::shared_ptr< ImpGraphic > newInstance()
std::shared_ptr< ImpGraphic > copy(std::shared_ptr< ImpGraphic > const &pImpGraphic)
bool mbReducingGraphicMemory
void reduceGraphicMemory(std::unique_lock< std::mutex > &rGuard, bool bDropAll=false)
void loopGraphicsAndSwapOut(std::unique_lock< std::mutex > &rGuard, bool bDropAll)
void swappedOut(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
static sal_Int64 getGraphicSizeBytes(const ImpGraphic *pImpGraphic)
void registerGraphic(const std::shared_ptr< ImpGraphic > &rImpGraphic)
void unregisterGraphic(ImpGraphic *pImpGraphic)
void swappedIn(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
void dumpState(rtl::OStringBuffer &rState)
std::chrono::seconds mnAllowedIdleTime
#define LINK(Instance, Class, Member)
#define SAL_INFO_IF(condition, area, stream)
IMPL_LINK(Manager, SwapOutTimerHandler, Timer *, pTimer, void)