From 6da49f13f80fa4a8f1b62424672f7ea081c6fa83 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 1 Jun 2011 16:18:37 +0200 Subject: [PATCH] Make complex rich text works with the threaded renderer. Painting must be done from the GUI thread. --- src/declarative/items/qsgtext.cpp | 33 ++++++++++++++++++++++++--------- src/declarative/items/qsgtext_p.h | 1 + src/declarative/items/qsgtext_p_p.h | 1 + 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/declarative/items/qsgtext.cpp b/src/declarative/items/qsgtext.cpp index fe18169..ae9bffc 100644 --- a/src/declarative/items/qsgtext.cpp +++ b/src/declarative/items/qsgtext.cpp @@ -103,11 +103,11 @@ QSGTextPrivate::QSGTextPrivate() lineHeightMode(QSGText::ProportionalHeight), lineCount(1), maximumLineCount(INT_MAX), maximumLineCountValid(false), texture(0), - imageCacheDirty(true), updateOnComponentComplete(true), + imageCacheDirty(false), updateOnComponentComplete(true), richText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false), - layoutTextElided(false), richTextAsImage(false), naturalWidth(0), doc(0), layoutThread(0), - nodeType(NodeIsNull) + layoutTextElided(false), richTextAsImage(false), textureImageCacheDirty(false), naturalWidth(0), + doc(0), layoutThread(0), nodeType(NodeIsNull) { cacheAllTextAsImage = enableImageCache(); } @@ -580,9 +580,10 @@ void QSGTextPrivate::invalidateImageCache() return; imageCacheDirty = true; - imageCache = QPixmap(); - } - if (q->isComponentComplete()) + + if (q->isComponentComplete()) + QCoreApplication::postEvent(q, new QEvent(QEvent::User)); + } else if (q->isComponentComplete()) q->update(); } @@ -591,6 +592,8 @@ void QSGTextPrivate::invalidateImageCache() */ void QSGTextPrivate::checkImageCache() { + Q_Q(QSGText); + if (!imageCacheDirty) return; @@ -631,6 +634,8 @@ void QSGTextPrivate::checkImageCache() } imageCacheDirty = false; + textureImageCacheDirty = true; + q->update(); } /*! @@ -1080,9 +1085,8 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) // XXX todo - some styled text can be done by the QSGTextNode if (d->richTextAsImage || d->cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && d->style != Normal)) { - bool wasDirty = d->imageCacheDirty; - - d->checkImageCache(); + bool wasDirty = d->textureImageCacheDirty; + d->textureImageCacheDirty = false; if (d->imageCache.isNull()) { delete oldNode; @@ -1142,6 +1146,17 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) } } +bool QSGText::event(QEvent *e) +{ + Q_D(QSGText); + if (e->type() == QEvent::User) { + d->checkImageCache(); + return true; + } else { + return QSGImplicitSizeItem::event(e); + } +} + qreal QSGText::paintedWidth() const { Q_D(const QSGText); diff --git a/src/declarative/items/qsgtext_p.h b/src/declarative/items/qsgtext_p.h index 090a2b0..a5b61bc 100644 --- a/src/declarative/items/qsgtext_p.h +++ b/src/declarative/items/qsgtext_p.h @@ -199,6 +199,7 @@ protected: virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); + virtual bool event(QEvent *); private: Q_DISABLE_COPY(QSGText) diff --git a/src/declarative/items/qsgtext_p_p.h b/src/declarative/items/qsgtext_p_p.h index 9c0d5b1..6e98d30 100644 --- a/src/declarative/items/qsgtext_p_p.h +++ b/src/declarative/items/qsgtext_p_p.h @@ -121,6 +121,7 @@ public: bool rightToLeftText:1; bool layoutTextElided:1; bool richTextAsImage:1; + bool textureImageCacheDirty:1; QRect layedOutTextRect; QSize paintedSize; -- 2.7.4