[Libreoffice-commits] core.git: vcl/inc vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jan 20 08:07:04 UTC 2021
vcl/inc/graphic/Manager.hxx | 5 ++-
vcl/source/gdi/impgraph.cxx | 18 +++++++-----
vcl/source/graphic/Manager.cxx | 58 +++++++++++++++++++++++++++++++----------
3 files changed, 58 insertions(+), 23 deletions(-)
New commits:
commit c36cef138a840af013cf85d33ea3d3d27aeb001a
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Dec 30 17:13:35 2020 +0900
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Jan 20 09:06:23 2021 +0100
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 at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx
index bff72780cbd7..098c8644ac61 100644
--- a/vcl/inc/graphic/Manager.hxx
+++ b/vcl/inc/graphic/Manager.hxx
@@ -41,6 +41,7 @@ private:
Manager();
void registerGraphic(const std::shared_ptr<ImpGraphic>& rImpGraphic);
+ void loopGraphicsAndSwapOut();
DECL_LINK(SwapOutTimerHandler, Timer*, void);
@@ -49,8 +50,8 @@ private:
public:
static Manager& get();
- void swappedIn(const ImpGraphic* pImpGraphic);
- void swappedOut(const ImpGraphic* pImpGraphic);
+ void swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
+ void swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
void reduceGraphicMemory();
void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize);
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 1e56e57a8226..30db3e932bb9 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1276,6 +1276,8 @@ bool ImpGraphic::swapOut()
bool bResult = false;
+ sal_Int64 nByteSize = getSizeBytes();
+
// We have GfxLink so we have the source available
if (mpGfxLink && mpGfxLink->IsNative())
{
@@ -1289,9 +1291,6 @@ bool ImpGraphic::swapOut()
// mark as swapped out
mbSwapOut = true;
- // Signal to manager that we have swapped out
- vcl::graphic::Manager::get().swappedOut(this);
-
bResult = true;
}
else
@@ -1331,12 +1330,15 @@ bool ImpGraphic::swapOut()
mpSwapFile = std::move(pSwapFile);
mbSwapOut = true;
-
- // Signal to manager that we have swapped out
- vcl::graphic::Manager::get().swappedOut(this);
}
}
+ if (bResult)
+ {
+ // Signal to manager that we have swapped out
+ vcl::graphic::Manager::get().swappedOut(this, nByteSize);
+ }
+
return bResult;
}
@@ -1480,7 +1482,9 @@ bool ImpGraphic::swapIn()
}
if (bReturn)
- vcl::graphic::Manager::get().swappedIn(this);
+ {
+ vcl::graphic::Manager::get().swappedIn(this, getSizeBytes());
+ }
return bReturn;
}
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)
More information about the Libreoffice-commits
mailing list