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>
This commit is contained in:
Andy Shaw 2015-12-10 08:35:14 +01:00 committed by Andy Shaw
parent 3fb0d851a0
commit e109b8a0f3
2 changed files with 12 additions and 1 deletions

View File

@ -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;

View File

@ -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;