[Libreoffice-commits] core.git: vcl/win

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Feb 6 07:30:04 UTC 2019


 vcl/win/gdi/salvd.cxx |   68 ++++++++++++++++++++++----------------------------
 1 file changed, 31 insertions(+), 37 deletions(-)

New commits:
commit d3e888cf9e053259076671e8bea0d667c1f92357
Author:     Dmitriy Shilin <dshil at fastmail.com>
AuthorDate: Wed Jan 30 22:48:07 2019 -0800
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Feb 6 08:29:41 2019 +0100

    tdf#107792 vcl/win: simplify WinSalInstance::CreateVirtualDevice
    
    Change-Id: I7e2fd41f8c4359374af143aaf7544bb61a8878c7
    Reviewed-on: https://gerrit.libreoffice.org/67189
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/vcl/win/gdi/salvd.cxx b/vcl/win/gdi/salvd.cxx
index 6dc94f0b12a2..bd6310b38759 100644
--- a/vcl/win/gdi/salvd.cxx
+++ b/vcl/win/gdi/salvd.cxx
@@ -78,25 +78,11 @@ std::unique_ptr<SalVirtualDevice> WinSalInstance::CreateVirtualDevice( SalGraphi
                                                        const SystemGraphicsData* pData )
 {
     WinSalGraphics* pGraphics = static_cast<WinSalGraphics*>(pSGraphics);
-
-    sal_uInt16 nBitCount;
-    switch (eFormat)
-    {
-        case DeviceFormat::BITMASK:
-            nBitCount = 1;
-            break;
-        default:
-            nBitCount = 0;
-            break;
-    }
-
-    HDC     hDC = nullptr;
-    HBITMAP hBmp = nullptr;
+    HDC hDC = nullptr;
 
     if( pData )
     {
         hDC = (pData->hDC) ? pData->hDC : GetDC(pData->hWnd);
-        hBmp = nullptr;
         if (hDC)
         {
             nDX = GetDeviceCaps( hDC, HORZRES );
@@ -112,39 +98,47 @@ std::unique_ptr<SalVirtualDevice> WinSalInstance::CreateVirtualDevice( SalGraphi
     {
         hDC = CreateCompatibleDC( pGraphics->getHDC() );
         SAL_WARN_IF( !hDC, "vcl", "CreateCompatibleDC failed: " << WindowsErrorString( GetLastError() ) );
+    }
+
+    if (!hDC)
+        return nullptr;
 
-        void *pDummy;
-        hBmp = WinSalVirtualDevice::ImplCreateVirDevBitmap(pGraphics->getHDC(), nDX, nDY, nBitCount, &pDummy);
+    sal_uInt16 nBitCount = (eFormat == DeviceFormat::BITMASK) ? 1 : 0;
 
+    HBITMAP hBmp = nullptr;
+    if (!pData)
+    {
         // #124826# continue even if hBmp could not be created
         // if we would return a failure in this case, the process
         // would terminate which is not required
+        hBmp = WinSalVirtualDevice::ImplCreateVirDevBitmap(pGraphics->getHDC(),
+                                                           nDX, nDY, nBitCount,
+                                                           &o3tl::temporary<void*>(nullptr));
     }
 
-    if (hDC)
-    {
-        WinSalVirtualDevice*    pVDev = new WinSalVirtualDevice(hDC, hBmp, nBitCount, (pData != nullptr && pData->hDC != nullptr ), nDX, nDY);
-        SalData*                pSalData = GetSalData();
-        WinSalGraphics*         pVirGraphics = new WinSalGraphics(WinSalGraphics::VIRTUAL_DEVICE, pGraphics->isScreen(), nullptr, pVDev);
-        pVirGraphics->SetLayout( SalLayoutFlags::NONE );   // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
-        pVirGraphics->setHDC(hDC);
-        if ( pSalData->mhDitherPal && pVirGraphics->isScreen() )
-        {
-            pVirGraphics->setDefPal(SelectPalette( hDC, pSalData->mhDitherPal, TRUE ));
-            RealizePalette( hDC );
-        }
-        pVirGraphics->InitGraphics();
+    const bool bForeignDC = pData != nullptr && pData->hDC != nullptr;
+    const SalData* pSalData = GetSalData();
 
-        pVDev->setGraphics(pVirGraphics);
+    WinSalVirtualDevice* pVDev = new WinSalVirtualDevice(hDC, hBmp, nBitCount,
+                                                         bForeignDC, nDX, nDY);
 
-        return std::unique_ptr<SalVirtualDevice>(pVDev);
-    }
-    else
+    WinSalGraphics* pVirGraphics = new WinSalGraphics(WinSalGraphics::VIRTUAL_DEVICE,
+                                                      pGraphics->isScreen(), nullptr, pVDev);
+
+    // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
+    pVirGraphics->SetLayout( SalLayoutFlags::NONE );
+    pVirGraphics->setHDC(hDC);
+
+    if ( pSalData->mhDitherPal && pVirGraphics->isScreen() )
     {
-        if ( hBmp )
-            DeleteBitmap( hBmp );
-        return nullptr;
+        pVirGraphics->setDefPal(SelectPalette( hDC, pSalData->mhDitherPal, TRUE ));
+        RealizePalette( hDC );
     }
+
+    pVirGraphics->InitGraphics();
+    pVDev->setGraphics(pVirGraphics);
+
+    return std::unique_ptr<SalVirtualDevice>(pVDev);
 }
 
 WinSalVirtualDevice::WinSalVirtualDevice(HDC hDC, HBITMAP hBMP, sal_uInt16 nBitCount, bool bForeignDC, long nWidth, long nHeight)


More information about the Libreoffice-commits mailing list