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-10 19:36:14 +0100 |
commit | fae487b70adb95cdac5f2ae108d5c25580112147 (patch) | |
tree | bac45f04f9ef0ed96fa554554ffe1082b5ec75cb /vcl/skia | |
parent | 4f1a5c4622d983d40faceedabbd46d55d9f28286 (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>
Diffstat (limited to 'vcl/skia')
-rw-r--r-- | vcl/skia/SkiaHelper.cxx | 17 | ||||
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 2 |
2 files changed, 13 insertions, 6 deletions
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; |