Kaydet (Commit) 9cf20b5f authored tarafından Khaled Hosny's avatar Khaled Hosny

tdf#104159: Re-enable OpenGL glyph caching on Windows

Change-Id: Icafec05a8cf4428d806efcb286addf3042fcf021
Reviewed-on: https://gerrit.libreoffice.org/32026Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarKhaled Hosny <khaledhosny@eglug.org>
üst a7bd6830
...@@ -45,6 +45,7 @@ class CommonSalLayout : public GenericSalLayout ...@@ -45,6 +45,7 @@ class CommonSalLayout : public GenericSalLayout
#ifdef _WIN32 #ifdef _WIN32
HDC mhDC; HDC mhDC;
HFONT mhFont; HFONT mhFont;
WinFontInstance& mrWinFontInstance;
double mnAveWidthFactor; double mnAveWidthFactor;
#elif defined(MACOSX) || defined(IOS) #elif defined(MACOSX) || defined(IOS)
const CoreTextStyle& mrCoreTextStyle; const CoreTextStyle& mrCoreTextStyle;
...@@ -67,6 +68,8 @@ public: ...@@ -67,6 +68,8 @@ public:
#if defined(_WIN32) #if defined(_WIN32)
explicit CommonSalLayout(HDC, WinFontInstance&, const WinFontFace&); explicit CommonSalLayout(HDC, WinFontInstance&, const WinFontFace&);
const FontSelectPattern& getFontSelData() const { return mrFontSelData; }; const FontSelectPattern& getFontSelData() const { return mrFontSelData; };
HFONT getHFONT() const { return mhFont; }
WinFontInstance& getWinFontInstance() const { return mrWinFontInstance; }
#elif defined(MACOSX) || defined(IOS) #elif defined(MACOSX) || defined(IOS)
explicit CommonSalLayout(const CoreTextStyle&); explicit CommonSalLayout(const CoreTextStyle&);
const CoreTextStyle& getFontData() const { return mrCoreTextStyle; }; const CoreTextStyle& getFontData() const { return mrCoreTextStyle; };
......
...@@ -180,6 +180,9 @@ private: ...@@ -180,6 +180,9 @@ private:
LogicalFontInstance* GetWinFontEntry(int nFallbackLevel); LogicalFontInstance* GetWinFontEntry(int nFallbackLevel);
bool CacheGlyphs(const CommonSalLayout& rLayout);
bool DrawCachedGlyphs(const CommonSalLayout& rLayout);
public: public:
HDC getHDC() const { return mhLocalDC; } HDC getHDC() const { return mhLocalDC; }
void setHDC(HDC aNew) { mhLocalDC = aNew; } void setHDC(HDC aNew) { mhLocalDC = aNew; }
......
...@@ -181,6 +181,7 @@ CommonSalLayout::CommonSalLayout(HDC hDC, WinFontInstance& rWinFontInstance, con ...@@ -181,6 +181,7 @@ CommonSalLayout::CommonSalLayout(HDC hDC, WinFontInstance& rWinFontInstance, con
: mrFontSelData(rWinFontInstance.maFontSelData) : mrFontSelData(rWinFontInstance.maFontSelData)
, mhDC(hDC) , mhDC(hDC)
, mhFont(static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT))) , mhFont(static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT)))
, mrWinFontInstance(rWinFontInstance)
, mnAveWidthFactor(1.0f) , mnAveWidthFactor(1.0f)
, mpVertGlyphs(nullptr) , mpVertGlyphs(nullptr)
{ {
......
...@@ -666,6 +666,70 @@ LogicalFontInstance* WinFontFace::CreateFontInstance( FontSelectPattern& rFSD ) ...@@ -666,6 +666,70 @@ LogicalFontInstance* WinFontFace::CreateFontInstance( FontSelectPattern& rFSD )
return pFontInstance; 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) void WinSalGraphics::DrawTextLayout(const CommonSalLayout& rLayout, HDC hDC, bool bUseDWrite)
{ {
Point aPos(0, 0); Point aPos(0, 0);
...@@ -684,6 +748,11 @@ void WinSalGraphics::DrawTextLayout(const CommonSalLayout& rLayout) ...@@ -684,6 +748,11 @@ void WinSalGraphics::DrawTextLayout(const CommonSalLayout& rLayout)
// no OpenGL, just classic rendering // no OpenGL, just classic rendering
DrawTextLayout(rLayout, hDC, false); DrawTextLayout(rLayout, hDC, false);
} }
else if (CacheGlyphs(rLayout) &&
DrawCachedGlyphs(rLayout))
{
// Nothing
}
else else
{ {
// We have to render the text to a hidden texture, and draw it. // We have to render the text to a hidden texture, and draw it.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment