Make complex rich text works with the threaded renderer.
authorYoann Lopes <yoann.lopes@nokia.com>
Wed, 1 Jun 2011 14:18:37 +0000 (16:18 +0200)
committerYoann Lopes <yoann.lopes@nokia.com>
Wed, 1 Jun 2011 14:18:37 +0000 (16:18 +0200)
Painting must be done from the GUI thread.

src/declarative/items/qsgtext.cpp
src/declarative/items/qsgtext_p.h
src/declarative/items/qsgtext_p_p.h

index fe18169..ae9bffc 100644 (file)
@@ -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);
index 090a2b0..a5b61bc 100644 (file)
@@ -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)
index 9c0d5b1..6e98d30 100644 (file)
@@ -121,6 +121,7 @@ public:
     bool rightToLeftText:1;
     bool layoutTextElided:1;
     bool richTextAsImage:1;
+    bool textureImageCacheDirty:1;
 
     QRect layedOutTextRect;
     QSize paintedSize;