aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@live.com>2015-02-24 09:29:15 -0600
committerMichael Brasser <michael.brasser@live.com>2015-02-25 14:36:25 +0000
commitdd58743eafaff2e55cc49d9d6b9f8a027b6f646e (patch)
tree20e656cb5515d613e2f1ddb55e283b68aee1a0f4
parentad67ec26d0cbc98e3440dd38bb20eef4da2ee96d (diff)
Allow glyph cache textures to be created at full size.
On embedded hardware, texture resizes can be quite slow. The glyph cache currently often needs to resize when new glyphs are added, and glyph additions are very frequent when using a language with a large set of glyphs (such as Chinese). The current glyph cache design minimizes the amount of memory used. When QSG_PREFER_FULLSIZE_GLYPHCACHE_TEXTURES is set, and we are using a font with a large number of glyphs, we can instead allocate max-sized textures. This leads to significantly less time when inserting glyphs into the cache (often incurred over a span of time), at the cost of higher initial memory and creation times (often incurred at application startup). Change-Id: Id1021b9d213e5f8635c4197b624474f28c6f44ff Task-number: QTBUG-29264 Reviewed-by: Robin Burchell <robin.burchell@viroteck.net> Reviewed-by: Gunnar Sletta <gunnar@sletta.org> Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
-rw-r--r--src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp12
-rw-r--r--src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h11
2 files changed, 20 insertions, 3 deletions
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
index 9ef0d50dfc..16745c18d5 100644
--- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
+++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
@@ -47,6 +47,7 @@
QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(qmlUseGlyphCacheWorkaround, QML_USE_GLYPHCACHE_WORKAROUND)
+DEFINE_BOOL_CONFIG_OPTION(qsgPreferFullSizeGlyphCacheTextures, QSG_PREFER_FULLSIZE_GLYPHCACHE_TEXTURES)
#if !defined(QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING)
# define QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING 2
@@ -491,6 +492,17 @@ bool QSGDefaultDistanceFieldGlyphCache::useTextureUploadWorkaround() const
return useWorkaround;
}
+bool QSGDefaultDistanceFieldGlyphCache::createFullSizeTextures() const
+{
+ static bool set = false;
+ static bool fullSize = false;
+ if (!set) {
+ fullSize = qsgPreferFullSizeGlyphCacheTextures() && glyphCount() > QT_DISTANCEFIELD_HIGHGLYPHCOUNT;
+ set = true;
+ }
+ return fullSize;
+}
+
int QSGDefaultDistanceFieldGlyphCache::maxTextureSize() const
{
if (!m_maxTextureSize)
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
index 3b64eadc6f..cffe02330a 100644
--- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
+++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
@@ -62,6 +62,7 @@ public:
bool useTextureResizeWorkaround() const;
bool useTextureUploadWorkaround() const;
+ bool createFullSizeTextures() const;
int maxTextureSize() const;
void setMaxTextureCount(int max) { m_maxTextureCount = max; }
@@ -75,7 +76,7 @@ private:
QDistanceField image;
int padding;
- TextureInfo() : texture(0), padding(-1)
+ TextureInfo(const QRect &preallocRect = QRect()) : texture(0), allocatedArea(preallocRect), padding(-1)
{ }
};
@@ -84,8 +85,12 @@ private:
TextureInfo *textureInfo(int index)
{
- for (int i = m_textures.count(); i <= index; ++i)
- m_textures.append(TextureInfo());
+ for (int i = m_textures.count(); i <= index; ++i) {
+ if (createFullSizeTextures())
+ m_textures.append(QRect(0, 0, maxTextureSize(), maxTextureSize()));
+ else
+ m_textures.append(TextureInfo());
+ }
return &m_textures[index];
}