summaryrefslogtreecommitdiff
path: root/vcl/win
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-10-19 09:45:54 +0000
committerJan-Marek Glogowski <glogow@fbihome.de>2018-10-19 22:53:46 +0200
commit792d07c7f2816f1afdbed1d0b8129e3f1aecf8d7 (patch)
tree50a6cbe66e9bb082828a035a30c86bbec53ba29d /vcl/win
parentd20c39d1b07a2c55de442cb4e0859fbb939af78b (diff)
WIN fix CacheGlyphToAtlas resource handling
Use :comphelper::ScopeGuard to handle cleanup. And actually restore the original font on the correct DC. Change-Id: Ib59d430636b470486da2f8e5e34ed8d71b57aac2 Reviewed-on: https://gerrit.libreoffice.org/62010 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/win')
-rw-r--r--vcl/win/gdi/winlayout.cxx23
1 files changed, 10 insertions, 13 deletions
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 35303fc5c8a5..efbbd0c1edb3 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -23,6 +23,7 @@
#include <sal/log.hxx>
#include <comphelper/windowserrorstring.hxx>
+#include <comphelper/scopeguard.hxx>
#include <opengl/texture.hxx>
#include <opengl/win/gdiimpl.hxx>
@@ -48,11 +49,11 @@
#include <shlwapi.h>
#include <winver.h>
-GlobalOpenGLGlyphCache * GlobalOpenGLGlyphCache::get() {
- SalData * data = GetSalData();
- if (!data->m_pGlobalOpenGLGlyphCache) {
+GlobalOpenGLGlyphCache * GlobalOpenGLGlyphCache::get()
+{
+ SalData *data = GetSalData();
+ if (!data->m_pGlobalOpenGLGlyphCache)
data->m_pGlobalOpenGLGlyphCache.reset(new GlobalOpenGLGlyphCache);
- }
return data->m_pGlobalOpenGLGlyphCache.get();
}
@@ -67,12 +68,15 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, S
SAL_WARN("vcl.gdi", "CreateCompatibleDC failed: " << WindowsErrorString(GetLastError()));
return false;
}
- HFONT hOrigFont = static_cast<HFONT>(SelectObject(aHDC.get(), hFont));
+
+ const HFONT hOrigFont = static_cast<HFONT>(SelectObject(aHDC.get(), hFont));
if (hOrigFont == nullptr)
{
SAL_WARN("vcl.gdi", "SelectObject failed: " << WindowsErrorString(GetLastError()));
return false;
}
+ const ::comphelper::ScopeGuard aHFONTrestoreScopeGuard(
+ [&aHDC,hOrigFont]() { SelectFont(aHDC.get(), hOrigFont); });
// For now we assume DWrite is present and we won't bother with fallback paths.
D2DWriteTextOutRenderer * pTxt = dynamic_cast<D2DWriteTextOutRenderer *>(&TextOutRenderer::get(true));
@@ -86,6 +90,7 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, S
SAL_WARN("vcl.gdi", "Binding of font failed. The font might not be supported by DirectWrite.");
return false;
}
+ const ::comphelper::ScopeGuard aFontReleaseScopeGuard([&pTxt]() { pTxt->ReleaseFont(); });
std::vector<WORD> aGlyphIndices(1);
aGlyphIndices[0] = nGlyphIndex;
@@ -158,10 +163,7 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, S
ID2D1SolidColorBrush* pBrush = nullptr;
if (!SUCCEEDED(pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &pBrush)))
- {
- pTxt->ReleaseFont();
return false;
- }
D2D1_POINT_2F baseline = {
static_cast<FLOAT>(aElement.getExtraOffset()),
@@ -194,12 +196,9 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, S
break;
default:
SAL_WARN("vcl.gdi", "DrawGlyphRun-EndDraw failed: " << WindowsErrorString(GetLastError()));
- SelectFont(aDC.getCompatibleHDC(), hOrigFont);
return false;
}
- pTxt->ReleaseFont();
-
if (!OpenGLGlyphCache::ReserveTextureSpace(aElement, nBitmapWidth, nBitmapHeight))
return false;
if (!aDC.copyToTexture(aElement.maTexture))
@@ -207,8 +206,6 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, S
maOpenGLGlyphCache.PutDrawElementInCache(aElement, nGlyphIndex);
- SelectFont(aDC.getCompatibleHDC(), hOrigFont);
-
return true;
}