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

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 10 18:37:02 UTC 2020


 officecfg/registry/schema/org/openoffice/Office/Common.xcs |   14 ++++++++++
 vcl/inc/skia/utils.hxx                                     |    2 -
 vcl/skia/SkiaHelper.cxx                                    |   17 +++++++++----
 vcl/skia/gdiimpl.cxx                                       |    2 -
 4 files changed, 28 insertions(+), 7 deletions(-)

New commits:
commit fae487b70adb95cdac5f2ae108d5c25580112147
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Wed Dec 9 12:39:16 2020 +0100
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Thu Dec 10 19:36:14 2020 +0100

    make Skia image cache size configurable
    
    As asked for in tdf#136244 comment #11. The default fits 4x 2000px
    32bpp images, which is 64MiB, which is not that little, but then
    4x 2000px is not that much either. So, yes, configurable ...
    
    A good further improvement would be to make the cache grow more
    if the memory is available and reduce the size on memory pressure
    (https://lists.freedesktop.org/archives/libreoffice/2020-December/086404.html).
    
    Change-Id: Ifa05025ab34630e456465ac8a96950463fd18b60
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107468
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 2f961f0532a2..de96a9477b37 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -1589,6 +1589,20 @@
           <value>10</value>
         </prop>
       </group>
+      <group oor:name="Skia">
+        <info>
+          <desc>Specifies a group of cache options related to Skia-based drawing.</desc>
+        </info>
+        <prop oor:name="ImageCacheSize" oor:type="xs:long" oor:nillable="false">
+          <info>
+            <desc>Specifies the maximum cache size in bytes for all images used by Skia-based
+            drawing code. Larger size may improve drawing performance when using
+            many large images in software rendering mode.</desc>
+            <label>Image Cache Size</label>
+          </info>
+          <value>64000000</value>
+        </prop>
+      </group>
     </group>
     <group oor:name="Path">
       <!--OldLocation: soffice.ini -->
diff --git a/vcl/inc/skia/utils.hxx b/vcl/inc/skia/utils.hxx
index 03e01d2e5d8b..7da858ab1fff 100644
--- a/vcl/inc/skia/utils.hxx
+++ b/vcl/inc/skia/utils.hxx
@@ -73,7 +73,7 @@ VCL_DLLPUBLIC void
 void addCachedImage(const OString& key, sk_sp<SkImage> image);
 sk_sp<SkImage> findCachedImage(const OString& key);
 void removeCachedImage(sk_sp<SkImage> image);
-constexpr int MAX_CACHE_SIZE = 4 * 2000 * 2000 * 4; // 4x 2000px 32bpp images, 64MiB
+tools::Long maxImageCacheSize();
 
 // SkSurfaceProps to be used by all Skia surfaces.
 VCL_DLLPUBLIC const SkSurfaceProps* surfaceProps();
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index b3aa5a1d1cbc..d545cc670bb5 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -485,7 +485,7 @@ struct ImageCacheItem
 {
     OString key;
     sk_sp<SkImage> image;
-    int size; // cost of the item
+    tools::Long size; // cost of the item
 };
 } //namespace
 
@@ -493,7 +493,7 @@ struct ImageCacheItem
 // to require a hash/map. Using o3tl::lru_cache would be simpler, but it doesn't support
 // calculating cost of each item.
 static std::list<ImageCacheItem>* imageCache = nullptr;
-static int imageCacheSize = 0; // sum of all ImageCacheItem.size
+static tools::Long imageCacheSize = 0; // sum of all ImageCacheItem.size
 
 void addCachedImage(const OString& key, sk_sp<SkImage> image)
 {
@@ -502,12 +502,13 @@ void addCachedImage(const OString& key, sk_sp<SkImage> image)
         return;
     if (imageCache == nullptr)
         imageCache = new std::list<ImageCacheItem>;
-    int size = image->width() * image->height()
-               * SkColorTypeBytesPerPixel(image->imageInfo().colorType());
+    tools::Long size = static_cast<tools::Long>(image->width()) * image->height()
+                       * SkColorTypeBytesPerPixel(image->imageInfo().colorType());
     imageCache->push_front({ key, image, size });
     imageCacheSize += size;
     SAL_INFO("vcl.skia.trace", "addcachedimage " << image << " :" << size << "/" << imageCacheSize);
-    while (imageCacheSize > MAX_CACHE_SIZE)
+    const tools::Long maxSize = maxImageCacheSize();
+    while (imageCacheSize > maxSize)
     {
         assert(!imageCache->empty());
         imageCacheSize -= imageCache->back().size;
@@ -554,6 +555,12 @@ void removeCachedImage(sk_sp<SkImage> image)
     }
 }
 
+tools::Long maxImageCacheSize()
+{
+    // Defaults to 4x 2000px 32bpp images, 64MiB.
+    return officecfg::Office::Common::Cache::Skia::ImageCacheSize::get();
+}
+
 void cleanup()
 {
     delete sharedGrDirectContext;
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index ee2e72889152..773bdd2be1bf 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -1574,7 +1574,7 @@ sk_sp<SkImage> SkiaSalGraphicsImpl::mergeCacheBitmaps(const SkiaSalBitmap& bitma
         }
     }
     // Do not cache the result if it would take most of the cache and thus get evicted soon.
-    if (targetSize.Width() * targetSize.Height() * 4 > SkiaHelper::MAX_CACHE_SIZE * 0.7)
+    if (targetSize.Width() * targetSize.Height() * 4 > SkiaHelper::maxImageCacheSize() * 0.7)
         return image;
     OString key;
     OStringBuffer keyBuf;


More information about the Libreoffice-commits mailing list