diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-17 13:36:52 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-17 14:43:43 (GMT) |
commit | e43cf7a591fc98c544c620e0722bdd1201feaea9 (patch) | |
tree | 39614c01ef4ce55b32ee887e9efc7ae1644cc45b /src/gui/painting/qtextureglyphcache.cpp | |
parent | e4e92b74980c4f601d080e1e072b556b7318c915 (diff) | |
download | Qt-e43cf7a591fc98c544c620e0722bdd1201feaea9.zip Qt-e43cf7a591fc98c544c620e0722bdd1201feaea9.tar.gz Qt-e43cf7a591fc98c544c620e0722bdd1201feaea9.tar.bz2 |
Make sure height of glyph cache is a power of two
Making the size of the glyph cache a power of two can potentially
have performance benefits on hardware accelerated graphics systems.
Since it will also decrease the number of times the cache has to be
copied, and therefore implies a speed-up for all paint engines, it has
been implemented for all of them in general.
Reviewed-by: Gunnar
Diffstat (limited to 'src/gui/painting/qtextureglyphcache.cpp')
-rw-r--r-- | src/gui/painting/qtextureglyphcache.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index 7f32d19..cf3957b 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -55,6 +55,20 @@ QT_BEGIN_NAMESPACE // #define CACHE_DEBUG +// returns the highest number closest to v, which is a power of 2 +// NB! assumes 32 bit ints +int qt_next_power_of_two(int v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + ++v; + return v; +} + void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const glyph_t *glyphs, const QFixedPoint *) { @@ -115,7 +129,7 @@ void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const rowHeight += margin * 2; if (isNull()) - createCache(QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH, rowHeight); + createCache(QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH, qt_next_power_of_two(rowHeight)); // now actually use the coords and paint the wanted glyps into cache. QHash<glyph_t, Coord>::iterator iter = listItemCoordinates.begin(); @@ -128,13 +142,9 @@ void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const m_cy = m_h; } if (m_cy + c.h > m_h) { - int new_height; - if (m_cx == 0) { // add a whole row - new_height = m_h + rowHeight; - m_cy = m_h; - } else { // just extend row - new_height = m_cy + rowHeight; - } + int new_height = m_h*2; + while (new_height < m_cy + c.h) + new_height *= 2; // if no room in the current texture - realloc a larger texture resizeTextureData(m_w, new_height); m_h = new_height; |