[Libreoffice-commits] core.git: officecfg/registry vcl/inc vcl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Tue May 8 00:25:35 UTC 2018


 officecfg/registry/schema/org/openoffice/Office/Common.xcs |   21 ++++++++++++
 vcl/inc/graphic/Manager.hxx                                |    3 +
 vcl/source/graphic/Manager.cxx                             |   22 ++++++++-----
 3 files changed, 37 insertions(+), 9 deletions(-)

New commits:
commit c6cf2320d2a464594e759289c34796538d31f02b
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Apr 27 18:30:45 2018 +0900

    config entries for the new graphic manager, deprecate old entries
    
    Add 2 new GraphicManager config entries GraphicMemoryLimit and
    GraphicAllowedIdleTime. At the same time, deprecate the existing
    config entries used in GraphicObject's GraphicManager, which are
    not relevant anymore.
    
    Change-Id: Idb775e5e1a623f6c23d0c67fea5334a6c713c6c2
    Reviewed-on: https://gerrit.libreoffice.org/53561
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 390b54595e40..88b6f3b07f1b 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -1491,6 +1491,7 @@
         </info>
         <prop oor:name="TotalCacheSize" oor:type="xs:int" oor:nillable="false">
           <info>
+            <deprecated>Not used anymore</deprecated>
             <desc>Specifies the maximum cache size for all graphical display
             objects.</desc>
             <label>Total Image Cache Size</label>
@@ -1499,6 +1500,7 @@
         </prop>
         <prop oor:name="ObjectCacheSize" oor:type="xs:int" oor:nillable="false">
           <info>
+            <deprecated>Not used anymore</deprecated>
             <desc>Specifies the maximum cache size for a single graphic display
             object.</desc>
             <label>Image Object Cache Size</label>
@@ -1507,12 +1509,31 @@
         </prop>
         <prop oor:name="ObjectReleaseTime" oor:type="xs:int" oor:nillable="false">
           <info>
+            <deprecated>Not used anymore</deprecated>
             <desc>Specifies the time in seconds after which a cached object is
             freed from the cache.</desc>
             <label>Image Object Release Timeout</label>
           </info>
           <value>600</value>
         </prop>
+        <prop oor:name="GraphicMemoryLimit" oor:type="xs:int" oor:nillable="false">
+          <info>
+            <desc>Specifies the allowed cumulated memory that the
+            graphic objects can occupy before they start to get swapped
+            to the disk to save memory.</desc>
+            <label>Graphic Memory Limit Size</label>
+          </info>
+          <value>300000000</value>
+        </prop>
+        <prop oor:name="GraphicAllowedIdleTime" oor:type="xs:int" oor:nillable="false">
+          <info>
+            <desc>Specifies the time in seconds when the graphic object
+            can be idle (time since it was last used) before it is
+            considered to be swapped to the disk to save memory.</desc>
+            <label>Graphic Allowed Idle Time</label>
+          </info>
+          <value>10</value>
+        </prop>
       </group>
     </group>
     <group oor:name="Path">
diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx
index 6dd88a5a4c1c..88d57229f9e2 100644
--- a/vcl/inc/graphic/Manager.hxx
+++ b/vcl/inc/graphic/Manager.hxx
@@ -36,7 +36,8 @@ class Manager final
 {
 private:
     std::unordered_set<ImpGraphic*> m_pImpGraphicList;
-    sal_Int64 mnTotalCacheSize;
+    std::chrono::seconds mnAllowedIdleTime;
+    sal_Int64 mnMemoryLimit;
     sal_Int64 mnUsedSize;
     Timer maSwapOutTimer;
 
diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx
index 106677cc0db4..c2146a680e8a 100644
--- a/vcl/source/graphic/Manager.cxx
+++ b/vcl/source/graphic/Manager.cxx
@@ -30,14 +30,19 @@ namespace graphic
 {
 namespace
 {
-void setTotalCacheSizeFromConfigIfPossible(sal_Int64& nTotalCacheSize)
+void setupConfigurationValuesIfPossible(sal_Int64& rMemoryLimit,
+                                        std::chrono::seconds& rAllowedIdleTime)
 {
     if (utl::ConfigManager::IsFuzzing())
         return;
 
     try
     {
-        nTotalCacheSize = officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::get();
+        using officecfg::Office::Common::Cache;
+
+        rMemoryLimit = Cache::GraphicManager::GraphicMemoryLimit::get();
+        rAllowedIdleTime
+            = std::chrono::seconds(Cache::GraphicManager::GraphicAllowedIdleTime::get());
     }
     catch (...)
     {
@@ -52,11 +57,12 @@ Manager& Manager::get()
 }
 
 Manager::Manager()
-    : mnTotalCacheSize(50000000)
+    : mnAllowedIdleTime(10)
+    , mnMemoryLimit(300000000)
     , mnUsedSize(0)
     , maSwapOutTimer("graphic::Manager maSwapOutTimer")
 {
-    setTotalCacheSizeFromConfigIfPossible(mnTotalCacheSize);
+    setupConfigurationValuesIfPossible(mnMemoryLimit, mnAllowedIdleTime);
 
     maSwapOutTimer.SetInvokeHandler(LINK(this, Manager, SwapOutTimerHandler));
     maSwapOutTimer.SetTimeout(10000);
@@ -68,7 +74,7 @@ void Manager::reduceGraphicMemory()
 {
     for (ImpGraphic* pEachImpGraphic : m_pImpGraphicList)
     {
-        if (mnUsedSize < mnTotalCacheSize * 0.7)
+        if (mnUsedSize < mnMemoryLimit * 0.7)
             return;
 
         sal_Int64 nCurrentGraphicSize = getGraphicSizeBytes(pEachImpGraphic);
@@ -79,8 +85,8 @@ void Manager::reduceGraphicMemory()
                 auto aCurrent = std::chrono::high_resolution_clock::now();
                 auto aDeltaTime = aCurrent - pEachImpGraphic->maLastUsed;
                 auto aSeconds = std::chrono::duration_cast<std::chrono::seconds>(aDeltaTime);
-                double nSeconds = aSeconds.count();
-                if (nSeconds > 10)
+
+                if (aSeconds > mnAllowedIdleTime)
                     pEachImpGraphic->ImplSwapOut();
             }
         }
@@ -105,7 +111,7 @@ void Manager::registerGraphic(std::shared_ptr<ImpGraphic>& pImpGraphic,
                               OUString const& /*rsContext*/)
 {
     // make some space first
-    if (mnUsedSize > mnTotalCacheSize)
+    if (mnUsedSize > mnMemoryLimit)
         reduceGraphicMemory();
 
     // Insert and update the used size (bytes)


More information about the Libreoffice-commits mailing list