diff options
| author | Neil <nyamatongwe@gmail.com> | 2019-12-12 12:09:39 +1100 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2019-12-12 12:09:39 +1100 | 
| commit | 24b5d9fca3a7b39ef98ff9a8e498a32fc0957a0f (patch) | |
| tree | e26d4eef9f2c2d194dbf63e91aa2ecf70a55a877 | |
| parent | 8ed33a929a786c73a5b15bb9d5ecf17e23d896ab (diff) | |
| download | scintilla-mirror-24b5d9fca3a7b39ef98ff9a8e498a32fc0957a0f.tar.gz | |
Backport: Hoist common painting code into PaintDC method.
Avoid warnings for potentially NULL pRenderTarget.
Backport of changeset 7836:270a67bbe4cb.
| -rw-r--r-- | win32/ScintillaWin.cxx | 72 | 
1 files changed, 32 insertions, 40 deletions
| diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index d375c7ca8..f57c47d9c 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -334,6 +334,8 @@ class ScintillaWin :  	Sci::Position TargetAsUTF8(char *text) const;  	void AddCharUTF16(wchar_t const *wcs, unsigned int wclen, CharacterSource charSource);  	Sci::Position EncodedFromUTF8(const char *utf8, char *encoded) const; + +	bool PaintDC(HDC hdc);  	sptr_t WndPaint();  	sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam); @@ -838,31 +840,17 @@ void ScintillaWin::AddCharUTF16(wchar_t const *wcs, unsigned int wclen, Characte  	}  } -sptr_t ScintillaWin::WndPaint() { -	//ElapsedPeriod ep; - -	// Redirect assertions to debug output and save current state -	const bool assertsPopup = Platform::ShowAssertionPopUps(false); -	paintState = painting; -	PAINTSTRUCT ps = {}; - -	// Removed since this interferes with reporting other assertions as it occurs repeatedly -	//PLATFORM_ASSERT(hRgnUpdate == NULL); -	hRgnUpdate = ::CreateRectRgn(0, 0, 0, 0); -	::GetUpdateRgn(MainHWND(), hRgnUpdate, FALSE); -	::BeginPaint(MainHWND(), &ps); -	rcPaint = PRectangle::FromInts(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom); -	const PRectangle rcClient = GetClientRectangle(); -	paintingAllText = BoundsContains(rcPaint, hRgnUpdate, rcClient); +bool ScintillaWin::PaintDC(HDC hdc) {  	if (technology == SC_TECHNOLOGY_DEFAULT) { -		AutoSurface surfaceWindow(ps.hdc, this); +		AutoSurface surfaceWindow(hdc, this);  		if (surfaceWindow) {  			Paint(surfaceWindow, rcPaint);  			surfaceWindow->Release();  		}  	} else {  #if defined(USE_D2D) -		EnsureRenderTarget(ps.hdc); +		EnsureRenderTarget(hdc); +		if (pRenderTarget) {  		AutoSurface surfaceWindow(pRenderTarget, this);  		if (surfaceWindow) {  			pRenderTarget->BeginDraw(); @@ -871,11 +859,35 @@ sptr_t ScintillaWin::WndPaint() {  			const HRESULT hr = pRenderTarget->EndDraw();  			if (hr == static_cast<HRESULT>(D2DERR_RECREATE_TARGET)) {  				DropRenderTarget(); -				paintState = paintAbandoned; +					return false; +				}  			}  		}  #endif  	} + +	return true; +} + +sptr_t ScintillaWin::WndPaint() { +	//ElapsedPeriod ep; + +	// Redirect assertions to debug output and save current state +	const bool assertsPopup = Platform::ShowAssertionPopUps(false); +	paintState = painting; +	PAINTSTRUCT ps = {}; + +	// Removed since this interferes with reporting other assertions as it occurs repeatedly +	//PLATFORM_ASSERT(hRgnUpdate == NULL); +	hRgnUpdate = ::CreateRectRgn(0, 0, 0, 0); +	::GetUpdateRgn(MainHWND(), hRgnUpdate, FALSE); +	::BeginPaint(MainHWND(), &ps); +	rcPaint = PRectangle::FromInts(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom); +	const PRectangle rcClient = GetClientRectangle(); +	paintingAllText = BoundsContains(rcPaint, hRgnUpdate, rcClient); +	if (!PaintDC(ps.hdc)) { +		paintState = paintAbandoned; +	}  	if (hRgnUpdate) {  		::DeleteRgn(hRgnUpdate);  		hRgnUpdate = 0; @@ -2995,27 +3007,7 @@ void ScintillaWin::FullPaintDC(HDC hdc) {  	paintState = painting;  	rcPaint = GetClientRectangle();  	paintingAllText = true; -	if (technology == SC_TECHNOLOGY_DEFAULT) { -		AutoSurface surfaceWindow(hdc, this); -		if (surfaceWindow) { -			Paint(surfaceWindow, rcPaint); -			surfaceWindow->Release(); -		} -	} else { -#if defined(USE_D2D) -		EnsureRenderTarget(hdc); -		AutoSurface surfaceWindow(pRenderTarget, this); -		if (surfaceWindow) { -			pRenderTarget->BeginDraw(); -			Paint(surfaceWindow, rcPaint); -			surfaceWindow->Release(); -			const HRESULT hr = pRenderTarget->EndDraw(); -			if (hr == static_cast<HRESULT>(D2DERR_RECREATE_TARGET)) { -				DropRenderTarget(); -			} -		} -#endif -	} +	PaintDC(hdc);  	paintState = notPainting;  } | 
