From e109b8a0f3c89c595f0da689e7ee847130e2ee47 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 10 Dec 2015 08:35:14 +0100 Subject: [PATCH] Decrease the cache if necessary when adding a new font It was possible for the cache to increase too quickly since it was relying on the timer to decrease which caused problems with FreeType. So by checking if it will be increased to be over the limit first before adding the new font, we can decrease it earlier in preparation. Task-number: QTBUG-47812 Task-number: QTBUG-49535 Change-Id: Iedc042d8903949140aa8c5257a9d54cde31a51be Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfont.cpp | 12 +++++++++++- src/gui/text/qfont_p.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 3c6709e685..16550c0b3c 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -2793,6 +2793,10 @@ void QFontCache::insertEngineData(const QFontDef &def, QFontEngineData *engineDa Q_ASSERT(!engineDataCache.contains(def)); engineData->ref.ref(); + // Decrease now rather than waiting + if (total_cost > min_cost * 2) + decreaseCache(); + engineDataCache.insert(def, engineData); increaseCost(sizeof(QFontEngineData)); } @@ -2830,8 +2834,10 @@ void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMu key.def.pixelSize, key.def.weight, key.def.style, key.def.fixedPitch); } #endif - engine->ref.ref(); + // Decrease now rather than waiting + if (total_cost > min_cost * 2) + decreaseCache(); Engine data(engine); data.timestamp = ++current_timestamp; @@ -2892,7 +2898,11 @@ void QFontCache::timerEvent(QTimerEvent *) return; } + decreaseCache(); +} +void QFontCache::decreaseCache() +{ // go through the cache and count up everything in use uint in_use_cost = 0; diff --git a/src/gui/text/qfont_p.h b/src/gui/text/qfont_p.h index 25b5ef0b0e..ff9265ca19 100644 --- a/src/gui/text/qfont_p.h +++ b/src/gui/text/qfont_p.h @@ -276,6 +276,7 @@ private: void increaseCost(uint cost); void decreaseCost(uint cost); void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; + void decreaseCache(); static const uint min_cost; uint total_cost, max_cost;