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 | 83cad7d1d019f45a6f72971e060e201a0f680f2c (patch) | |
tree | 178fe210705544c2b61e67eb11d6e9ef0068f4c1 | |
parent | a078390895594ab190e789ea578b2594fe5216b9 (diff) | |
download | scintilla-mirror-83cad7d1d019f45a6f72971e060e201a0f680f2c.tar.gz |
Hoist common painting code into PaintDC method.
Avoid warnings for potentially NULL pRenderTarget.
-rw-r--r-- | win32/ScintillaWin.cxx | 76 |
1 files changed, 34 insertions, 42 deletions
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index b5ff31bae..b896ee458 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -333,6 +333,8 @@ class ScintillaWin : Sci::Position TargetAsUTF8(char *text) const; 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); @@ -835,6 +837,35 @@ Sci::Position ScintillaWin::EncodedFromUTF8(const char *utf8, char *encoded) con } } +bool ScintillaWin::PaintDC(HDC hdc) { + if (technology == SC_TECHNOLOGY_DEFAULT) { + AutoSurface surfaceWindow(hdc, this); + if (surfaceWindow) { + Paint(surfaceWindow, rcPaint); + surfaceWindow->Release(); + } + } else { +#if defined(USE_D2D) + EnsureRenderTarget(hdc); + if (pRenderTarget) { + 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(); + return false; + } + } + } +#endif + } + + return true; +} + sptr_t ScintillaWin::WndPaint() { //ElapsedPeriod ep; @@ -851,27 +882,8 @@ sptr_t ScintillaWin::WndPaint() { 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 (technology == SC_TECHNOLOGY_DEFAULT) { - AutoSurface surfaceWindow(ps.hdc, this); - if (surfaceWindow) { - Paint(surfaceWindow, rcPaint); - surfaceWindow->Release(); - } - } else { -#if defined(USE_D2D) - EnsureRenderTarget(ps.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(); - paintState = paintAbandoned; - } - } -#endif + if (!PaintDC(ps.hdc)) { + paintState = paintAbandoned; } if (hRgnUpdate) { ::DeleteRgn(hRgnUpdate); @@ -2994,27 +3006,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; } |