summaryrefslogtreecommitdiff
path: root/vcl/source/graphic/Manager.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-12-30 17:13:35 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-01-20 09:06:23 +0100
commitc36cef138a840af013cf85d33ea3d3d27aeb001a (patch)
tree900cae430b5e000add7278285540effdba14dc22 /vcl/source/graphic/Manager.cxx
parentbca1b74c0753f2305a5e234293df88aa3e1d9af0 (diff)
vcl: Improve graphic manager swapping allocation
This improves the counting of the used space by graphics and makes the manager loop faster. Change-Id: Ifebe5fe52722d0f22dae0d1bdef02f65afb036ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109595 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source/graphic/Manager.cxx')
-rw-r--r--vcl/source/graphic/Manager.cxx58
1 files changed, 44 insertions, 14 deletions
diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx
index 5d535e446955..fafca90b5ad8 100644
--- a/vcl/source/graphic/Manager.cxx
+++ b/vcl/source/graphic/Manager.cxx
@@ -75,25 +75,24 @@ Manager::Manager()
}
}
-void Manager::reduceGraphicMemory()
+void Manager::loopGraphicsAndSwapOut()
{
- if (!mbSwapEnabled)
- return;
-
- std::scoped_lock<std::recursive_mutex> aGuard(maMutex);
-
// 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
// m_pImpGraphicList invalidating a loop over m_pImpGraphicList, e.g.
// reexport of tdf118346-1.odg
o3tl::sorted_vector<ImpGraphic*> aImpGraphicList = m_pImpGraphicList;
+
for (ImpGraphic* pEachImpGraphic : aImpGraphicList)
{
- if (mnUsedSize < mnMemoryLimit * 0.7)
+ if (mnUsedSize < sal_Int64(mnMemoryLimit * 0.7))
return;
+ if (pEachImpGraphic->isSwappedOut())
+ continue;
+
sal_Int64 nCurrentGraphicSize = getGraphicSizeBytes(pEachImpGraphic);
- if (!pEachImpGraphic->isSwappedOut() && nCurrentGraphicSize > 1000000)
+ if (nCurrentGraphicSize > 100000)
{
if (!pEachImpGraphic->mpContext)
{
@@ -108,6 +107,33 @@ void Manager::reduceGraphicMemory()
}
}
+void Manager::reduceGraphicMemory()
+{
+ if (!mbSwapEnabled)
+ return;
+
+ if (mnUsedSize < mnMemoryLimit)
+ return;
+
+ std::scoped_lock<std::recursive_mutex> aGuard(maMutex);
+
+ loopGraphicsAndSwapOut();
+
+ sal_Int64 calculatedSize = 0;
+ for (ImpGraphic* pEachImpGraphic : m_pImpGraphicList)
+ {
+ if (!pEachImpGraphic->isSwappedOut())
+ {
+ calculatedSize += getGraphicSizeBytes(pEachImpGraphic);
+ }
+ }
+
+ if (calculatedSize != mnUsedSize)
+ {
+ mnUsedSize = calculatedSize;
+ }
+}
+
sal_Int64 Manager::getGraphicSizeBytes(const ImpGraphic* pImpGraphic)
{
if (!pImpGraphic->isAvailable())
@@ -213,18 +239,22 @@ std::shared_ptr<ImpGraphic> Manager::newInstance(const GraphicExternalLink& rGra
return pReturn;
}
-void Manager::swappedIn(const ImpGraphic* pImpGraphic)
+void Manager::swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes)
{
std::scoped_lock<std::recursive_mutex> aGuard(maMutex);
-
- mnUsedSize += getGraphicSizeBytes(pImpGraphic);
+ if (pImpGraphic)
+ {
+ mnUsedSize += nSizeBytes;
+ }
}
-void Manager::swappedOut(const ImpGraphic* pImpGraphic)
+void Manager::swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes)
{
std::scoped_lock<std::recursive_mutex> aGuard(maMutex);
-
- mnUsedSize -= getGraphicSizeBytes(pImpGraphic);
+ if (pImpGraphic)
+ {
+ mnUsedSize -= nSizeBytes;
+ }
}
void Manager::changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSizeBytes)