diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-08-17 11:09:51 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-14 12:54:04 (GMT) |
commit | 91e96d6c730aac4accef64e5eaab1b289939ef8e (patch) | |
tree | 23a5303b53c29f3ec0ec24fccff176ef76fdc1f0 /src/gui/painting/qpainter.cpp | |
parent | 49dfc4ed6a89cdd7377e4b88236bb7303fdfdc15 (diff) | |
download | Qt-91e96d6c730aac4accef64e5eaab1b289939ef8e.zip Qt-91e96d6c730aac4accef64e5eaab1b289939ef8e.tar.gz Qt-91e96d6c730aac4accef64e5eaab1b289939ef8e.tar.bz2 |
Optimize QStaticText for space
By caching the results of getGlyphPositions() we can make a code path
in the critical paint engines which is optimal both in space and speed.
The engines where speed is of less importance (pdf engine etc.) which
may need more information, we choose the slower code path of drawText()
which lays out the text again. We should have optimal paths in raster,
vg and GL2 paint engines. The others are less important. Memory
consumption of static text is now 14 bytes per glyph, 8 bytes per item
and a static overhead of 40 bytes per QStaticText object.
Diffstat (limited to 'src/gui/painting/qpainter.cpp')
-rw-r--r-- | src/gui/painting/qpainter.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 83f66e2..1d7f57d 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5719,8 +5719,10 @@ void QPainter::drawText(const QPointF &p, const QString &str) /*! Draws the given \a staticText beginning at the given \a position. - This function can be used to optimize drawing text if the text and its layout is updated + This function can be used to optimize drawing text if the text and its layout is updated seldomly. + + \sa QStaticText */ void QPainter::drawStaticText(const QPointF &position, const QStaticText &staticText) { @@ -5728,9 +5730,19 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static if (!d->engine || staticText.isEmpty() || pen().style() == Qt::NoPen) return; - const QStaticTextPrivate *staticText_d = QStaticTextPrivate::get(&staticText); - bool restoreWhenFinished = false; + const QStaticTextPrivate *staticText_d = QStaticTextPrivate::get(&staticText); + // If we don't have an extended paint engine, or if the painter is transformed, + // we go through standard code path + if (d->extended == 0 || !d->state->matrix.isIdentity()) { + if (staticText_d->size.isValid()) + drawText(QRectF(position, staticText_d->size), staticText_d->text); + else + drawText(position, staticText_d->text); + return; + } + + bool restoreWhenFinished = false; if (staticText_d->size.isValid()) { setClipRect(QRectF(position, staticText_d->size)); @@ -5746,8 +5758,8 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static } for (int i=0; i<staticText_d->itemCount; ++i) { - const QTextItemInt &gf = staticText_d->items[i]; - d->engine->drawTextItem(staticText_d->itemPositions[i] + position, gf); + QStaticTextItem *item = staticText_d->items + i; + d->extended->drawStaticTextItem(position, item); } if (restoreWhenFinished) |