summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond.kjernasen@nokia.com>2010-09-21 15:08:09 (GMT)
committerTrond Kjernåsen <trond.kjernasen@nokia.com>2010-09-21 15:19:56 (GMT)
commiteb2926a2f9607e985b8bca54346e6fdf91343247 (patch)
tree3910c0d194d515a5058bd7e839ae453255041a93
parentfc7f7d9193f0b9e4bfefa63d739a24005c0140af (diff)
downloadQt-eb2926a2f9607e985b8bca54346e6fdf91343247.zip
Qt-eb2926a2f9607e985b8bca54346e6fdf91343247.tar.gz
Qt-eb2926a2f9607e985b8bca54346e6fdf91343247.tar.bz2
Fixed drawing a large number of glyphs with the same font under GL.
Our glyph caching system doesn't take GL texture size limitation into account, and assumes you can create an infinitely large texture. On top of that, the cache will never create a cache that is wider than 256, or QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH, which means we'll hit the texture size limit even faster. With this patch the entire texture is utilized. However, to fix in properly we need to support having multiple texture for each font engine. That will be fixed shortly (see task QTBUG-13784). Task-number: QT-3971 Reviewed-by: Eskil
-rw-r--r--src/gui/painting/qtextureglyphcache.cpp20
-rw-r--r--src/gui/painting/qtextureglyphcache_p.h6
-rw-r--r--src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp11
-rw-r--r--src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h2
4 files changed, 30 insertions, 9 deletions
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp
index 631a9cf..b609f7b 100644
--- a/src/gui/painting/qtextureglyphcache.cpp
+++ b/src/gui/painting/qtextureglyphcache.cpp
@@ -47,10 +47,6 @@
#include "private/qnativeimage_p.h"
#include "private/qfontengine_ft_p.h"
-#ifndef QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH
-#define QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH 256
-#endif
-
QT_BEGIN_NAMESPACE
// #define CACHE_DEBUG
@@ -137,10 +133,18 @@ void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const
m_currentRowHeight = qMax(m_currentRowHeight, c.h + margin * 2);
if (m_cx + c.w > m_w) {
- // no room on the current line, start new glyph strip
- m_cx = 0;
- m_cy += m_currentRowHeight + paddingDoubled;
- m_currentRowHeight = 0; // New row
+ int new_width = m_w*2;
+ while (new_width < m_cx + c.w)
+ new_width *= 2;
+ if (new_width <= maxTextureWidth()) {
+ resizeTextureData(new_width, m_h);
+ m_w = new_width;
+ } else {
+ // no room on the current line, start new glyph strip
+ m_cx = 0;
+ m_cy += m_currentRowHeight + paddingDoubled;
+ m_currentRowHeight = 0; // New row
+ }
}
if (m_cy + c.h > m_h) {
int new_height = m_h*2;
diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h
index a818978..e6d2b22 100644
--- a/src/gui/painting/qtextureglyphcache_p.h
+++ b/src/gui/painting/qtextureglyphcache_p.h
@@ -64,6 +64,10 @@
# undef m_type
#endif
+#ifndef QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH
+#define QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH 256
+#endif
+
struct glyph_metrics_t;
typedef unsigned int glyph_t;
@@ -113,6 +117,8 @@ public:
QHash<glyph_t, Coord> coords;
QImage textureMapForGlyph(glyph_t g) const;
+ virtual int maxTextureWidth() const { return QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH; }
+ virtual int maxTextureHeight() const { return 32768; }
protected:
QFontEngine *m_current_fontengine;
diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
index 410cf21..f353995 100644
--- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
+++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
@@ -129,7 +129,7 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height)
GLuint oldTexture = m_texture;
createTextureData(width, height);
-
+
if (ctx->d_ptr->workaround_brokenFBOReadBack) {
QImageTextureGlyphCache::resizeTextureData(width, height);
Q_ASSERT(image().depth() == 8);
@@ -281,4 +281,13 @@ int QGLTextureGlyphCache::glyphPadding() const
return 1;
}
+int QGLTextureGlyphCache::maxTextureWidth() const
+{
+ return ctx->d_ptr->maxTextureSize();
+}
+
+int QGLTextureGlyphCache::maxTextureHeight() const
+{
+ return ctx->d_ptr->maxTextureSize();
+}
QT_END_NAMESPACE
diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
index 6bcd655..eb3693c 100644
--- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
+++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
@@ -73,6 +73,8 @@ public:
virtual void resizeTextureData(int width, int height);
virtual void fillTexture(const Coord &c, glyph_t glyph);
virtual int glyphPadding() const;
+ virtual int maxTextureWidth() const;
+ virtual int maxTextureHeight() const;
inline GLuint texture() const { return m_texture; }