diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2016-12-15 02:47:13 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2016-12-16 04:32:22 +0000 |
commit | 9cf20b5f0473db0b4dd2dcf607b7884f40762995 (patch) | |
tree | 59e94b312922e73c242c332b0e59069e7c45bb24 /vcl/win/gdi | |
parent | a7bd6830e26d798068970684754fa23894d9f7c2 (diff) |
tdf#104159: Re-enable OpenGL glyph caching on Windows
Change-Id: Icafec05a8cf4428d806efcb286addf3042fcf021
Reviewed-on: https://gerrit.libreoffice.org/32026
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Khaled Hosny <khaledhosny@eglug.org>
Diffstat (limited to 'vcl/win/gdi')
-rw-r--r-- | vcl/win/gdi/winlayout.cxx | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx index d0d96157e246..1f31cfa1df15 100644 --- a/vcl/win/gdi/winlayout.cxx +++ b/vcl/win/gdi/winlayout.cxx @@ -666,6 +666,70 @@ LogicalFontInstance* WinFontFace::CreateFontInstance( FontSelectPattern& rFSD ) return pFontInstance; } +bool WinSalGraphics::CacheGlyphs(const CommonSalLayout& rLayout) +{ + static bool bDoGlyphCaching = (std::getenv("SAL_DISABLE_GLYPH_CACHING") == nullptr); + if (!bDoGlyphCaching) + return false; + + HDC hDC = getHDC(); + HFONT hFONT = rLayout.getHFONT(); + WinFontInstance& rFont = rLayout.getWinFontInstance(); + + int nStart = 0; + Point aPos(0, 0); + const GlyphItem* pGlyph; + while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart)) + { + if (!rFont.GetGlyphCache().IsGlyphCached(pGlyph->maGlyphId)) + { + if (!rFont.CacheGlyphToAtlas(hDC, hFONT, pGlyph->maGlyphId, *this)) + return false; + } + } + + return true; +} + +bool WinSalGraphics::DrawCachedGlyphs(const CommonSalLayout& rLayout) +{ + HDC hDC = getHDC(); + + Rectangle aRect; + rLayout.GetBoundRect(*this, aRect); + + COLORREF color = GetTextColor(hDC); + SalColor salColor = MAKE_SALCOLOR(GetRValue(color), GetGValue(color), GetBValue(color)); + + WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get()); + if (!pImpl) + return false; + + WinFontInstance& rFont = rLayout.getWinFontInstance(); + + int nStart = 0; + Point aPos(0, 0); + const GlyphItem* pGlyph; + while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart)) + { + OpenGLGlyphDrawElement& rElement(rFont.GetGlyphCache().GetDrawElement(pGlyph->maGlyphId)); + OpenGLTexture& rTexture = rElement.maTexture; + + if (!rTexture) + return false; + + SalTwoRect a2Rects(0, 0, + rTexture.GetWidth(), rTexture.GetHeight(), + aPos.X() - rElement.getExtraOffset() + rElement.maLeftOverhangs, + aPos.Y() - rElement.mnBaselineOffset - rElement.getExtraOffset(), + rTexture.GetWidth(), rTexture.GetHeight()); + + pImpl->DeferredTextDraw(rTexture, salColor, a2Rects); + } + + return true; +} + void WinSalGraphics::DrawTextLayout(const CommonSalLayout& rLayout, HDC hDC, bool bUseDWrite) { Point aPos(0, 0); @@ -684,6 +748,11 @@ void WinSalGraphics::DrawTextLayout(const CommonSalLayout& rLayout) // no OpenGL, just classic rendering DrawTextLayout(rLayout, hDC, false); } + else if (CacheGlyphs(rLayout) && + DrawCachedGlyphs(rLayout)) + { + // Nothing + } else { // We have to render the text to a hidden texture, and draw it. |