diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-29 15:53:39 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-29 15:53:39 (GMT) |
commit | da388773f581e251054abd037dc410ae52cfa69c (patch) | |
tree | 5801db3f2793ff9b9d418b25814db50880427550 /src/gui/text/qstatictext.cpp | |
parent | 951922772c0c5f8b8833c2793064f8c6ebeecd9c (diff) | |
download | Qt-da388773f581e251054abd037dc410ae52cfa69c.zip Qt-da388773f581e251054abd037dc410ae52cfa69c.tar.gz Qt-da388773f581e251054abd037dc410ae52cfa69c.tar.bz2 |
Improve performance of QStaticText on OpenGL by caching data on GPU
There's a big improvement to be seen in the OpenGL engine by caching
the vertex data for the QStaticText in VBOs. In order to have the
buffers properly disposed, I've implemented a userdata concept for
QStaticTextItem. By default, the optimizations will be turned off, and
can be turned on by using the useBackendOptimizations flag.
Diffstat (limited to 'src/gui/text/qstatictext.cpp')
-rw-r--r-- | src/gui/text/qstatictext.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 6c960bb..7be89cb 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -236,6 +236,43 @@ QString QStaticText::text() const } /*! + Sets whether the QStaticText object should use optimizations specific to the paint engine + backend if they are available. If \a on is set to true, backend optimizations will be turned + on, otherwise they will be turned off. The default value is false. + + If backend optimizations are on, the paint engine used to draw the static text is allowed to + store data in the object which will assist it in future calls to drawStaticText. In particular, + when using the opengl graphics system, or when painting on a QGLWidget, turning this flag on will + improve performance, but increase the memory footprint of the QStaticText object. + + The default value is false. + + \note This function will cause the layout of the text to be recalculated. + + \sa useBackendOptimizations() +*/ +void QStaticText::setUseBackendOptimizations(bool on) +{ + if (on == d_ptr->useBackendOptimizations) + return; + + detach(); + d_ptr->useBackendOptimizations = on; + d_ptr->init(); +} + +/*! + Returns whether the QStaticText object should use optimizations specific to the paint engine + backend when possible. By default this setting is false. + + \sa setUseBackendOptimizations() +*/ +bool QStaticText::useBackendOptimizations() const +{ + return d_ptr->useBackendOptimizations; +} + +/*! Sets the maximum size of the QStaticText to \a maximumSize. \note This function will cause the layout of the text to be recalculated. @@ -470,6 +507,12 @@ void QStaticTextPrivate::init() itemCount = counterDevice.itemCount(); items = new QStaticTextItem[itemCount]; + if (useBackendOptimizations) { + for (int i=0; i<itemCount; ++i) + items[i].useBackendOptimizations = true; + } + + int glyphCount = counterDevice.glyphCount(); glyphPool = new glyph_t[glyphCount]; positionPool = new QFixedPoint[glyphCount]; |