tdf#156361 use slow blending path if alpha mask blending is diabled

SkiaSalGraphicsImpl::blendBitmap() fails unexpectedly in the following
cases so return false and use the non-Skia alpha mask blending code:
- Unexpected white areas when running a slideshow or printing:
    https://bugs.documentfoundation.org/attachment.cgi?id=188447
- Unexpected scaling of bitmap and/or alpha mask when exporting to PDF:
    https://bugs.documentfoundation.org/attachment.cgi?id=188498

Change-Id: I13ae613f24bff4cd018110a08ed70559a1714687
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154678
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
Reviewed-by: Patrick Luby <plubius@neooffice.org>
diff --git a/include/vcl/skia/SkiaHelper.hxx b/include/vcl/skia/SkiaHelper.hxx
index 37fed7f..769c4d2 100644
--- a/include/vcl/skia/SkiaHelper.hxx
+++ b/include/vcl/skia/SkiaHelper.hxx
@@ -19,6 +19,7 @@ namespace SkiaHelper
{
VCL_DLLPUBLIC bool isVCLSkiaEnabled();
VCL_DLLPUBLIC OUString readLog();
VCL_DLLPUBLIC bool isAlphaMaskBlendingEnabled();

#if HAVE_FEATURE_SKIA

diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index a8332cf..41ce551 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -18,6 +18,7 @@
namespace SkiaHelper
{
bool isVCLSkiaEnabled() { return false; }
bool isAlphaMaskBlendingEnabled() { return false; }

} // namespace

@@ -400,6 +401,8 @@ bool isVCLSkiaEnabled()
    return bRet;
}

bool isAlphaMaskBlendingEnabled() { return false; }

static RenderMethod methodToUse = RenderRaster;

static bool initRenderMethodToUse()
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 45f3fc1..77aaa19 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -1297,6 +1297,16 @@ bool SkiaSalGraphicsImpl::blendAlphaBitmap(const SalTwoRect& rPosAry,
                                           const SalBitmap& rMaskBitmap,
                                           const SalBitmap& rAlphaBitmap)
{
    // tdf#156361 use slow blending path if alpha mask blending is diabled
    // SkiaSalGraphicsImpl::blendBitmap() fails unexpectedly in the following
    // cases so return false and use the non-Skia alpha mask blending code:
    // - Unexpected white areas when running a slideshow or printing:
    //     https://bugs.documentfoundation.org/attachment.cgi?id=188447
    // - Unexpected scaling of bitmap and/or alpha mask when exporting to PDF:
    //     https://bugs.documentfoundation.org/attachment.cgi?id=188498
    if (!SkiaHelper::isAlphaMaskBlendingEnabled())
        return false;

    if (checkInvalidSourceOrDestination(rPosAry))
        return false;

diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 612ea5d..d77b3dd 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -359,7 +359,7 @@ void OutputDevice::DrawDeviceAlphaBitmap( const Bitmap& rBmp, const AlphaMask& r

        // we need to make sure Skia never reaches this slow code path
        // (but do not fail in no-op cases)
        assert(!SkiaHelper::isVCLSkiaEnabled()
        assert(!SkiaHelper::isVCLSkiaEnabled() || !SkiaHelper::isAlphaMaskBlendingEnabled()
            || tools::Rectangle(Point(), rBmp.GetSizePixel())
                .Intersection(tools::Rectangle(rSrcPtPixel, rSrcSizePixel)).IsEmpty()
            || mpAlphaVDev->LogicToPixel(mpAlphaVDev->GetOutputSizePixel()).IsEmpty());