Kaydet (Commit) 8939cb94 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

tdf#115420 fix DC usecount and drop wrong asserts

For DC initialization we check the thread ID to assign a normal
or cached DC to the corresponding WinSalGraphics variable.
The cached DC has a usage count, as there are some limits on
cached DCs count (DCX_CACHE).

But for the WinSalGraphics DC init and release the variable just
matters for the accounting, and generally which thread is doing
the calls: the non-main thread always has to relay them to the
main application thread.

Since we're releasing all WinSalGraphics in ~WinSalFrame and do
all release and re-init in ImplSetParentFrame, there is no way
to correspond the thread ID to the WinSalGraphics variable.

So this drops the wrong assertions based on the WinSalGraphics
variables and renames the GETDC message to GETCACHEDDC to make
usage of a cached DC (DCX_CACHE) more obvious.
As a consequence of the different release DC handling this also
fixes the accounting of the cached DCs, wich was broken in the
initial fix; commit c15ea73f

Change-Id: I11ce52a1b4005f26567f92588437fa37bf227a2e
Reviewed-on: https://gerrit.libreoffice.org/51318Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst b120932c
...@@ -215,7 +215,7 @@ int ImplSalWICompareAscii( const wchar_t* pStr1, const char* pStr2 ); ...@@ -215,7 +215,7 @@ int ImplSalWICompareAscii( const wchar_t* pStr1, const char* pStr2 );
// wParam == 0; lParam == pObject; // wParam == 0; lParam == pObject;
#define SAL_MSG_DESTROYOBJECT (WM_USER+117) #define SAL_MSG_DESTROYOBJECT (WM_USER+117)
// wParam == hWnd; lParam == 0; lResult == hDC // wParam == hWnd; lParam == 0; lResult == hDC
#define SAL_MSG_GETDC (WM_USER+120) #define SAL_MSG_GETCACHEDDC (WM_USER+120)
// wParam == hWnd; lParam == 0 // wParam == hWnd; lParam == 0
#define SAL_MSG_RELEASEDC (WM_USER+121) #define SAL_MSG_RELEASEDC (WM_USER+121)
// wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd // wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
......
...@@ -33,8 +33,8 @@ public: ...@@ -33,8 +33,8 @@ public:
HWND mhWnd; // Window handle HWND mhWnd; // Window handle
HCURSOR mhCursor; // cursor handle HCURSOR mhCursor; // cursor handle
HIMC mhDefIMEContext; // default IME-Context HIMC mhDefIMEContext; // default IME-Context
WinSalGraphics* mpLocalGraphics; // current local frame graphics WinSalGraphics* mpLocalGraphics; // current main thread frame graphics
WinSalGraphics* mpThreadGraphics; // current frame graphics for other threads WinSalGraphics* mpThreadGraphics; // current frame graphics for other threads (DCX_CACHE)
WinSalFrame* mpNextFrame; // pointer to next frame WinSalFrame* mpNextFrame; // pointer to next frame
HMENU mSelectedhMenu; // the menu where highlighting is currently going on HMENU mSelectedhMenu; // the menu where highlighting is currently going on
HMENU mLastActivatedhMenu; // the menu that was most recently opened HMENU mLastActivatedhMenu; // the menu that was most recently opened
......
...@@ -630,7 +630,7 @@ LRESULT CALLBACK SalComWndProc( HWND, UINT nMsg, WPARAM wParam, LPARAM lParam, b ...@@ -630,7 +630,7 @@ LRESULT CALLBACK SalComWndProc( HWND, UINT nMsg, WPARAM wParam, LPARAM lParam, b
CASE_NOYIELDLOCK_RESULT( SAL_MSG_CREATEOBJECT, ImplSalCreateObject( CASE_NOYIELDLOCK_RESULT( SAL_MSG_CREATEOBJECT, ImplSalCreateObject(
GetSalData()->mpInstance, reinterpret_cast<WinSalFrame*>(lParam)) ) GetSalData()->mpInstance, reinterpret_cast<WinSalFrame*>(lParam)) )
CASE_NOYIELDLOCK( SAL_MSG_DESTROYOBJECT, delete reinterpret_cast<SalObject*>(lParam) ) CASE_NOYIELDLOCK( SAL_MSG_DESTROYOBJECT, delete reinterpret_cast<SalObject*>(lParam) )
CASE_NOYIELDLOCK_RESULT( SAL_MSG_GETDC, GetDCEx( CASE_NOYIELDLOCK_RESULT( SAL_MSG_GETCACHEDDC, GetDCEx(
reinterpret_cast<HWND>(wParam), nullptr, DCX_CACHE) ) reinterpret_cast<HWND>(wParam), nullptr, DCX_CACHE) )
CASE_NOYIELDLOCK( SAL_MSG_RELEASEDC, ReleaseDC( CASE_NOYIELDLOCK( SAL_MSG_RELEASEDC, ReleaseDC(
reinterpret_cast<HWND>(wParam), reinterpret_cast<HDC>(lParam)) ) reinterpret_cast<HWND>(wParam), reinterpret_cast<HDC>(lParam)) )
......
...@@ -920,17 +920,12 @@ bool WinSalFrame::ReleaseFrameGraphicsDC( WinSalGraphics* pGraphics ) ...@@ -920,17 +920,12 @@ bool WinSalFrame::ReleaseFrameGraphicsDC( WinSalGraphics* pGraphics )
// we don't want to run the WinProc in the main thread directly // we don't want to run the WinProc in the main thread directly
// so we don't hit the mbNoYieldLock assert // so we don't hit the mbNoYieldLock assert
if ( !pSalData->mpInstance->IsMainThread() ) if ( !pSalData->mpInstance->IsMainThread() )
{
assert( pGraphics == mpThreadGraphics );
SendMessageW( pSalData->mpInstance->mhComWnd, SAL_MSG_RELEASEDC, SendMessageW( pSalData->mpInstance->mhComWnd, SAL_MSG_RELEASEDC,
reinterpret_cast<WPARAM>(mhWnd), reinterpret_cast<LPARAM>(hDC) ); reinterpret_cast<WPARAM>(mhWnd), reinterpret_cast<LPARAM>(hDC) );
pSalData->mnCacheDCInUse--;
}
else else
{
assert( pGraphics == mpLocalGraphics );
ReleaseDC( mhWnd, hDC ); ReleaseDC( mhWnd, hDC );
} if ( pGraphics == mpThreadGraphics )
pSalData->mnCacheDCInUse--;
pGraphics->setHDC(nullptr); pGraphics->setHDC(nullptr);
return TRUE; return TRUE;
} }
...@@ -994,10 +989,6 @@ bool WinSalFrame::InitFrameGraphicsDC( WinSalGraphics *pGraphics, HDC hDC, HWND ...@@ -994,10 +989,6 @@ bool WinSalFrame::InitFrameGraphicsDC( WinSalGraphics *pGraphics, HDC hDC, HWND
{ {
SalData* pSalData = GetSalData(); SalData* pSalData = GetSalData();
assert( pGraphics ); assert( pGraphics );
if ( !pSalData->mpInstance->IsMainThread() )
assert( pGraphics == mpThreadGraphics );
else
assert( pGraphics == mpLocalGraphics );
pGraphics->setHWND( hWnd ); pGraphics->setHWND( hWnd );
HDC hCurrentDC = pGraphics->getHDC(); HDC hCurrentDC = pGraphics->getHDC();
...@@ -1045,7 +1036,7 @@ SalGraphics* WinSalFrame::AcquireGraphics() ...@@ -1045,7 +1036,7 @@ SalGraphics* WinSalFrame::AcquireGraphics()
pGraphics = mpThreadGraphics; pGraphics = mpThreadGraphics;
assert( !pGraphics->getHDC() ); assert( !pGraphics->getHDC() );
hDC = reinterpret_cast<HDC>(static_cast<sal_IntPtr>(SendMessageW( pSalData->mpInstance->mhComWnd, hDC = reinterpret_cast<HDC>(static_cast<sal_IntPtr>(SendMessageW( pSalData->mpInstance->mhComWnd,
SAL_MSG_GETDC, reinterpret_cast<WPARAM>(mhWnd), 0 ))); SAL_MSG_GETCACHEDDC, reinterpret_cast<WPARAM>(mhWnd), 0 )));
} }
else else
{ {
...@@ -1525,7 +1516,7 @@ void WinSalFrame::ImplSetParentFrame( HWND hNewParentWnd, bool bAsChild ) ...@@ -1525,7 +1516,7 @@ void WinSalFrame::ImplSetParentFrame( HWND hNewParentWnd, bool bAsChild )
{ {
HDC hDC = reinterpret_cast<HDC>(static_cast<sal_IntPtr>( HDC hDC = reinterpret_cast<HDC>(static_cast<sal_IntPtr>(
SendMessageW( pSalData->mpInstance->mhComWnd, SendMessageW( pSalData->mpInstance->mhComWnd,
SAL_MSG_GETDC, reinterpret_cast<WPARAM>(hWnd), 0 ))); SAL_MSG_GETCACHEDDC, reinterpret_cast<WPARAM>(hWnd), 0 )));
InitFrameGraphicsDC( mpThreadGraphics, hDC, hWnd ); InitFrameGraphicsDC( mpThreadGraphics, hDC, hWnd );
if ( hDC ) if ( hDC )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment