diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-12-09 12:39:16 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-12-11 11:05:58 +0100 |
commit | beaf7e142977e5607f205e1a001e57a31588fef9 (patch) | |
tree | 5e7abce29ca954ed150f81dbae2d52f81188d3b2 /vcl | |
parent | 4aa9cb784469b8c13660f36c829c0fadc11c922b (diff) |
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@collabora.com>
(cherry picked from commit fae487b70adb95cdac5f2ae108d5c25580112147)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107540
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/skia/utils.hxx | 2 | ||||
-rw-r--r-- | vcl/skia/SkiaHelper.cxx | 17 | ||||
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 2 |
3 files changed, 14 insertions, 7 deletions
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; |