summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2011-02-22 14:49:34 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2011-02-24 11:02:52 (GMT)
commit2a2e50befeb3414205377702dfb9fe082f213ede (patch)
treeade9ca9adee52a19197aea2ed92c30f9275e11fa
parent473ff22f9d84c407c5a2011defcf07f19527a056 (diff)
downloadQt-2a2e50befeb3414205377702dfb9fe082f213ede.zip
Qt-2a2e50befeb3414205377702dfb9fe082f213ede.tar.gz
Qt-2a2e50befeb3414205377702dfb9fe082f213ede.tar.bz2
Keep reference count for cached font engines in QTextEngine
So that if these font engines are deallocated elsewhere (by QFontCache for instance), we can still access them in QTextEngine. Task-number: QTBUG-17603 Reviewed-by: Eskil
-rw-r--r--src/gui/text/qtextengine.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 415fa4b..d2e8291 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1385,6 +1385,15 @@ void QTextEngine::shape(int item) const
}
}
+static inline void releaseCachedFontEngine(QFontEngine *fontEngine)
+{
+ if (fontEngine) {
+ fontEngine->ref.deref();
+ if (fontEngine->cache_count == 0 && fontEngine->ref == 0)
+ delete fontEngine;
+ }
+}
+
void QTextEngine::invalidate()
{
freeMemory();
@@ -1392,6 +1401,9 @@ void QTextEngine::invalidate()
maxWidth = 0;
if (specialData)
specialData->resolvedFormatIndices.clear();
+
+ releaseCachedFontEngine(feCache.prevFontEngine);
+ releaseCachedFontEngine(feCache.prevScaledFontEngine);
feCache.reset();
}
@@ -1824,7 +1836,9 @@ QFontEngine *QTextEngine::fontEngine(const QScriptItem &si, QFixed *ascent, QFix
scaledEngine = font.d->engineForScript(script);
}
feCache.prevFontEngine = engine;
+ engine->ref.ref();
feCache.prevScaledFontEngine = scaledEngine;
+ scaledEngine->ref.ref();
feCache.prevScript = script;
feCache.prevPosition = si.position;
feCache.prevLength = length(&si);
@@ -1835,6 +1849,7 @@ QFontEngine *QTextEngine::fontEngine(const QScriptItem &si, QFixed *ascent, QFix
else {
engine = font.d->engineForScript(script);
feCache.prevFontEngine = engine;
+ engine->ref.ref();
feCache.prevScript = script;
feCache.prevPosition = -1;
feCache.prevLength = -1;