summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-07-22 11:11:27 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-07-23 11:22:59 +0200
commit4e512171c21a193027c35d19a5273507a2725596 (patch)
treee0c354208a355c22f0e0ba9639b10a1010b2a52f /vcl
parent58ddacdb4be78dd00e05a46459ed0bcbe7531632 (diff)
no need to allocate these static vars on demand
the constructor can be laid out at compile/link time Change-Id: I377a537e15199ae81394d76ac662576280a25c25 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119362 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/skia/SkiaHelper.cxx41
1 files changed, 16 insertions, 25 deletions
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index b9b5b4fb2f20..754176787abc 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -496,7 +496,7 @@ struct ImageCacheItem
// LRU cache, last item is the least recently used. Hopefully there won't be that many items
// 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 std::list<ImageCacheItem> imageCache;
static tools::Long imageCacheSize = 0; // sum of all ImageCacheItem.size
void addCachedImage(const OString& key, sk_sp<SkImage> image)
@@ -504,38 +504,32 @@ void addCachedImage(const OString& key, sk_sp<SkImage> image)
static bool disabled = getenv("SAL_DISABLE_SKIA_CACHE") != nullptr;
if (disabled)
return;
- if (imageCache == nullptr)
- imageCache = new std::list<ImageCacheItem>;
tools::Long size = static_cast<tools::Long>(image->width()) * image->height()
* SkColorTypeBytesPerPixel(image->imageInfo().colorType());
- imageCache->push_front({ key, image, size });
+ imageCache.push_front({ key, image, size });
imageCacheSize += size;
SAL_INFO("vcl.skia.trace", "addcachedimage " << image << " :" << size << "/" << imageCacheSize);
const tools::Long maxSize = maxImageCacheSize();
while (imageCacheSize > maxSize)
{
- assert(!imageCache->empty());
- imageCacheSize -= imageCache->back().size;
- SAL_INFO("vcl.skia.trace", "least used removal " << imageCache->back().image << ":"
- << imageCache->back().size);
- imageCache->pop_back();
+ assert(!imageCache.empty());
+ imageCacheSize -= imageCache.back().size;
+ SAL_INFO("vcl.skia.trace",
+ "least used removal " << imageCache.back().image << ":" << imageCache.back().size);
+ imageCache.pop_back();
}
}
sk_sp<SkImage> findCachedImage(const OString& key)
{
- if (imageCache != nullptr)
+ for (auto it = imageCache.begin(); it != imageCache.end(); ++it)
{
- for (auto it = imageCache->begin(); it != imageCache->end(); ++it)
+ if (it->key == key)
{
- if (it->key == key)
- {
- sk_sp<SkImage> ret = it->image;
- SAL_INFO("vcl.skia.trace",
- "findcachedimage " << key << " : " << it->image << " found");
- imageCache->splice(imageCache->begin(), *imageCache, it);
- return ret;
- }
+ sk_sp<SkImage> ret = it->image;
+ SAL_INFO("vcl.skia.trace", "findcachedimage " << key << " : " << it->image << " found");
+ imageCache.splice(imageCache.begin(), imageCache, it);
+ return ret;
}
}
SAL_INFO("vcl.skia.trace", "findcachedimage " << key << " not found");
@@ -544,15 +538,13 @@ sk_sp<SkImage> findCachedImage(const OString& key)
void removeCachedImage(sk_sp<SkImage> image)
{
- if (imageCache == nullptr)
- return;
- for (auto it = imageCache->begin(); it != imageCache->end();)
+ for (auto it = imageCache.begin(); it != imageCache.end();)
{
if (it->image == image)
{
imageCacheSize -= it->size;
assert(imageCacheSize >= 0);
- it = imageCache->erase(it);
+ it = imageCache.erase(it);
}
else
++it;
@@ -569,8 +561,7 @@ void cleanup()
{
delete sharedGrDirectContext;
sharedGrDirectContext = nullptr;
- delete imageCache;
- imageCache = nullptr;
+ imageCache.clear();
imageCacheSize = 0;
}