QFontCache: Centralize the engine type safety check

We depend on the assumption QFontCache::findEngine(key) for key.multi=1
returns a font engine of type QFontEngine::Multi;
guarantee that by checking it in a single place.

Change-Id: I287da4fd62deb22fc5520cde5b0505bc44547609
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
bb10
Konstantin Ritt 2016-01-25 09:46:55 +04:00
parent 0f27d11285
commit 5f472cae71
3 changed files with 9 additions and 4 deletions

View File

@ -2809,6 +2809,10 @@ QFontEngine *QFontCache::findEngine(const Key &key)
EngineCache::Iterator it = engineCache.find(key),
end = engineCache.end();
if (it == end) return 0;
Q_ASSERT(it.value().data != Q_NULLPTR);
Q_ASSERT(key.multi == (it.value().data->type() == QFontEngine::Multi));
// found... update the hitcount and timestamp
updateHitCountAndTimeStamp(it.value());
@ -2829,6 +2833,9 @@ void QFontCache::updateHitCountAndTimeStamp(Engine &value)
void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMulti)
{
Q_ASSERT(engine != Q_NULLPTR);
Q_ASSERT(key.multi == (engine->type() == QFontEngine::Multi));
#ifdef QFONTCACHE_DEBUG
FC_DEBUG("QFontCache: inserting new engine %p, refcount %d", engine, engine->ref.load());
if (!insertMulti && engineCache.contains(key)) {

View File

@ -935,7 +935,6 @@ QFontEngine *loadSingleEngine(int script,
engine = fontCache->findEngine(key);
key.script = script;
if (engine) {
Q_ASSERT(engine->type() != QFontEngine::Multi);
// Also check for OpenType tables when using complex scripts
if (Q_UNLIKELY(!engine->supportsScript(QChar::Script(script)))) {
qWarning(" OpenType support missing for script %d", script);
@ -958,7 +957,6 @@ QFontEngine *loadSingleEngine(int script,
engine = pfdb->fontEngine(def, size->handle);
if (engine) {
Q_ASSERT(engine->type() != QFontEngine::Multi);
// Also check for OpenType tables when using complex scripts
if (!engine->supportsScript(QChar::Script(script))) {
qWarning(" OpenType support missing for script %d", script);
@ -986,7 +984,7 @@ QFontEngine *loadEngine(int script, const QFontDef &request,
QtFontStyle *style, QtFontSize *size)
{
QFontEngine *engine = loadSingleEngine(script, request, family, foundry, style, size);
Q_ASSERT(!engine || engine->type() != QFontEngine::Multi);
if (engine && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol) {
QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase();
QFontEngineMulti *pfMultiEngine = pfdb->fontEngineMulti(engine, QChar::Script(script));

View File

@ -110,7 +110,7 @@ void tst_QFontCache::clear()
fontEngine->ref.ref();
// cache the engine once again; there is a special case when the engine is cached more than once
QFontCache::instance()->insertEngine(QFontCache::Key(QFontDef(), 0, 0), fontEngine);
QFontCache::instance()->insertEngine(QFontCache::Key(QFontDef(), 0, 1), fontEngine);
}
// use it: