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/qquicktextedit.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/qquicktextedit.cpp')
-rw-r--r-- | src/quick/items/qquicktextedit.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index aca7150ca2..b950f96277 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -1739,6 +1739,7 @@ void QQuickTextEdit::triggerPreprocess() Q_D(QQuickTextEdit); if (d->updateType == QQuickTextEditPrivate::UpdateNone) d->updateType = QQuickTextEditPrivate::UpdateOnlyPreprocess; + polish(); update(); } @@ -1758,6 +1759,25 @@ static inline void updateNodeTransform(QQuickTextNode* node, const QPointF &topL node->setMatrix(transformMatrix); } +/*! + * \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 QQuickTextEdit::invalidateFontCaches() +{ + Q_D(QQuickTextEdit); + if (d->document == 0) + return; + + QTextBlock block; + for (block = d->document->firstBlock(); block.isValid(); block = block.next()) { + if (block.layout() != 0 && block.layout()->engine() != 0) + block.layout()->engine()->resetFontEngineCache(); + } +} + QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) { Q_UNUSED(updatePaintNodeData); @@ -1911,9 +1931,16 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData * rootNode->resetCursorNode(cursor); } + invalidateFontCaches(); + return rootNode; } +void QQuickTextEdit::updatePolish() +{ + invalidateFontCaches(); +} + /*! \qmlproperty bool QtQuick::TextEdit::canPaste @@ -2079,6 +2106,7 @@ void QQuickTextEdit::q_contentsChange(int pos, int charsRemoved, int charsAdded) markDirtyNodesForRange(pos, editRange, delta); + polish(); if (isComponentComplete()) { d->updateType = QQuickTextEditPrivate::UpdatePaintNode; update(); @@ -2106,6 +2134,7 @@ void QQuickTextEdit::updateSelection() // No need for node updates when we go from an empty selection to another empty selection if (d->control->textCursor().hasSelection() || d->hadSelection) { markDirtyNodesForRange(qMin(d->lastSelectionStart, d->control->textCursor().selectionStart()), qMax(d->control->textCursor().selectionEnd(), d->lastSelectionEnd), 0); + polish(); if (isComponentComplete()) { d->updateType = QQuickTextEditPrivate::UpdatePaintNode; update(); @@ -2246,6 +2275,7 @@ void QQuickTextEdit::updateWholeDocument() node->setDirty(); } + polish(); if (isComponentComplete()) { d->updateType = QQuickTextEditPrivate::UpdatePaintNode; update(); @@ -2260,6 +2290,7 @@ void QQuickTextEdit::invalidateBlock(const QTextBlock &block) void QQuickTextEdit::updateCursor() { Q_D(QQuickTextEdit); + polish(); if (isComponentComplete()) { d->updateType = QQuickTextEditPrivate::UpdatePaintNode; update(); |