diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2014-10-16 16:57:08 +0200 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@theqtcompany.com> | 2014-11-13 19:58:28 +0100 |
commit | dd08a22a4e8d7120341a1227e227de3f0628dd2f (patch) | |
tree | 6130ebf44600d5ec579752f617d9189875e7bb0b /src/quick/items/qquicktext.cpp | |
parent | dd6e14a7df6e40ff8b9ffe22fe6124630a15bda0 (diff) |
Invalidate font caches when switching between threadsv5.4.0-rc1
The font caches can only be used from a single thread at a time.
QFontEngineFT for instance, uses a global static thread storage
which is accessed on releasing and creating engines, and this
causes a crash if the font engine is created on one thread and
released on another.
We use the updatePolish() function to make sure the caches are
empty before entering updatePaintNode(), and then we invalidate
the cache again after updatePaintNode() is done.
[ChangeLog][Text] Fixed uncommon crash in text nodes.
Change-Id: I01dbc2ed58aeebd03d77a157c700330334bdb385
Task-number: QTBUG-38800
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/quick/items/qquicktext.cpp')
-rw-r--r-- | src/quick/items/qquicktext.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index bfa2fccd67..87255f4bd9 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -79,6 +79,7 @@ QQuickTextPrivate::QQuickTextPrivate() , requireImplicitSize(false), implicitWidthValid(false), implicitHeightValid(false) , truncated(false), hAlignImplicit(true), rightToLeftText(false) , layoutTextElided(false), textHasChanged(true), needToUpdateLayout(false), formatModifiesFontSize(false) + , polishSize(false) { implicitAntialiasing = true; } @@ -356,6 +357,8 @@ void QQuickTextPrivate::updateLayout() textHasChanged = true; updateLayout(); } + + q->polish(); } void QQuickText::imageDownloadFinished() @@ -2248,13 +2251,22 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data node->addImage(QRectF(img->pos.x() + dx, img->pos.y() + dy, pix->width(), pix->height()), pix->image()); } } + + // The font caches have now been initialized on the render thread, so they have to be + // invalidated before we can use them from the main thread again. + invalidateFontCaches(); + return node; } void QQuickText::updatePolish() { Q_D(QQuickText); - d->updateSize(); + if (d->polishSize) { + d->updateSize(); + d->polishSize = false; + } + invalidateFontCaches(); } /*! @@ -2381,6 +2393,7 @@ void QQuickText::setFontSizeMode(FontSizeMode mode) if (d->fontSizeMode() == mode) return; + d->polishSize = true; polish(); d->extra.value().fontSizeMode = mode; @@ -2409,8 +2422,10 @@ void QQuickText::setMinimumPixelSize(int size) if (d->minimumPixelSize() == size) return; - if (d->fontSizeMode() != FixedSize && (widthValid() || heightValid())) + if (d->fontSizeMode() != FixedSize && (widthValid() || heightValid())) { + d->polishSize = true; polish(); + } d->extra.value().minimumPixelSize = size; emit minimumPixelSizeChanged(); } @@ -2437,8 +2452,10 @@ void QQuickText::setMinimumPointSize(int size) if (d->minimumPointSize() == size) return; - if (d->fontSizeMode() != FixedSize && (widthValid() || heightValid())) + if (d->fontSizeMode() != FixedSize && (widthValid() || heightValid())) { + d->polishSize = true; polish(); + } d->extra.value().minimumPointSize = size; emit minimumPointSizeChanged(); } @@ -2699,4 +2716,26 @@ QString QQuickText::linkAt(qreal x, qreal y) const return d->anchorAt(QPointF(x, y)); } +/*! + * \internal + * + * Invalidates font caches owned by the text objects owned by the element + * to work around the fact that text objects cannot be used from multiple threads. + */ +void QQuickText::invalidateFontCaches() +{ + Q_D(QQuickText); + + if (d->richText && d->extra->doc != 0) { + QTextBlock block; + for (block = d->extra->doc->firstBlock(); block.isValid(); block = block.next()) { + if (block.layout() != 0 && block.layout()->engine() != 0) + block.layout()->engine()->resetFontEngineCache(); + } + } else { + if (d->layout.engine() != 0) + d->layout.engine()->resetFontEngineCache(); + } +} + QT_END_NAMESPACE |