24 #include <officecfg/Office/Common.hxx>
33 void 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 , mnMemoryLimit(300000000)
65 , 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);
104 pEachImpGraphic->swapOut();
118 std::scoped_lock<std::recursive_mutex> aGuard(
maMutex);
122 sal_Int64 calculatedSize = 0;
125 if (!pEachImpGraphic->isSwappedOut())
146 std::scoped_lock<std::recursive_mutex> aGuard(
maMutex);
149 reduceGraphicMemory();
155 std::scoped_lock<std::recursive_mutex> aGuard(
maMutex);
166 sal_Int64 calculatedSize = 0;
169 if (!pEachImpGraphic->isSwappedOut())
178 "Calculated size mismatch. Variable size is '"
179 <<
mnUsedSize <<
"' but calculated size is '" << calculatedSize <<
"'");
186 std::scoped_lock<std::recursive_mutex> aGuard(
maMutex);
192 std::shared_ptr<ImpGraphic>
Manager::copy(std::shared_ptr<ImpGraphic>
const& rImpGraphicPtr)
194 auto pReturn = std::make_shared<ImpGraphic>(*rImpGraphicPtr);
201 auto pReturn = std::make_shared<ImpGraphic>();
207 sal_Int32 nPageIndex)
209 auto pReturn = std::make_shared<ImpGraphic>(rGfxLink, nPageIndex);
216 auto pReturn = std::make_shared<ImpGraphic>(rBitmapEx);
223 auto pReturn = std::make_shared<ImpGraphic>(rAnimation);
228 std::shared_ptr<ImpGraphic>
231 auto pReturn = std::make_shared<ImpGraphic>(rVectorGraphicDataPtr);
238 auto pReturn = std::make_shared<ImpGraphic>(rMetaFile);
245 auto pReturn = std::make_shared<ImpGraphic>(rGraphicLink);
252 std::scoped_lock<std::recursive_mutex> aGuard(
maMutex);
261 std::scoped_lock<std::recursive_mutex> aGuard(
maMutex);
270 std::scoped_lock<std::recursive_mutex> aGuard(
maMutex);
#define LINK(Instance, Class, Member)
o3tl::sorted_vector< ImpGraphic * > m_pImpGraphicList
static sal_Int64 getGraphicSizeBytes(const ImpGraphic *pImpGraphic)
void unregisterGraphic(ImpGraphic *pImpGraphic)
#define SAL_INFO_IF(condition, area, stream)
void registerGraphic(const std::shared_ptr< ImpGraphic > &rImpGraphic)
void reduceGraphicMemory()
std::shared_ptr< ImpGraphic > copy(std::shared_ptr< ImpGraphic > const &pImpGraphic)
void swappedIn(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
std::recursive_mutex maMutex
IMPL_LINK(Manager, SwapOutTimerHandler, Timer *, pTimer, void)
std::chrono::seconds mnAllowedIdleTime
void SetDebugName(const char *pDebugName)
std::shared_ptr< ImpGraphic > newInstance()
void changeExisting(const ImpGraphic *pImpGraphic, sal_Int64 nOldSize)
virtual void Start() override
Activates the timer task.
void loopGraphicsAndSwapOut()
void SetTimeout(sal_uInt64 nTimeoutMs)
sal_uLong getSizeBytes() const
void SetInvokeHandler(const Link< Timer *, void > &rLink)
std::pair< const_iterator, bool > insert(Value &&x)
void swappedOut(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
size_type erase(const Value &x)