Optimize distance-field glyph recycling.
authorYoann Lopes <yoann.lopes@nokia.com>
Mon, 23 May 2011 11:39:53 +0000 (13:39 +0200)
committerYoann Lopes <yoann.lopes@nokia.com>
Mon, 23 May 2011 11:46:01 +0000 (13:46 +0200)
Unused glyphs in the cache should not be overwritten if they are
immediatly reused after being unreferenced.

src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp

index a21fcce..27da408 100644 (file)
@@ -678,6 +678,15 @@ int QSGDistanceFieldGlyphCache::distanceFieldRadius() const
 
 void QSGDistanceFieldGlyphCache::populate(int count, const glyph_t *glyphs)
 {
+    // Avoid useless and costly glyph re-generation
+    if (cacheIsFull() && !m_textureData->unusedGlyphs.isEmpty()) {
+        for (int i = 0; i < count; ++i) {
+            glyph_t glyphIndex = glyphs[i];
+            if (m_textureData->texCoords.contains(glyphIndex) && m_textureData->unusedGlyphs.contains(glyphIndex))
+                m_textureData->unusedGlyphs.remove(glyphIndex);
+        }
+    }
+
     for (int i = 0; i < count; ++i) {
         glyph_t glyphIndex = glyphs[i];
         if ((int) glyphIndex >= glyphCount()) {