aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2011-06-20 09:20:14 +0200
committerGunnar Sletta <gunnar.sletta@nokia.com>2011-06-20 09:20:14 +0200
commitfba41ea10b5d5703f06ad5514aec6a3e8e8f6f14 (patch)
treee56dcd6ca9a2050b11ea452866d8693857cda6c1
parent170b1ddc7931781a70758dc2d206bfdbad6fb3f5 (diff)
Implement caching of the distance fields...
-rw-r--r--src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp b/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
index 31e654b0b9..0011492053 100644
--- a/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
+++ b/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
@@ -51,6 +51,7 @@
#include <qglfunctions.h>
#include <qglyphrun.h>
#include <qrawfont.h>
+#include <qdir.h>
QT_BEGIN_NAMESPACE
@@ -917,11 +918,38 @@ void QSGDistanceFieldGlyphCache::updateCache()
resizeTexture((requiredWidth), (requiredHeight));
glBindTexture(GL_TEXTURE_2D, m_textureData->texture);
+ // ### Remove before final release
+ static bool cacheDistanceFields = QApplication::arguments().contains("--cache-distance-fields");
+
+ QString tmpPath = QString::fromLatin1("%1/.qt/").arg(QDir::tempPath());
+ QString keyBase = QString::fromLatin1("%1%2%3_%4_%5_%6.fontblob")
+ .arg(tmpPath)
+ .arg(m_font.familyName())
+ .arg(m_font.styleName())
+ .arg(m_font.weight())
+ .arg(m_font.style());
+
+ if (cacheDistanceFields && !QFile::exists(tmpPath))
+ QDir(tmpPath).mkpath(tmpPath);
+
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 (cacheDistanceFields) {
+ QString key = keyBase.arg(glyphIndex);
+ QFile file(key);
+ if (file.open(QFile::ReadOnly)) {
+ int fileSize = file.size();
+ int dim = sqrt(fileSize);
+ QByteArray blob = file.readAll();
+ glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, dim, dim, GL_ALPHA, GL_UNSIGNED_BYTE, blob.constData());
+ continue;
+ }
+ }
+
+ QImage glyph = renderDistanceFieldGlyph(glyphIndex);
+
if (ctx->d_ptr->workaround_brokenFBOReadBack) {
QPainter p(&m_textureData->image);
p.setCompositionMode(QPainter::CompositionMode_Source);
@@ -931,6 +959,13 @@ 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());
+
+ if (cacheDistanceFields) {
+ QString key = keyBase.arg(glyphIndex);
+ QFile file(key);
+ file.open(QFile::WriteOnly);
+ file.write((const char *) glyph.constBits(), glyph.width() * glyph.height());
+ }
}
m_textureData->pendingGlyphs.reset();
}