[Libreoffice-commits] core.git: vcl/inc vcl/source vcl/win
Khaled Hosny
khaledhosny at eglug.org
Fri Dec 16 04:32:58 UTC 2016
vcl/inc/CommonSalLayout.hxx | 3 +
vcl/inc/win/salgdi.h | 3 +
vcl/source/gdi/CommonSalLayout.cxx | 1
vcl/win/gdi/winlayout.cxx | 69 +++++++++++++++++++++++++++++++++++++
4 files changed, 76 insertions(+)
New commits:
commit 9cf20b5f0473db0b4dd2dcf607b7884f40762995
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Thu Dec 15 02:47:13 2016 +0200
tdf#104159: Re-enable OpenGL glyph caching on Windows
Change-Id: Icafec05a8cf4428d806efcb286addf3042fcf021
Reviewed-on: https://gerrit.libreoffice.org/32026
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Khaled Hosny <khaledhosny at eglug.org>
diff --git a/vcl/inc/CommonSalLayout.hxx b/vcl/inc/CommonSalLayout.hxx
index 05ea342..b0c9381 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 8a493d7..65cf06f 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 2c059ef..d68534f 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 d0d9615..1f31cfa 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.
More information about the Libreoffice-commits
mailing list