diff options
author | Andy Shaw <andy.shaw@digia.com> | 2015-12-10 08:35:14 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@theqtcompany.com> | 2015-12-16 13:13:02 +0000 |
commit | e109b8a0f3c89c595f0da689e7ee847130e2ee47 (patch) | |
tree | f96fe350e1e915257e518e3f763340f4ee719aaa /src | |
parent | 3fb0d851a08b7912152f98096c7308b3c430e605 (diff) |
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 <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qfont.cpp | 12 | ||||
-rw-r--r-- | src/gui/text/qfont_p.h | 1 |
2 files changed, 12 insertions, 1 deletions
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; |