Related tdf#156630 and tdf#156629 force snapshot of alpha mask

On macOS, with Skia/Metal or Skia/Raster with a Retina display
(i.e. 2.0 window scale), the alpha mask gets upscaled in certain
cases.

This bug appears to be caused by pending scaling of an existing
SkImage in the bitmap parameter. So, force the SkiaSalBitmap to
handle its pending scaling.

This change consolidates the three duplicate fixes added in the
following commits into the AlphaMask(const Bitmap&) constructor.

  commit 12fd870113a663dde5ceb38c61f1986a34095d0e
  commit ce2d9f5dd4b6a26847c4779bce4866d969ff4400

From my light testing, the bitmap's SkImage is not scaled except
when running macOS with a Retina display. The only exception is
that this fix will be triggered on all platforms when exporting
to PDF images with an alpha mask.

Change-Id: Iea5afd55aac984ca606b2b4b44e457d81d76fac0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155568
Tested-by: Jenkins
Reviewed-by: Patrick Luby <plubius@neooffice.org>
diff --git a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
index 7c9f7b3..e5658f6 100644
--- a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
+++ b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
@@ -180,19 +180,7 @@ namespace drawinglayer::primitive2d
                BitmapEx bitmap;
                if( useAlphaMask )
                {
                    AlphaMask aMaskBitmap(maVirtualDeviceMask->GetBitmap(Point(), maVirtualDeviceMask->GetOutputSizePixel()));

                    // Related tdf#156630 force snapshot of alpha mask
                    // On macOS, with Skia/Raster with a Retina display (i.e.
                    // 2.0 window scale), the alpha mask gets upscaled. Also,
                    // when Skia is enabled, the alpha mask gets inverted in
                    // the first export to PDF after launching the application.
                    // These two bugs appear to be caused by asynchronous
                    // rendering of the returned bitmap. So, we force a copy
                    // of the alpha mask in case it changes before the bitmap
                    // is actually drawn.
                    AlphaMask::ScopedReadAccess pAccessAlpha(aMaskBitmap);

                    const AlphaMask aMaskBitmap(maVirtualDeviceMask->GetBitmap(Point(), maVirtualDeviceMask->GetOutputSizePixel()));
                    bitmap = BitmapEx(aMainBitmap, aMaskBitmap);
                }
                else
diff --git a/slideshow/source/engine/shapes/gdimtftools.cxx b/slideshow/source/engine/shapes/gdimtftools.cxx
index 1928052..2fc3c86f 100644
--- a/slideshow/source/engine/shapes/gdimtftools.cxx
+++ b/slideshow/source/engine/shapes/gdimtftools.cxx
@@ -354,18 +354,6 @@ bool getAnimationFromGraphic( VectorOfMtfAnimationFrames&   o_rFrames,
        if( useAlphaMask )
        {
            AlphaMask aAlphaMask(pVDevMask->GetBitmap(aEmptyPoint, aAnimSize));

            // Related tdf#156630 force snapshot of alpha mask
            // On macOS, with Skia/Raster with a Retina display (i.e.
            // 2.0 window scale), the alpha mask gets upscaled. Also,
            // when Skia is enabled, the alpha mask gets inverted in
            // the first export to PDF after launching the application.
            // These two bugs appear to be caused by asynchronous
            // rendering of the returned bitmap. So, we force a copy
            // of the alpha mask in case it changes before the bitmap
            // is actually drawn.
            AlphaMask::ScopedReadAccess pAccessAlpha(aAlphaMask);

            pMtf->AddAction(
                new MetaBmpExAction( aEmptyPoint,
                                     BitmapEx(
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 8e07a00..b5da2e4 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -224,6 +224,20 @@ BitmapBuffer* SkiaSalBitmap::AcquireBuffer(BitmapAccessMode nMode)
            assert(!mEraseColorSet);
            break;
        case BitmapAccessMode::Info:
            // Related tdf#156630 and tdf#156629 force snapshot of alpha mask
            // On macOS, with Skia/Metal or Skia/Raster with a Retina display
            // (i.e. 2.0 window scale), the alpha mask gets upscaled in certain
            // cases.
            // This bug appears to be caused by pending scaling of an existing
            // SkImage in the bitmap parameter. So, force the SkiaSalBitmap to
            // handle its pending scaling.
            // Note: also handle pending scaling if SAL_FORCE_HIDPI_SCALING is
            // set otherwise exporting the following animated .png image will
            // fail:
            //   https://bugs.documentfoundation.org/attachment.cgi?id=188792
            if ((mPixelsSize != mSize || getenv("SAL_FORCE_HIDPI_SCALING")) && mImage)
                EnsureBitmapData();
            assert(mPixelsSize == mSize);
            break;
    }
#ifdef DBG_UTIL
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 8077253..f5275eb 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -861,21 +861,7 @@ Image createImage(const OUString& rImage)

Image createImage(const VirtualDevice& rDevice)
{
    BitmapEx aBitmapEx(rDevice.GetBitmapEx(Point(), rDevice.GetOutputSizePixel()));

    // Related tdf#156629 force snapshot of alpha mask
    // On macOS, with Skia/Metal with a Retina display (i.e. 2.0 window
    // scale), the alpha mask gets upscaled for the font color and the
    // character background color icons in Writer's properties sidebar
    // with most icon sets. The Breeze and Colibre icon sets running in
    // light mode are the most obvious cases.
    // This bug appears to be caused by asynchronous rendering of the
    // returned image. So, we force a copy of the alpha mask in case it
    // changes before the image is actually drawn.
    AlphaMask aAlphaMask(aBitmapEx.GetAlphaMask());
    AlphaMask::ScopedReadAccess pAccessAlpha(aAlphaMask);

    return Image(BitmapEx(aBitmapEx.GetBitmap(), aAlphaMask));
    return Image(rDevice.GetBitmapEx(Point(), rDevice.GetOutputSizePixel()));
}

sal_uInt16 insert_to_menu(sal_uInt16 nLastId, PopupMenu* pMenu, int pos, const OUString& rId,