diff options
author | Dmitriy Shilin <dshil@fastmail.com> | 2019-01-30 22:48:07 -0800 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-02-06 08:29:41 +0100 |
commit | d3e888cf9e053259076671e8bea0d667c1f92357 (patch) | |
tree | 407367fbc68097a7dd3c90627a8c63f8a4e6f384 /vcl/win | |
parent | 20c4c3acd5fbf38f2e990435bf346d4fbac05f9d (diff) |
tdf#107792 vcl/win: simplify WinSalInstance::CreateVirtualDevice
Change-Id: I7e2fd41f8c4359374af143aaf7544bb61a8878c7
Reviewed-on: https://gerrit.libreoffice.org/67189
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/win')
-rw-r--r-- | vcl/win/gdi/salvd.cxx | 68 |
1 files changed, 31 insertions, 37 deletions
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) |