summaryrefslogtreecommitdiff
path: root/vcl/source/graphic/Manager.cxx
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2023-03-10 10:36:22 +0000
committerMichael Meeks <michael.meeks@collabora.com>2023-03-11 21:03:05 +0000
commit4a4602ad7513262a6c0423f17b42791a852b7e23 (patch)
treeee6d2b88f488ad1b4ba0c8cbd6b392f4e8cbc440 /vcl/source/graphic/Manager.cxx
parent9dec458e40a8b6a180e5c1c6f93fd4277825b9a2 (diff)
lok: add trimMemory capability, and expand dumpState to caches.
Being able to trigger some more aggressive memory saving is useful in for both online and mobile. Change-Id: I9b91c9fe9eecec06c75112595deac0bfeb94c144 Signed-off-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148624 Tested-by: Jenkins
Diffstat (limited to 'vcl/source/graphic/Manager.cxx')
-rw-r--r--vcl/source/graphic/Manager.cxx36
1 files changed, 30 insertions, 6 deletions
diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx
index bdb5ba7ef432..f77e3e3c4041 100644
--- a/vcl/source/graphic/Manager.cxx
+++ b/vcl/source/graphic/Manager.cxx
@@ -75,7 +75,7 @@ Manager::Manager()
}
}
-void Manager::loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard)
+void Manager::loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard, bool bDropAll)
{
// make a copy of m_pImpGraphicList because if we swap out a svg, the svg
// filter may create more temp Graphics which are auto-added to
@@ -85,14 +85,14 @@ void Manager::loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard)
for (ImpGraphic* pEachImpGraphic : aImpGraphicList)
{
- if (mnUsedSize < sal_Int64(mnMemoryLimit * 0.7))
+ if (mnUsedSize < sal_Int64(mnMemoryLimit * 0.7) && !bDropAll)
return;
if (pEachImpGraphic->isSwappedOut())
continue;
sal_Int64 nCurrentGraphicSize = getGraphicSizeBytes(pEachImpGraphic);
- if (nCurrentGraphicSize > 100000)
+ if (nCurrentGraphicSize > 100000 || bDropAll)
{
if (!pEachImpGraphic->mpContext)
{
@@ -112,22 +112,23 @@ void Manager::loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard)
}
}
-void Manager::reduceGraphicMemory(std::unique_lock<std::mutex>& rGuard)
+void Manager::reduceGraphicMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll)
{
// maMutex is locked in callers
if (!mbSwapEnabled)
return;
- if (mnUsedSize < mnMemoryLimit)
+ if (mnUsedSize < mnMemoryLimit && !bDropAll)
return;
// avoid recursive reduceGraphicMemory on reexport of tdf118346-1.odg to odg
if (mbReducingGraphicMemory)
return;
+
mbReducingGraphicMemory = true;
- loopGraphicsAndSwapOut(rGuard);
+ loopGraphicsAndSwapOut(rGuard, bDropAll);
sal_Int64 calculatedSize = 0;
for (ImpGraphic* pEachImpGraphic : m_pImpGraphicList)
@@ -148,6 +149,29 @@ void Manager::reduceGraphicMemory(std::unique_lock<std::mutex>& rGuard)
mbReducingGraphicMemory = false;
}
+void Manager::dropCache()
+{
+ std::unique_lock aGuard(maMutex);
+
+ reduceGraphicMemory(aGuard, true);
+}
+
+void Manager::dumpState(rtl::OStringBuffer& rState)
+{
+ std::unique_lock aGuard(maMutex);
+
+ rState.append("\nImage Manager items:\t");
+ rState.append(static_cast<sal_Int32>(m_pImpGraphicList.size()));
+ rState.append("\tsize:\t");
+ rState.append(static_cast<sal_Int64>(mnUsedSize / 1024));
+ rState.append("\tkb");
+
+ for (ImpGraphic* pEachImpGraphic : m_pImpGraphicList)
+ {
+ pEachImpGraphic->dumpState(rState);
+ }
+}
+
sal_Int64 Manager::getGraphicSizeBytes(const ImpGraphic* pImpGraphic)
{
if (!pImpGraphic->isAvailable())