summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2009-06-02 13:25:07 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2009-06-03 07:10:42 (GMT)
commitfa95af38594b09718b9eb9048b75b9628dc9a0da (patch)
tree81e0817af46beaaf9684127f32a3462faaa79c89 /src/gui/painting
parentd37de8e085bdc3ee5d0185b403879bac485ef834 (diff)
downloadQt-fa95af38594b09718b9eb9048b75b9628dc9a0da.zip
Qt-fa95af38594b09718b9eb9048b75b9628dc9a0da.tar.gz
Qt-fa95af38594b09718b9eb9048b75b9628dc9a0da.tar.bz2
Implemented QGLTextureGlyphCache to avoid wasting glyph cache memory.
Now there's only a copy of the texture glyph cache in graphics memory, avoiding the system memory copy that we used earlier. In addition the texture will use the GL_ALPHA texture format when possible, making it consume less graphics memory as well. Reviewed-by: Tom
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qtextureglyphcache.cpp69
-rw-r--r--src/gui/painting/qtextureglyphcache_p.h3
2 files changed, 43 insertions, 29 deletions
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp
index 89df869..6b195bf 100644
--- a/src/gui/painting/qtextureglyphcache.cpp
+++ b/src/gui/painting/qtextureglyphcache.cpp
@@ -157,6 +157,46 @@ void QTextureGlyphCache::populate(const QTextItemInt &ti,
}
+QImage QTextureGlyphCache::textureMapForGlyph(glyph_t g) const
+{
+#if defined(Q_WS_X11)
+ if (m_transform.type() > QTransform::TxTranslate) {
+ QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_None;
+ QImage::Format imageFormat = QImage::Format_Invalid;
+ switch (m_type) {
+ case Raster_RGBMask:
+ format = QFontEngineFT::Format_A32;
+ imageFormat = QImage::Format_RGB32;
+ break;
+ case Raster_A8:
+ format = QFontEngineFT::Format_A8;
+ imageFormat = QImage::Format_Indexed8;
+ break;
+ case Raster_Mono:
+ format = QFontEngineFT::Format_Mono;
+ imageFormat = QImage::Format_Mono;
+ break;
+ };
+
+ QFontEngineFT *ft = static_cast<QFontEngineFT*> (m_current_textitem->fontEngine);
+ QFontEngineFT::QGlyphSet *gset = ft->loadTransformedGlyphSet(m_transform);
+
+ if (gset && ft->loadGlyphs(gset, &g, 1, format)) {
+ QFontEngineFT::Glyph *glyph = gset->glyph_data.value(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);
+ }
+ } else
+#endif
+ if (m_type == QFontEngineGlyphCache::Raster_RGBMask)
+ return m_current_textitem->fontEngine->alphaRGBMapForGlyph(g, glyphMargin(), m_transform);
+ else
+ return m_current_textitem->fontEngine->alphaMapForGlyph(g, m_transform);
+
+ return QImage();
+}
+
/************************************************************************
* QImageTextureGlyphCache
*/
@@ -198,34 +238,7 @@ int QImageTextureGlyphCache::glyphMargin() const
void QImageTextureGlyphCache::fillTexture(const Coord &c, glyph_t g)
{
- QImage mask;
-#if defined(Q_WS_X11)
- if (m_transform.type() > QTransform::TxTranslate) {
- QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_None;
- switch (m_type) {
- case Raster_RGBMask:
- format = QFontEngineFT::Format_A32; break;
- case Raster_A8:
- format = QFontEngineFT::Format_A8; break;
- case Raster_Mono:
- format = QFontEngineFT::Format_Mono; break;
- };
-
- QFontEngineFT *ft = static_cast<QFontEngineFT*> (m_current_textitem->fontEngine);
- QFontEngineFT::QGlyphSet *gset = ft->loadTransformedGlyphSet(m_transform);
-
- if (gset && ft->loadGlyphs(gset, &g, 1, format)) {
- QFontEngineFT::Glyph *glyph = gset->glyph_data.value(g);
- const int bytesPerLine = (format == QFontEngineFT::Format_Mono ? ((glyph->width + 31) & ~31) >> 3
- : (glyph->width + 3) & ~3);
- mask = QImage(glyph->data, glyph->width, glyph->height, bytesPerLine, m_image.format());
- }
- } else
-#endif
- if (m_type == QFontEngineGlyphCache::Raster_RGBMask)
- mask = m_current_textitem->fontEngine->alphaRGBMapForGlyph(g, glyphMargin(), m_transform);
- else
- mask = m_current_textitem->fontEngine->alphaMapForGlyph(g, m_transform);
+ QImage mask = textureMapForGlyph(g);
#ifdef CACHE_DEBUG
printf("fillTexture of %dx%d at %d,%d in the cache of %dx%d\n", c.w, c.h, c.x, c.y, m_image.width(), m_image.height());
diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h
index 7f2c478..cb5be75 100644
--- a/src/gui/painting/qtextureglyphcache_p.h
+++ b/src/gui/painting/qtextureglyphcache_p.h
@@ -108,6 +108,8 @@ public:
QHash<glyph_t, Coord> coords;
+ QImage textureMapForGlyph(glyph_t g) const;
+
protected:
const QTextItemInt *m_current_textitem;
@@ -116,7 +118,6 @@ protected:
int m_cx; // current x
int m_cy; // current y
QFontEngineGlyphCache::Type m_type;
-
};