aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/scenegraph
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@nokia.com>2011-05-24 11:43:17 +0200
committerYoann Lopes <yoann.lopes@nokia.com>2011-05-24 11:43:17 +0200
commit2d69163a2819f72c5b18c5dd483976a54c797b81 (patch)
tree9c26f99fee00cc0d427fcab0e298f7cb4f94c56f /src/declarative/scenegraph
parent780097f270c40814691459396661ebed90285ab8 (diff)
Small optimizations in distance-field cache.
Diffstat (limited to 'src/declarative/scenegraph')
-rw-r--r--src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp26
-rw-r--r--src/declarative/scenegraph/qsgdistancefieldglyphcache_p.h4
2 files changed, 17 insertions, 13 deletions
diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp b/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
index 27da408d65..50c946a849 100644
--- a/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
+++ b/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
@@ -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
diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphcache_p.h b/src/declarative/scenegraph/qsgdistancefieldglyphcache_p.h
index 5ee439552a..f7e2d9367e 100644
--- a/src/declarative/scenegraph/qsgdistancefieldglyphcache_p.h
+++ b/src/declarative/scenegraph/qsgdistancefieldglyphcache_p.h
@@ -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)