diff options
author | Andreas Kling <andreas.kling@nokia.com> | 2010-03-05 14:12:18 +0100 |
---|---|---|
committer | Andreas Kling <andreas.kling@nokia.com> | 2010-03-05 16:30:54 +0100 |
commit | 56c9bd9a4c03418ad0ba83b576bcc278e86bfe99 (patch) | |
tree | d9a1046f44a4b3083a4862c0dbd9db877d06c8b2 /src/gui | |
parent | 1fdaff30cde418a858170547e9d3c514617ba366 (diff) | |
download | qt4-tools-56c9bd9a4c03418ad0ba83b576bcc278e86bfe99.tar.gz |
FreeType: Fast lookup of Latin-1 glyphs
Store all glyphs with index < 256 in a pointer array for fast lookup
Reviewed-by: Benjamin Poulain
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qpaintengine_raster.cpp | 2 | ||||
-rw-r--r-- | src/gui/painting/qtextureglyphcache.cpp | 2 | ||||
-rw-r--r-- | src/gui/text/qfontengine_ft.cpp | 70 | ||||
-rw-r--r-- | src/gui/text/qfontengine_ft_p.h | 16 |
4 files changed, 72 insertions, 18 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index a7c2a0b3c3..bfcf7dbd19 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -3390,7 +3390,7 @@ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte }; for(int i = 0; i < glyphs.size(); i++) { - QFontEngineFT::Glyph *glyph = gset->glyph_data.value(glyphs[i]); + QFontEngineFT::Glyph *glyph = gset->getGlyph(glyphs[i]); if (!glyph || glyph->format != neededFormat) { if (!lockedFace) diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index cf3957b5c4..4418018492 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -195,7 +195,7 @@ QImage QTextureGlyphCache::textureMapForGlyph(glyph_t g) const QFontEngineFT::QGlyphSet *gset = ft->loadTransformedGlyphSet(m_transform); if (gset && ft->loadGlyphs(gset, &g, 1, format)) { - QFontEngineFT::Glyph *glyph = gset->glyph_data.value(g); + QFontEngineFT::Glyph *glyph = gset->getGlyph(g); const int bytesPerLine = (format == QFontEngineFT::Format_Mono ? ((glyph->width + 31) & ~31) >> 3 : (glyph->width + 3) & ~3); return QImage(glyph->data, glyph->width, glyph->height, bytesPerLine, imageFormat); diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 17ade64004..6b40aadf08 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -746,7 +746,7 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format) QFontEngineFT::Glyph *QFontEngineFT::loadGlyphMetrics(QGlyphSet *set, uint glyph) const { - Glyph *g = set->glyph_data.value(glyph); + Glyph *g = set->getGlyph(glyph); if (g) return g; @@ -858,10 +858,10 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph } } - Glyph *g = set->glyph_data.value(glyph); + Glyph *g = set->getGlyph(glyph); if (g && g->format == format) { if (uploadToServer && !g->uploadedToServer) { - set->glyph_data[glyph] = 0; + set->setGlyph(glyph, 0); delete g; g = 0; } else { @@ -1158,7 +1158,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph uploadGlyphToServer(set, glyph, g, &info, glyph_buffer_size); } - set->glyph_data[glyph] = g; + set->setGlyph(glyph, g); return g; } @@ -1381,8 +1381,7 @@ QFontEngineFT::QGlyphSet *QFontEngineFT::loadTransformedGlyphSet(const QTransfor } gs = &transformedGlyphSets[0]; - qDeleteAll(gs->glyph_data); - gs->glyph_data.clear(); + gs->clear(); gs->id = allocateServerGlyphSet(); @@ -1398,7 +1397,7 @@ bool QFontEngineFT::loadGlyphs(QGlyphSet *gs, glyph_t *glyphs, int num_glyphs, G FT_Face face = 0; for (int i = 0; i < num_glyphs; ++i) { - Glyph *glyph = gs->glyph_data.value(glyphs[i]); + Glyph *glyph = gs->getGlyph(glyphs[i]); if (glyph == 0 || glyph->format != format) { if (!face) { face = lockFace(); @@ -1635,7 +1634,7 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlag FT_Face face = 0; if (flags & QTextEngine::DesignMetrics) { for (int i = 0; i < glyphs->numGlyphs; i++) { - Glyph *g = defaultGlyphSet.glyph_data.value(glyphs->glyphs[i]); + Glyph *g = defaultGlyphSet.getGlyph(glyphs->glyphs[i]); if (g) { glyphs->advances_x[i] = QFixed::fromFixed(g->linearAdvance); } else { @@ -1648,7 +1647,7 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlag } } else { for (int i = 0; i < glyphs->numGlyphs; i++) { - Glyph *g = defaultGlyphSet.glyph_data.value(glyphs->glyphs[i]); + Glyph *g = defaultGlyphSet.getGlyph(glyphs->glyphs[i]); if (g) { glyphs->advances_x[i] = QFixed(g->advance); } else { @@ -1677,7 +1676,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(const QGlyphLayout &glyphs) QFixed ymax = 0; QFixed xmax = 0; for (int i = 0; i < glyphs.numGlyphs; i++) { - Glyph *g = defaultGlyphSet.glyph_data.value(glyphs.glyphs[i]); + Glyph *g = defaultGlyphSet.getGlyph(glyphs.glyphs[i]); if (!g) { if (!face) face = lockFace(); @@ -1719,7 +1718,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph) { FT_Face face = 0; glyph_metrics_t overall; - Glyph *g = defaultGlyphSet.glyph_data.value(glyph); + Glyph *g = defaultGlyphSet.getGlyph(glyph); if (!g) { face = lockFace(); g = loadGlyph(glyph, Format_None, true); @@ -1783,8 +1782,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph, const QTransform &matr transformedGlyphSets.prepend(QGlyphSet()); } glyphSet = &transformedGlyphSets[0]; - qDeleteAll(glyphSet->glyph_data); - glyphSet->glyph_data.clear(); + glyphSet->clear(); glyphSet->id = allocateServerGlyphSet(); glyphSet->transformationMatrix = m; } @@ -1792,7 +1790,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph, const QTransform &matr } else { glyphSet = &defaultGlyphSet; } - Glyph * g = glyphSet->glyph_data.value(glyph); + Glyph * g = glyphSet->getGlyph(glyph); if (!g) { face = lockFace(); g = loadGlyphMetrics(glyphSet, glyph); @@ -1881,7 +1879,7 @@ QImage QFontEngineFT::alphaRGBMapForGlyph(glyph_t g, int margin, const QTransfor void QFontEngineFT::removeGlyphFromCache(glyph_t glyph) { - delete defaultGlyphSet.glyph_data.take(glyph); + defaultGlyphSet.removeGlyphFromCache(glyph); } int QFontEngineFT::glyphCount() const @@ -1937,11 +1935,53 @@ QFontEngineFT::QGlyphSet::QGlyphSet() transformationMatrix.yy = 0x10000; transformationMatrix.xy = 0; transformationMatrix.yx = 0; + memset(fast_glyph_data, 0, sizeof(fast_glyph_data)); + fast_glyph_count = 0; } QFontEngineFT::QGlyphSet::~QGlyphSet() { + clear(); +} + +void QFontEngineFT::QGlyphSet::clear() +{ + if (fast_glyph_count > 0) { + for (int i = 0; i < 256; ++i) { + if (fast_glyph_data[i]) { + delete fast_glyph_data[i]; + fast_glyph_data[i] = 0; + } + } + fast_glyph_count = 0; + } qDeleteAll(glyph_data); + glyph_data.clear(); +} + +void QFontEngineFT::QGlyphSet::removeGlyphFromCache(int index) +{ + if (index < 256) { + if (fast_glyph_data[index]) { + delete fast_glyph_data[index]; + fast_glyph_data[index] = 0; + if (fast_glyph_count > 0) + --fast_glyph_count; + } + } else { + delete glyph_data.take(index); + } +} + +void QFontEngineFT::QGlyphSet::setGlyph(int index, Glyph *glyph) +{ + if (index < 256) { + if (!fast_glyph_data[index]) + ++fast_glyph_count; + fast_glyph_data[index] = glyph; + } else { + glyph_data.insert(index, glyph); + } } unsigned long QFontEngineFT::allocateServerGlyphSet() diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h index 98dd002719..12b7da86a1 100644 --- a/src/gui/text/qfontengine_ft_p.h +++ b/src/gui/text/qfontengine_ft_p.h @@ -180,7 +180,21 @@ public: FT_Matrix transformationMatrix; unsigned long id; // server sided id, GlyphSet for X11 bool outline_drawing; + + void removeGlyphFromCache(int index); + void clear(); + inline Glyph *getGlyph(int index) const + { + if (index < 256) + return fast_glyph_data[index]; + return glyph_data.value(index); + } + void setGlyph(int index, Glyph *glyph); + +private: mutable QHash<int, Glyph *> glyph_data; // maps from glyph index to glyph data + mutable Glyph *fast_glyph_data[256]; // for fast lookup of glyphs < 256 + mutable int fast_glyph_count; }; virtual QFontEngine::FaceId faceId() const; @@ -252,7 +266,7 @@ public: QGlyphSet *defaultGlyphs() { return &defaultGlyphSet; } GlyphFormat defaultGlyphFormat() const { return defaultFormat; } - inline Glyph *cachedGlyph(glyph_t g) const { return defaultGlyphSet.glyph_data.value(g); } + inline Glyph *cachedGlyph(glyph_t g) const { return defaultGlyphSet.getGlyph(g); } QGlyphSet *loadTransformedGlyphSet(const QTransform &matrix); bool loadGlyphs(QGlyphSet *gs, glyph_t *glyphs, int num_glyphs, GlyphFormat format = Format_Render); |