From 85178095ca75444e9a2834374e0a1807b01fb9ad Mon Sep 17 00:00:00 2001 From: vsonnier Date: Tue, 21 Jun 2016 21:05:17 +0200 Subject: [PATCH] Reset all font caches when font size changes --- src/util/GLFont.cpp | 21 ++++++++++++++------- src/util/GLFont.h | 5 ++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/util/GLFont.cpp b/src/util/GLFont.cpp index 4843b6c..220f9ca 100644 --- a/src/util/GLFont.cpp +++ b/src/util/GLFont.cpp @@ -793,7 +793,10 @@ void GLFont::doCacheGC() { } //end while } -void GLFont::flushGC() { +void GLFont::clearCache() { + + std::lock_guard lock(cache_busy); + std::map::iterator cache_iter; cache_iter = stringCache.begin(); @@ -806,6 +809,14 @@ void GLFont::flushGC() { } } +void GLFont::clearAllCaches() { + + for (int i = 0; i < GLFont::GLFONT_SIZE_MAX; i++) { + + fonts[i].clearCache(); + } +} + GLFont &GLFont::getFont(GLFontSize esize) { @@ -864,8 +875,6 @@ void GLFont::setScale(GLFontScale scale) { userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE48; userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE72; userFontZoomMapping[GLFont::GLFONT_SIZE64] = GLFont::GLFONT_SIZE96; - - } //Large : 2x normal, more or less else if (currentScaleFactor == GLFontScale::GLFONT_SCALE_LARGE) { @@ -880,10 +889,8 @@ void GLFont::setScale(GLFontScale scale) { userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE96; } - //Not overridden mapping stays normal, like the biggest fonts. - - //Note that there is no need to flush the GC, no longer used fonts will be purged auto-magically by aging, - //and the new fonts will show up. + //Flush all the GC stuff + clearAllCaches(); } GLFont::GLFontScale GLFont::getScale() { diff --git a/src/util/GLFont.h b/src/util/GLFont.h index ddbdc49..28f2363 100644 --- a/src/util/GLFont.h +++ b/src/util/GLFont.h @@ -137,7 +137,10 @@ private: void drawCacheString(GLFontStringCache *fc, float xpos, float ypos, Align hAlign, Align vAlign); void doCacheGC(); - void flushGC(); + void clearCache(); + + //force GC of all available fonts + static void clearAllCaches(); float getStringWidth(const std::wstring& str, float size, float viewAspect);