Blame SOURCES/0168-desktop-vcl-support-transparency-in-VirtualDevices-w.patch

135360
From 4678c8d368c3accd85c57745cf58218f5ea1b907 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Thu, 1 Oct 2015 14:17:21 +0200
135360
Subject: [PATCH 168/398] desktop, vcl: support transparency in VirtualDevices
135360
 with user-provided memory
135360
135360
Change-Id: I65c31995c02a644aa436aecd065255fab38045e4
135360
(cherry picked from commit 1d3b613318654ceb2d34996ef8ca653cfe32a8ea)
135360
---
135360
 desktop/source/lib/init.cxx | 24 +++++++++++++++++++++++-
135360
 include/vcl/virdev.hxx      |  2 ++
135360
 vcl/source/gdi/virdev.cxx   | 12 ++++++++----
135360
 3 files changed, 33 insertions(+), 5 deletions(-)
135360
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index 4432ec8ea889..1f87146bacf8 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -754,10 +754,21 @@ void doc_paintTile (LibreOfficeKitDocument* pThis,
135360
     InitSvpForLibreOfficeKit();
135360
 
135360
     ScopedVclPtrInstance< VirtualDevice > pDevice(nullptr, Size(1, 1), (sal_uInt16)32) ;
135360
+
135360
+    // Set background to transparent by default.
135360
+    memset(pBuffer, 0, nCanvasWidth * nCanvasHeight * 4);
135360
+    pDevice->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
135360
+
135360
     boost::shared_array< sal_uInt8 > aBuffer( pBuffer, NoDelete< sal_uInt8 >() );
135360
+
135360
+    // Allocate a separate buffer for the alpha device.
135360
+    std::vector<sal_uInt8> aAlpha(nCanvasWidth * nCanvasHeight);
135360
+    memset(aAlpha.data(), 0, nCanvasWidth * nCanvasHeight);
135360
+    boost::shared_array<sal_uInt8> aAlphaBuffer(aAlpha.data(), NoDelete<sal_uInt8>());
135360
+
135360
     pDevice->SetOutputSizePixelScaleOffsetAndBuffer(
135360
                 Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(),
135360
-                aBuffer, true );
135360
+                aBuffer, aAlphaBuffer, true );
135360
 
135360
     pDoc->paintTile(*pDevice.get(), nCanvasWidth, nCanvasHeight,
135360
                     nTilePosX, nTilePosY, nTileWidth, nTileHeight);
135360
@@ -771,6 +782,17 @@ void doc_paintTile (LibreOfficeKitDocument* pThis,
135360
                     nTilePosX, nTilePosY, nTileWidth, nTileHeight);
135360
 #endif
135360
 
135360
+    // Overwrite pBuffer's alpha channel with the separate alpha buffer.
135360
+    for (int nRow = 0; nRow < nCanvasHeight; ++nRow)
135360
+    {
135360
+        for (int nCol = 0; nCol < nCanvasWidth; ++nCol)
135360
+        {
135360
+            const int nOffset = (nCanvasHeight * nRow) + nCol;
135360
+            // VCL's transparent is 0, RGBA's transparent is 0xff.
135360
+            pBuffer[nOffset * 4 +3] = 0xff - aAlpha[nOffset];
135360
+        }
135360
+    }
135360
+
135360
     static bool bDebug = getenv("LOK_DEBUG") != 0;
135360
     if (bDebug)
135360
     {
135360
diff --git a/include/vcl/virdev.hxx b/include/vcl/virdev.hxx
135360
index 3720a19c98f3..85e0afd78131 100644
135360
--- a/include/vcl/virdev.hxx
135360
+++ b/include/vcl/virdev.hxx
135360
@@ -48,6 +48,7 @@ private:
135360
                                                      const bool bTopDown );
135360
     SAL_DLLPRIVATE bool ImplSetOutputSizePixel( const Size& rNewSize, bool bErase,
135360
                                                 const basebmp::RawMemorySharedArray &pBuffer,
135360
+                                                const basebmp::RawMemorySharedArray &pAlphaBuffer,
135360
                                                 const bool bTopDown );
135360
 
135360
     VirtualDevice (const VirtualDevice &) SAL_DELETED_FUNCTION;
135360
@@ -127,6 +128,7 @@ public:
135360
                                                                 const Fraction& rScale,
135360
                                                                 const Point& rNewOffset,
135360
                                                                 const basebmp::RawMemorySharedArray &pBuffer,
135360
+                                                                const basebmp::RawMemorySharedArray &pAlphaBuffer,
135360
                                                                 const bool bTopDown = false );
135360
     bool                SetOutputSize( const Size& rNewSize, bool bErase = true )
135360
                             { return SetOutputSizePixel( LogicToPixel( rNewSize ), bErase ); }
135360
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
135360
index b24378de4b25..ee44d30267e8 100644
135360
--- a/vcl/source/gdi/virdev.cxx
135360
+++ b/vcl/source/gdi/virdev.cxx
135360
@@ -393,6 +393,7 @@ void VirtualDevice::ImplFillOpaqueRectangle( const Rectangle& rRect )
135360
 
135360
 bool VirtualDevice::ImplSetOutputSizePixel( const Size& rNewSize, bool bErase,
135360
                                             const basebmp::RawMemorySharedArray &pBuffer,
135360
+                                            const basebmp::RawMemorySharedArray &pAlphaBuffer,
135360
                                             const bool bTopDown )
135360
 {
135360
     if( InnerImplSetOutputSizePixel(rNewSize, bErase, pBuffer, bTopDown) )
135360
@@ -409,7 +410,7 @@ bool VirtualDevice::ImplSetOutputSizePixel( const Size& rNewSize, bool bErase,
135360
             {
135360
                 mpAlphaVDev = VclPtr<VirtualDevice>::Create( *this, mnAlphaDepth );
135360
                 mpAlphaVDev->InnerImplSetOutputSizePixel(rNewSize, bErase,
135360
-                                                         basebmp::RawMemorySharedArray(),
135360
+                                                         pAlphaBuffer,
135360
                                                          bTopDown );
135360
             }
135360
 
135360
@@ -443,13 +444,16 @@ void VirtualDevice::EnableRTL( bool bEnable )
135360
 
135360
 bool VirtualDevice::SetOutputSizePixel( const Size& rNewSize, bool bErase )
135360
 {
135360
-    return ImplSetOutputSizePixel( rNewSize, bErase, basebmp::RawMemorySharedArray(), false );
135360
+    return ImplSetOutputSizePixel( rNewSize, bErase, basebmp::RawMemorySharedArray(), basebmp::RawMemorySharedArray(), false );
135360
 }
135360
 
135360
 bool VirtualDevice::SetOutputSizePixelScaleOffsetAndBuffer(
135360
     const Size& rNewSize, const Fraction& rScale, const Point& rNewOffset,
135360
-    const basebmp::RawMemorySharedArray &pBuffer, const bool bTopDown )
135360
+    const basebmp::RawMemorySharedArray &pBuffer, const basebmp::RawMemorySharedArray &pAlphaBuffer, const bool bTopDown )
135360
 {
135360
+    if (pAlphaBuffer)
135360
+        mnAlphaDepth = 8;
135360
+
135360
     if (pBuffer) {
135360
         MapMode mm = GetMapMode();
135360
         mm.SetOrigin( rNewOffset );
135360
@@ -457,7 +461,7 @@ bool VirtualDevice::SetOutputSizePixelScaleOffsetAndBuffer(
135360
         mm.SetScaleY( rScale );
135360
         SetMapMode( mm );
135360
     }
135360
-    return ImplSetOutputSizePixel( rNewSize, true, pBuffer, bTopDown );
135360
+    return ImplSetOutputSizePixel( rNewSize, true, pBuffer, pAlphaBuffer, bTopDown );
135360
 }
135360
 
135360
 void VirtualDevice::SetReferenceDevice( RefDevMode i_eRefDevMode )
135360
-- 
135360
2.12.0
135360