diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2021-09-20 17:55:37 +0200 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2022-05-18 12:33:19 +0200 |
commit | 3571b8e600b24e2e1109cd4c64b615937d3e2cb7 (patch) | |
tree | 5e074bfe3688146d7f47fe70b0927676e25b4c76 | |
parent | d0e734297046eb0470fdf58f9ad3c001214a797f (diff) |
WIN lazy init WinSalInfoPrinter graphics
... and while at it make stuff private and add _ to the newly
private member variables.
The new assert revealed a bug in the SalGraphics refcounting,
because the virtual ReleaseGraphics is called from the
destructor, which was probably also the reason for the HACK
and comment in Printer::ImplReleaseFonts.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122371
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
(cherry picked from commit 1b7c53db87bb67eeb2591fbb186f7ac20eb00c68)
Conflicts:
vcl/win/gdi/salprn.cxx
Change-Id: I7af0bda19be6810dd8c0ea5b74604381e2047407
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134515
Tested-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
-rw-r--r-- | include/vcl/print.hxx | 1 | ||||
-rw-r--r-- | vcl/inc/win/salprn.h | 13 | ||||
-rw-r--r-- | vcl/source/gdi/print.cxx | 15 | ||||
-rw-r--r-- | vcl/win/gdi/salprn.cxx | 57 |
4 files changed, 47 insertions, 39 deletions
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx index fbdf9c9e19cb..5beb2d964c83 100644 --- a/include/vcl/print.hxx +++ b/include/vcl/print.hxx @@ -226,6 +226,7 @@ public: protected: virtual bool AcquireGraphics() const override; virtual void ReleaseGraphics( bool bRelease = true ) override; + void ImplReleaseGraphics(bool bRelease = true); virtual void ImplReleaseFonts() override; virtual long GetGradientStepCount( long nMinRect ) override; diff --git a/vcl/inc/win/salprn.h b/vcl/inc/win/salprn.h index c0c6e7fb7932..9e921dd3090e 100644 --- a/vcl/inc/win/salprn.h +++ b/vcl/inc/win/salprn.h @@ -40,19 +40,24 @@ struct SalDriverData class WinSalGraphics; -class WinSalInfoPrinter : public SalInfoPrinter +class WinSalInfoPrinter final : public SalInfoPrinter { public: - WinSalGraphics* mpGraphics; // current Printer graphics OUString maDriverName; // printer driver name OUString maDeviceName; // printer device name OUString maPortName; // printer port name - HDC mhDC; // printer hdc - bool mbGraphics; // is Graphics used + +private: + HDC m_hDC; ///< printer hdc + WinSalGraphics* m_pGraphics; ///< current Printer graphics + bool m_bGraphics; ///< is Graphics used + public: WinSalInfoPrinter(); virtual ~WinSalInfoPrinter() override; + void setHDC(HDC); + virtual SalGraphics* AcquireGraphics() override; virtual void ReleaseGraphics( SalGraphics* pGraphics ) override; virtual bool Setup( weld::Window* pFrame, ImplJobSetup* pSetupData ) override; diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx index 0cf07a6ac578..09f3dbda47e2 100644 --- a/vcl/source/gdi/print.cxx +++ b/vcl/source/gdi/print.cxx @@ -547,13 +547,7 @@ bool Printer::AcquireGraphics() const void Printer::ImplReleaseFonts() { -#ifdef UNX - // HACK to fix an urgent P1 printing issue fast - // WinSalPrinter does not respect GetGraphics/ReleaseGraphics conventions - // so Printer::mpGraphics often points to a dead WinSalGraphics - // TODO: fix WinSalPrinter's GetGraphics/ReleaseGraphics handling mpGraphics->ReleaseFonts(); -#endif mbNewFont = true; mbInitFont = true; @@ -562,7 +556,7 @@ void Printer::ImplReleaseFonts() mpDeviceFontSizeList.reset(); } -void Printer::ReleaseGraphics( bool bRelease ) +void Printer::ImplReleaseGraphics(bool bRelease) { DBG_TESTSOLARMUTEX(); @@ -615,6 +609,11 @@ void Printer::ReleaseGraphics( bool bRelease ) mpNextGraphics = nullptr; } +void Printer::ReleaseGraphics(bool bRelease) +{ + ImplReleaseGraphics(bRelease); +} + void Printer::ImplInit( SalPrinterQueueInfo* pInfo ) { ImplSVData* pSVData = ImplGetSVData(); @@ -909,7 +908,7 @@ void Printer::dispose() mpPrinterOptions.reset(); - ReleaseGraphics(); + ImplReleaseGraphics(); if ( mpInfoPrinter ) ImplGetSVData()->mpDefInst->DestroyInfoPrinter( mpInfoPrinter ); if ( mpDisplayDev ) diff --git a/vcl/win/gdi/salprn.cxx b/vcl/win/gdi/salprn.cxx index adb9f0e102d0..1fe4968690bd 100644 --- a/vcl/win/gdi/salprn.cxx +++ b/vcl/win/gdi/salprn.cxx @@ -1040,17 +1040,8 @@ static bool ImplUpdateSalPrnIC( WinSalInfoPrinter* pPrinter, const ImplJobSetup* if ( !hNewDC ) return FALSE; - if ( pPrinter->mpGraphics ) - { - assert(pPrinter->mpGraphics->getHDC() == pPrinter->mhDC); - delete pPrinter->mpGraphics; - DeleteDC(pPrinter->mhDC); - } - - pPrinter->mpGraphics = ImplCreateSalPrnGraphics( hNewDC ); - pPrinter->mhDC = hNewDC; - - return TRUE; + pPrinter->setHDC(hNewDC); + return true; } @@ -1074,8 +1065,7 @@ SalInfoPrinter* WinSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueIn return nullptr; } - pPrinter->mpGraphics = ImplCreateSalPrnGraphics( hDC ); - pPrinter->mhDC = hDC; + pPrinter->setHDC(hDC); if ( !pSetupData->GetDriverData() ) ImplUpdateSalJobSetup( pPrinter, pSetupData, false, nullptr ); ImplDevModeToJobSetup( pPrinter, pSetupData, JobSetFlags::ALL ); @@ -1091,23 +1081,33 @@ void WinSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter ) WinSalInfoPrinter::WinSalInfoPrinter() : - mpGraphics( nullptr ), - mhDC( nullptr ), - mbGraphics( FALSE ) + m_hDC(nullptr), + m_pGraphics(nullptr), + m_bGraphics(false) { m_bPapersInit = FALSE; } WinSalInfoPrinter::~WinSalInfoPrinter() { - if ( mpGraphics ) + setHDC(nullptr); +} + +void WinSalInfoPrinter::setHDC(HDC hNewDC) +{ + assert(!m_bGraphics); + + if (m_hDC) { + assert(!m_pGraphics || m_hDC == m_pGraphics->getHDC()); // we get intermittent crashes on the Windows jenkins box around here, let us see if there is something weird about the DC - SAL_WARN("vcl", "Graphics DC " << mpGraphics->getHDC()); - assert(mpGraphics->getHDC() == mhDC); - delete mpGraphics; - DeleteDC(mhDC); + SAL_WARN_IF(!hNewDC, "vcl", "Graphics DC " << m_hDC); + delete m_pGraphics; + m_pGraphics = nullptr; + DeleteDC(m_hDC); } + + m_hDC = hNewDC; } void WinSalInfoPrinter::InitPaperFormats( const ImplJobSetup* pSetupData ) @@ -1148,18 +1148,21 @@ int WinSalInfoPrinter::GetLandscapeAngle( const ImplJobSetup* pSetupData ) SalGraphics* WinSalInfoPrinter::AcquireGraphics() { - if ( mbGraphics ) + assert(m_hDC); + if (m_bGraphics) return nullptr; - if ( mpGraphics ) - mbGraphics = TRUE; + if (!m_pGraphics) + m_pGraphics = ImplCreateSalPrnGraphics(m_hDC); + if (m_pGraphics) + m_bGraphics = true; - return mpGraphics; + return m_pGraphics; } void WinSalInfoPrinter::ReleaseGraphics( SalGraphics* ) { - mbGraphics = FALSE; + m_bGraphics = false; } bool WinSalInfoPrinter::Setup(weld::Window* pFrame, ImplJobSetup* pSetupData) @@ -1265,7 +1268,7 @@ void WinSalInfoPrinter::GetPageInfo( const ImplJobSetup*, Point& rPageOffset, Size& rPaperSize ) { - HDC hDC = mhDC; + HDC hDC = m_hDC; rOutWidth = GetDeviceCaps( hDC, HORZRES ); rOutHeight = GetDeviceCaps( hDC, VERTRES ); |