vcl/skia/salbmp.cxx                |   12 ++++++++----
 vcl/source/bitmap/alpha.cxx        |   14 ++++++++++++++
 vcl/source/gdi/pdfwriter_impl2.cxx |    6 ++++++
 3 files changed, 28 insertions(+), 4 deletions(-)

New commits:
commit 462f1c43cc97eb5c13343f285516702aa0c47a8d
Author:     Patrick Luby <plub...@neooffice.org>
AuthorDate: Wed Aug 23 17:22:55 2023 -0400
Commit:     Patrick Luby <plub...@neooffice.org>
CommitDate: Thu Aug 24 15:14:43 2023 +0200

    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.gran...@collabora.co.uk>
    Reviewed-by: Patrick Luby <plub...@neooffice.org>

diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 2aa9a0a69cee..0876efed92ed 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 ff0d035d52d1..cb8be28664d4 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 cd46a6a2e9fe..37583d0b01d1 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -509,7 +509,13 @@ 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

Reply via email to