summaryrefslogtreecommitdiff
path: root/vcl/skia/salbmp.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-06-30 15:02:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-07-02 16:57:46 +0200
commit72f2de04a23680fcb75cf5bc89b3422f9e89cdef (patch)
treeb0ddebb861c6d25196cad38098ecfafdeee95ae1 /vcl/skia/salbmp.cxx
parent13f3ccd125e42cc01a7f262434ae935adbe5e192 (diff)
optimised Skia Invert() operation
which is not that important right now, but my upcoming transparency->alpha patch will make more heavy use of Invert(), and this change will reduce the cost of that Change-Id: I53d8dfbf153f16f4d94022527c71d70d08392dfc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153857 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/skia/salbmp.cxx')
-rw-r--r--vcl/skia/salbmp.cxx25
1 files changed, 25 insertions, 0 deletions
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 57cea14316c5..1ce85dd0e837 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -623,6 +623,31 @@ bool SkiaSalBitmap::AlphaBlendWith(const SalBitmap& rSalBmp)
return true;
}
+bool SkiaSalBitmap::Invert()
+{
+#ifdef DBG_UTIL
+ assert(mWriteAccessCount == 0);
+#endif
+ // Normally this would need to convert contents of mBuffer for all possible formats,
+ // so just let the VCL algorithm do it.
+ // Avoid the costly SkImage->buffer->SkImage conversion.
+ if (!mBuffer && mImage && !mEraseColorSet)
+ {
+ // This is 8-bit bitmap serving as alpha/transparency/mask, so the image itself needs no alpha.
+ sk_sp<SkSurface> surface = createSkSurface(mSize, kOpaque_SkAlphaType);
+ surface->getCanvas()->clear(SK_ColorWHITE);
+ SkPaint paint;
+ paint.setBlendMode(SkBlendMode::kDifference);
+ surface->getCanvas()->drawImage(
+ mImage, 0, 0, SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear), &paint);
+ ResetToSkImage(makeCheckedImageSnapshot(surface));
+ DataChanged();
+ SAL_INFO("vcl.skia.trace", "invert(" << this << ")");
+ return true;
+ }
+ return false;
+}
+
SkBitmap SkiaSalBitmap::GetAsSkBitmap() const
{
#ifdef DBG_UTIL