make SkiaSalBitmap discard cached data of incorrect size (tdf#132367)
Performing the delayed scaling for the bitmap data could keep
around cached mImage with a different size. Which theoretically could
be kept around and resized later, but the bitmap data scaling finishes
the delayed scaling by discarding all the data about it (scaling
quality), so the later resizing wouldn't know how.
Change-Id: I6a817d87becd44214f0f4db0755731b6e4ae1409
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92846
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index cfdb9d3..d13e765 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -76,6 +76,8 @@
void ResetCachedData();
// Sets the data only as SkImage (will be converted as needed).
void ResetToSkImage(sk_sp<SkImage> image);
// Resets all data that does not match mSize.
void ResetCachedDataBySize();
// Call to ensure mBuffer has data (will convert from mImage if necessary).
void EnsureBitmapData();
void EnsureBitmapData() const { return const_cast<SkiaSalBitmap*>(this)->EnsureBitmapData(); }
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 1f91b5d..52808b38 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -679,6 +679,9 @@
<< static_cast<int>(mScaleQuality));
mPixelsSize = mSize;
mScaleQuality = kNone_SkFilterQuality;
// Information about the pending scaling has been discarded, so make sure we do not
// keep around any cached images would still need scaling.
ResetCachedDataBySize();
}
else
canvas.drawImage(mImage, 0, 0, &paint);
@@ -767,8 +770,8 @@
// mBuffer from it if needed, in that case ResetToSkImage() should be used.
assert(mBuffer.get() || !mImage);
mBitmap.reset();
mAlphaImage.reset();
mImage.reset();
mAlphaImage.reset();
}
void SkiaSalBitmap::ResetToSkImage(sk_sp<SkImage> image)
@@ -776,8 +779,21 @@
SkiaZone zone;
mBuffer.reset();
mBitmap.reset();
mAlphaImage.reset();
mImage = image;
mAlphaImage.reset();
}
void SkiaSalBitmap::ResetCachedDataBySize()
{
SkiaZone zone;
assert(!mBitmap.isNull());
assert(mBitmap.width() == mSize.getWidth() && mBitmap.height() == mSize.getHeight());
assert(mSize == mPixelsSize);
if (mImage && (mImage->width() != mSize.getWidth() || mImage->height() != mSize.getHeight()))
mImage.reset();
if (mAlphaImage
&& (mAlphaImage->width() != mSize.getWidth() || mAlphaImage->height() != mSize.getHeight()))
mAlphaImage.reset();
}
#ifdef DBG_UTIL