fix canvas bug
authorCharles Yin <charles.yin@nokia.com>
Tue, 11 Oct 2011 04:28:28 +0000 (14:28 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 11 Oct 2011 04:42:53 +0000 (06:42 +0200)
do painting only after component loaded and paint after geometry size initialized

Task-number:QTBUG-21920
Task-number:QTBUG-21918
Change-Id: Ibbc12d416dc694eff35f16c03cbc3c16e333645b
Reviewed-on: http://codereview.qt-project.org/6387
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Charles Yin <charles.yin@nokia.com>
src/declarative/items/context2d/qsgcanvasitem.cpp
src/declarative/items/context2d/qsgcontext2dtexture.cpp
tests/auto/declarative/qsgcanvasitem/data/tst_canvas.qml

index 49a0eb7..deb3493 100644 (file)
@@ -416,18 +416,16 @@ void QSGCanvasItem::geometryChanged(const QRectF &newGeometry,
 void QSGCanvasItem::componentComplete()
 {
     Q_D(QSGCanvasItem);
+    QSGItem::componentComplete();
 
     if (!d->context)
         createContext();
     createTexture();
 
-
-    _doPainting(canvasWindow());
-    QSGItem::componentComplete();
-
     d->baseUrl = qmlEngine(this)->contextForObject(this)->baseUrl();
+    requestPaint();
+    updatePolish(); //force update the canvas sizes to texture for the first time
     d->componentCompleted = true;
-    update();
 }
 
 void QSGCanvasItem::updatePolish()
@@ -535,7 +533,8 @@ void QSGCanvasItem::markDirty(const QRectF& region)
 {
     Q_D(QSGCanvasItem);
     d->dirtyRect |= region;
-    polish();
+    if (d->componentCompleted)
+        polish();
     update();
 }
 
@@ -699,8 +698,6 @@ QString QSGCanvasItem::toDataURL(const QString& mimeType) const
             type = QLatin1Literal("PPM");
         else if (mime == QLatin1Literal("image/tiff"))
             type = QLatin1Literal("TIFF");
-        else if (mime == QLatin1Literal("image/xbm"))
-            type = QLatin1Literal("XBM");
         else if (mime == QLatin1Literal("image/xpm"))
             type = QLatin1Literal("XPM");
         else
index 6d879f7..c84dda4 100644 (file)
@@ -101,6 +101,8 @@ void QSGContext2DTexture::markDirtyTexture()
     m_dirtyTexture = true;
     unlock();
     emit textureChanged();
+    if (m_item)
+        emit m_item->painted();
 }
 
 bool QSGContext2DTexture::setCanvasSize(const QSize &size)
@@ -142,12 +144,6 @@ void QSGContext2DTexture::setItem(QSGCanvasItem* item)
         m_context = item->context();
         m_state = m_context->state;
         unlock();
-        connect(this, SIGNAL(textureChanged()), m_item, SIGNAL(painted()), Qt::QueuedConnection);
-        canvasChanged(item->canvasSize().toSize()
-                    , item->tileSize()
-                    , item->canvasWindow().toAlignedRect()
-                    , item->canvasWindow().toAlignedRect()
-                    , item->smooth());
     }
 }
 
index b6621d8..db61fce 100644 (file)
@@ -9,10 +9,10 @@ Rectangle {
         id:canvas
         Canvas {
             id:c
-             width:10;height:10
+             width:100;height:100
              onPaint: {
                  context.fillStyle = "red";
-                 context.fillRect(0, 0, 10, 10);
+                 context.fillRect(0, 0, 100, 100);
              }
              property int paintCount:spyPaint.count
              property int paintedCount:spyPainted.count
@@ -183,7 +183,6 @@ Rectangle {
                    {mimeType:"image/jpeg"},
                    {mimeType:"image/x-portable-pixmap"},
                    {mimeType:"image/tiff"},
-                   {mimeType:"image/xbm"},
                    {mimeType:"image/xpm"},
                    ];
        }
@@ -210,7 +209,8 @@ Rectangle {
            ctx.fillStyle = "blue";
            ctx.fillRect(0, 0, c.width, c.height);
            ctx.restore();
-
+           c.requestPaint();
+           wait(100);
            var dataUrl2 = c.toDataURL(data.mimeType);
            verify (dataUrl2 != "data:,");
            verify (dataUrl2 != dataUrl);
@@ -224,7 +224,9 @@ Rectangle {
            c.renderTarget = Canvas.Image;
 
            c.requestPaint();
-           wait(200);
+           wait(100);
+           c.toDataURL();
+
            compare(c.paintedCount, 1);
            compare(c.paintCount, 1);
            c.destroy();