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 | |
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')
-rw-r--r-- | vcl/inc/CommonSalLayout.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/win/salgdi.h | 3 | ||||
-rw-r--r-- | vcl/source/gdi/CommonSalLayout.cxx | 1 | ||||
-rw-r--r-- | vcl/win/gdi/winlayout.cxx | 69 |
4 files changed, 76 insertions, 0 deletions
diff --git a/vcl/inc/CommonSalLayout.hxx b/vcl/inc/CommonSalLayout.hxx index 05ea342d5b82..b0c9381defea 100644 --- a/vcl/inc/CommonSalLayout.hxx +++ b/vcl/inc/CommonSalLayout.hxx @@ -45,6 +45,7 @@ class CommonSalLayout : public GenericSalLayout #ifdef _WIN32 HDC mhDC; HFONT mhFont; + WinFontInstance& mrWinFontInstance; double mnAveWidthFactor; #elif defined(MACOSX) || defined(IOS) const CoreTextStyle& mrCoreTextStyle; @@ -67,6 +68,8 @@ public: #if defined(_WIN32) explicit CommonSalLayout(HDC, WinFontInstance&, const WinFontFace&); const FontSelectPattern& getFontSelData() const { return mrFontSelData; }; + HFONT getHFONT() const { return mhFont; } + WinFontInstance& getWinFontInstance() const { return mrWinFontInstance; } #elif defined(MACOSX) || defined(IOS) explicit CommonSalLayout(const CoreTextStyle&); const CoreTextStyle& getFontData() const { return mrCoreTextStyle; }; diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h index 8a493d7dc72b..65cf06f202f4 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -180,6 +180,9 @@ private: LogicalFontInstance* GetWinFontEntry(int nFallbackLevel); + bool CacheGlyphs(const CommonSalLayout& rLayout); + bool DrawCachedGlyphs(const CommonSalLayout& rLayout); + public: HDC getHDC() const { return mhLocalDC; } void setHDC(HDC aNew) { mhLocalDC = aNew; } diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx index 2c059ef119b1..d68534fcedce 100644 --- a/vcl/source/gdi/CommonSalLayout.cxx +++ b/vcl/source/gdi/CommonSalLayout.cxx @@ -181,6 +181,7 @@ CommonSalLayout::CommonSalLayout(HDC hDC, WinFontInstance& rWinFontInstance, con : mrFontSelData(rWinFontInstance.maFontSelData) , mhDC(hDC) , mhFont(static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT))) +, mrWinFontInstance(rWinFontInstance) , mnAveWidthFactor(1.0f) , mpVertGlyphs(nullptr) { 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. |