summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-07-27 14:42:15 +0200
committerLuboš Luňák <l.lunak@collabora.com>2020-07-27 15:57:33 +0200
commit4addedabe6778e70754709290502d721cdef796d (patch)
tree560d6f7615ed38309e2b93e50c969311dfe9e716
parent843eb355cb960413fef3817b9cbff75ac1f72c7d (diff)
tweak not caching images in Skia drawing when upscaling (tdf#132438)
The change done for tdf#134237 was meant to avoid caching of very large images when zooming in. But it turns out that it happens quite often that we get asked to draw something larger than the drawing area, such as when scrolling a document with a larger image. So tweak the check to hopefully avoid only huge images or when upscaling a lot. Change-Id: Ifa76e0ef2df78085afc21fd064b77d5b1c9513b5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99482 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r--vcl/skia/gdiimpl.cxx22
1 files changed, 21 insertions, 1 deletions
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index a5d2a484ce6a..066311e97c2b 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -1363,7 +1363,27 @@ sk_sp<SkImage> SkiaSalGraphicsImpl::mergeCacheBitmaps(const SkiaSalBitmap& bitma
// better to rely on Skia to clip and draw only the necessary, rather than prepare
// a very large image only to not use most of it.
if (targetSize.Width() > GetWidth() || targetSize.Height() > GetHeight())
- return image;
+ {
+ // This is a bit tricky. The condition above just checks that at least a part of the resulting
+ // image will not be used (it's larger then our drawing area). But this may often happen
+ // when just scrolling a document with a large image, where the caching may very well be worth it.
+ // Since the problem is mainly the cost of upscaling and then the size of the resulting bitmap,
+ // compute a ratio of how much this is going to be scaled up, how much this is larger than
+ // the drawing area, and then refuse to cache if it's too much.
+ const double upscaleRatio = 1.0 * targetSize.Width() / bitmap.GetSize().Width()
+ * targetSize.Height() / bitmap.GetSize().Height();
+ const double oversizeRatio
+ = 1.0 * targetSize.Width() / GetWidth() * targetSize.Height() / GetHeight();
+ const double ratio = upscaleRatio * oversizeRatio;
+ if (ratio > 10)
+ {
+ SAL_INFO("vcl.skia.trace", "mergecachebitmaps("
+ << this << "): not caching upscaling, ratio:" << ratio
+ << ", " << bitmap.GetSize() << "->" << targetSize
+ << " in " << Size(GetWidth(), GetHeight()));
+ return image;
+ }
+ }
OString key;
OStringBuffer keyBuf;
keyBuf.append(targetSize.Width())