From 2ac3bffd816d9fbe9646b6126b4a882f391b466f Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 4 Feb 2010 10:43:52 +0100 Subject: Small optimization for QStaticText when used with index arrays Don't recalculate the index array when the glyphs are simply moved. --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index d82d335..d20c258 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1349,7 +1349,13 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp textureCoordinateArray.clear(); #if defined(QSTATICTEXT_USE_INDEXARRAY) - indices.clear(); + QStaticTextUserData *uData = staticTextItem->userData; + QOpenGLStaticTextUserData *openGlUserData = uData != 0 + && uData->type == QStaticTextUserData::OpenGLUserData + ? static_cast(uData) + : 0; + bool updateIndices = openGlUserData == 0 + || openGlUserData->indices.size() < staticTextItem->numGlyphs; int j=0; #endif @@ -1362,8 +1368,10 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp textureCoordinateArray.addRect(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy)); #if defined(QSTATICTEXT_USE_INDEXARRAY) - for (int k=0; k<6; ++k) - indices.append(j++); + if (updateIndices) { + for (int k=0; k<6; ++k) + indices.append(j++); + } #endif } @@ -1390,7 +1398,8 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp textureCoordinateArray.data(), GL_STATIC_DRAW); #if defined(QSTATICTEXT_USE_INDEXARRAY) - userData->indices = indices; + if (updateIndices) + userData->indices = indices; #endif // If a new user data has been created, make sure we delete the old -- cgit v0.12