summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-07-27 14:42:15 +0200
committerCaolán McNamara <caolanm@redhat.com>2020-07-29 10:24:40 +0200
commit7057d6729c865eac4831f9c286421b553a7c4ee9 (patch)
treec10ffb5788e834ebdb9b9ab5f46562d1b4eeab66
parent5863e5a06069a005023f97013ffd170f121d3f8a (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> (cherry picked from commit 4addedabe6778e70754709290502d721cdef796d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99493 Reviewed-by: Caolán McNamara <caolanm@redhat.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 980f0c688651..66f3655f9c53 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -1340,7 +1340,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())