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)
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();
132 sal_Int64 calculatedSize = 0;
135 if (!pEachImpGraphic->isSwappedOut())
143 assert(rGuard.owns_lock() && rGuard.mutex() == &
maMutex);
160 std::unique_lock aGuard(
maMutex);
163 reduceGraphicMemory(aGuard);
169 std::unique_lock aGuard(
maMutex);
176 assert(aGuard.owns_lock() && aGuard.mutex() == &
maMutex);
182 sal_Int64 calculatedSize = 0;
185 if (!pEachImpGraphic->isSwappedOut())
194 "Calculated size mismatch. Variable size is '"
195 <<
mnUsedSize <<
"' but calculated size is '" << calculatedSize <<
"'");
202 std::scoped_lock aGuard(
maMutex);
208std::shared_ptr<ImpGraphic>
Manager::copy(std::shared_ptr<ImpGraphic>
const& rImpGraphicPtr)
210 auto pReturn = std::make_shared<ImpGraphic>(*rImpGraphicPtr);
217 auto pReturn = std::make_shared<ImpGraphic>();
223 sal_Int32 nPageIndex)
225 auto pReturn = std::make_shared<ImpGraphic>(rGfxLink, nPageIndex);
232 auto pReturn = std::make_shared<ImpGraphic>(rBitmapEx);
239 auto pReturn = std::make_shared<ImpGraphic>(rAnimation);
244std::shared_ptr<ImpGraphic>
247 auto pReturn = std::make_shared<ImpGraphic>(rVectorGraphicDataPtr);
254 auto pReturn = std::make_shared<ImpGraphic>(rMetaFile);
261 auto pReturn = std::make_shared<ImpGraphic>(rGraphicLink);
268 std::scoped_lock aGuard(
maMutex);
277 std::scoped_lock aGuard(
maMutex);
286 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 loopGraphicsAndSwapOut(std::unique_lock< std::mutex > &rGuard)
void reduceGraphicMemory(std::unique_lock< std::mutex > &rGuard)
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)
std::chrono::seconds mnAllowedIdleTime
#define LINK(Instance, Class, Member)
#define SAL_INFO_IF(condition, area, stream)
IMPL_LINK(Manager, SwapOutTimerHandler, Timer *, pTimer, void)