tdf#156866 use mSize instead of mPixelSize for inverted surface
Commit 5baac4e53128d3c0fc73b9918dc9a9c2777ace08 switched to setting
the surface size to mPixelsSize in an attempt to avoid downscaling
mImage but since it causes tdf#156866, revert back to setting the
surface size to mSize.
Also, in release builds, tdf#156629 and tdf#156630 reappear in many
cases because a BitmapInfoAccess is in a debug block. So, instead
of relying on other code to a create a BitmapInfoAccess instance,
create one here to force the alpha mask to handle any pending
scaling and make the alpha mask immutable.
Change-Id: If9f0dfb7b9a82cf7a3e402965ceffd42eace4c82
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156022
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Patrick Luby <plubius@neooffice.org>
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 2aa9a0a..0876efe 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -672,15 +672,19 @@ bool SkiaSalBitmap::Invert()
if (!mBuffer && mImage && !mImageImmutable && !mEraseColorSet)
{
// This is 8-bit bitmap serving as alpha/transparency/mask, so the image itself needs no alpha.
// Use pixels size so that we don't downscale the image
sk_sp<SkSurface> surface = createSkSurface(mPixelsSize, kOpaque_SkAlphaType);
// tdf#156866 use mSize instead of mPixelSize for inverted surface
// Commit 5baac4e53128d3c0fc73b9918dc9a9c2777ace08 switched to setting
// the surface size to mPixelsSize in an attempt to avoid downscaling
// mImage but since it causes tdf#156866, revert back to setting the
// surface size to mSize.
sk_sp<SkSurface> surface = createSkSurface(mSize, kOpaque_SkAlphaType);
surface->getCanvas()->clear(SK_ColorWHITE);
SkPaint paint;
paint.setBlendMode(SkBlendMode::kDifference);
// Drawing the image does not work so create a shader from the image
paint.setShader(GetSkShader(SkSamplingOptions()));
surface->getCanvas()->drawRect(
SkRect::MakeXYWH(0, 0, mPixelsSize.Width(), mPixelsSize.Height()), paint);
surface->getCanvas()->drawRect(SkRect::MakeXYWH(0, 0, mSize.Width(), mSize.Height()),
paint);
ResetToSkImage(makeCheckedImageSnapshot(surface));
DataChanged();
SAL_INFO("vcl.skia.trace", "invert(" << this << ")");
diff --git a/vcl/source/bitmap/alpha.cxx b/vcl/source/bitmap/alpha.cxx
index ff0d035..cb8be28 100644
--- a/vcl/source/bitmap/alpha.cxx
+++ b/vcl/source/bitmap/alpha.cxx
@@ -25,6 +25,10 @@
#include <svdata.hxx>
#include <salbmp.hxx>
#include <sal/log.hxx>
#if HAVE_FEATURE_SKIA
#include <vcl/skia/SkiaHelper.hxx>
#endif
AlphaMask::AlphaMask() = default;
@@ -34,6 +38,16 @@ AlphaMask::AlphaMask( const Bitmap& rBitmap ) :
// no need to do any conversion if it is already an AlphaMask
if ( typeid(rBitmap) != typeid(AlphaMask) && !rBitmap.IsEmpty() )
Convert( BmpConversion::N8BitNoConversion );
#if HAVE_FEATURE_SKIA
// Related tdf#156866 force snapshot of alpha mask when using Skia
// In release builds, tdf#156629 and tdf#156630 reappear in many
// cases because a BitmapInfoAccess is in a debug block. So, instead
// of relying on other code to a create a BitmapInfoAccess instance,
// create one here to force the alpha mask to handle any pending
// scaling and make the alpha mask immutable.
else if ( SkiaHelper::isVCLSkiaEnabled() )
BitmapInfoAccess aInfoAccess( *this );
#endif
assert( (IsEmpty() || getPixelFormat() == vcl::PixelFormat::N8_BPP) && "alpha bitmap should be 8bpp" );
assert( (IsEmpty() || HasGreyPalette8Bit()) && "alpha bitmap should have greyscale palette" );
}
diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx
index cd46a6a..37583d0 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -509,8 +509,14 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa
aAlpha.Invert(); // convert to alpha
aAlpha.BlendWith(aPaintAlpha);
#if HAVE_FEATURE_SKIA
#if OSL_DEBUG_LEVEL > 0
// In release builds, we always invert
// regardless of whether Skia is enabled or not.
// But in debug builds, we can't invert when
// Skia is enabled.
if ( !SkiaHelper::isVCLSkiaEnabled() )
#endif
#endif
{
// When Skia is disabled, the alpha mask
// must be inverted a second time. To test