Small optimizations in distance-field cache.
authorYoann Lopes <yoann.lopes@nokia.com>
Tue, 24 May 2011 09:43:17 +0000 (11:43 +0200)
committerYoann Lopes <yoann.lopes@nokia.com>
Tue, 24 May 2011 09:43:17 +0000 (11:43 +0200)
src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
src/declarative/scenegraph/qsgdistancefieldglyphcache_p.h

index 27da408..50c946a 100644 (file)
@@ -632,12 +632,13 @@ QSGDistanceFieldGlyphCache::Metrics QSGDistanceFieldGlyphCache::glyphMetrics(gly
     QHash<glyph_t, Metrics>::iterator metric = m_metrics.find(glyph);
     if (metric == m_metrics.end()) {
         QPainterPath path = m_font.pathForGlyph(glyph);
+        QRectF br = path.boundingRect();
 
         Metrics m;
-        m.width = path.boundingRect().width();
-        m.height = path.boundingRect().height();
-        m.baselineX = path.boundingRect().x();
-        m.baselineY = -path.boundingRect().y();
+        m.width = br.width();
+        m.height = br.height();
+        m.baselineX = br.x();
+        m.baselineY = -br.y();
 
         metric = m_metrics.insert(glyph, m);
     }
@@ -706,14 +707,15 @@ void QSGDistanceFieldGlyphCache::populate(int count, const glyph_t *glyphs)
             m_textureData->texCoords.insert(glyphIndex, TexCoord());
             continue;
         }
+        QRectF br = path.boundingRect();
 
         TexCoord c;
         c.xMargin = QT_DISTANCEFIELD_RADIUS / qreal(QT_DISTANCEFIELD_SCALE);
         c.yMargin = QT_DISTANCEFIELD_RADIUS / qreal(QT_DISTANCEFIELD_SCALE);
         c.x = m_textureData->currX;
         c.y = m_textureData->currY;
-        c.width = path.boundingRect().width();
-        c.height = path.boundingRect().height();
+        c.width = br.width();
+        c.height = br.height();
 
         if (!cacheIsFull()) {
             m_textureData->currX += QT_DISTANCEFIELD_TILESIZE;
@@ -735,7 +737,7 @@ void QSGDistanceFieldGlyphCache::populate(int count, const glyph_t *glyphs)
 
         if (c.y < maxTextureSize()) {
             m_textureData->texCoords.insert(glyphIndex, c);
-            m_textureData->pendingGlyphs.insert(glyphIndex);
+            m_textureData->pendingGlyphs.add(glyphIndex);
         }
     }
 }
@@ -914,10 +916,10 @@ void QSGDistanceFieldGlyphCache::updateCache()
     resizeTexture((requiredWidth), (requiredHeight));
     glBindTexture(GL_TEXTURE_2D, m_textureData->texture);
 
-    QSet<glyph_t>::const_iterator i = m_textureData->pendingGlyphs.constBegin();
-    for (; i != m_textureData->pendingGlyphs.constEnd(); ++i) {
-        QImage glyph = renderDistanceFieldGlyph(*i);
-        TexCoord c = m_textureData->texCoords.value(*i);
+    for (int i = 0; i < m_textureData->pendingGlyphs.size(); ++i) {
+        glyph_t glyphIndex = m_textureData->pendingGlyphs.at(i);
+        QImage glyph = renderDistanceFieldGlyph(glyphIndex);
+        TexCoord c = m_textureData->texCoords.value(glyphIndex);
 
         if (ctx->d_ptr->workaround_brokenFBOReadBack) {
             QPainter p(&m_textureData->image);
@@ -929,7 +931,7 @@ void QSGDistanceFieldGlyphCache::updateCache()
         convert_to_Format_Alpha(&glyph);
         glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, glyph.width(), glyph.height(), GL_ALPHA, GL_UNSIGNED_BYTE, glyph.constBits());
     }
-    m_textureData->pendingGlyphs.clear();
+    m_textureData->pendingGlyphs.reset();
 }
 
 bool QSGDistanceFieldGlyphCache::useWorkaroundBrokenFBOReadback() const
index 5ee4395..f7e2d93 100644 (file)
@@ -47,6 +47,7 @@
 #include <private/qgl_p.h>
 #include <private/qfont_p.h>
 #include <private/qfontengine_p.h>
+#include <QtGui/private/qdatabuffer_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -126,7 +127,7 @@ private:
         GLuint fbo;
         QSize size;
         QHash<glyph_t, TexCoord> texCoords;
-        QSet<glyph_t> pendingGlyphs;
+        QDataBuffer<glyph_t> pendingGlyphs;
         QHash<glyph_t, quint32> glyphRefCount;
         QSet<glyph_t> unusedGlyphs;
         int currX;
@@ -137,6 +138,7 @@ private:
         DistanceFieldTextureData(const QGLContext *)
             : texture(0)
             , fbo(0)
+            , pendingGlyphs(64)
             , currX(0)
             , currY(0)
             , doubleGlyphResolution(false)