Optimization for context2d painting
authorCharles Yin <charles.yin@nokia.com>
Thu, 17 Nov 2011 08:14:44 +0000 (18:14 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 17 Nov 2011 09:21:46 +0000 (10:21 +0100)
Avoid pass painting state by value.

Change-Id: I86529ee7357b6cadbaa941b296d7ad025977f2aa
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp
src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h
src/declarative/items/context2d/qquickcontext2dtexture.cpp

index e91a21c..476e7e2 100644 (file)
@@ -197,7 +197,7 @@ static inline void drawRepeatPattern(QPainter* p, const QImage& image, const QRe
     }
 }
 
-QPen QQuickContext2DCommandBuffer::makePen(QQuickContext2D::State state)
+QPen QQuickContext2DCommandBuffer::makePen(const QQuickContext2D::State& state)
 {
     QPen pen;
     pen.setWidthF(state.lineWidth);
@@ -208,7 +208,7 @@ QPen QQuickContext2DCommandBuffer::makePen(QQuickContext2D::State state)
     return pen;
 }
 
-void QQuickContext2DCommandBuffer::setPainterState(QPainter* p, QQuickContext2D::State state, const QPen& pen)
+void QQuickContext2DCommandBuffer::setPainterState(QPainter* p, const QQuickContext2D::State& state, const QPen& pen)
 {
    p->setTransform(state.matrix * p->transform());
 
@@ -229,10 +229,10 @@ void QQuickContext2DCommandBuffer::setPainterState(QPainter* p, QQuickContext2D:
        p->setCompositionMode(state.globalCompositeOperation);
 }
 
-QQuickContext2D::State QQuickContext2DCommandBuffer::replay(QPainter* p, QQuickContext2D::State state)
+void QQuickContext2DCommandBuffer::replay(QPainter* p, QQuickContext2D::State& state)
 {
     if (!p)
-        return state;
+        return;
 
     reset();
 
@@ -418,7 +418,6 @@ QQuickContext2D::State QQuickContext2DCommandBuffer::replay(QPainter* p, QQuickC
     }
 
     p->end();
-    return state;
 }
 
 QQuickContext2DCommandBuffer::QQuickContext2DCommandBuffer()
index 46964d3..7deb2fb 100644 (file)
@@ -236,10 +236,10 @@ public:
     inline QColor takeColor() { return colors[colorIdx++]; }
     inline QBrush takeBrush() { return brushes[brushIdx++]; }
 
-    QQuickContext2D::State replay(QPainter* painter, QQuickContext2D::State state);
+    void replay(QPainter* painter, QQuickContext2D::State& state);
 private:
-    QPen makePen(QQuickContext2D::State state);
-    void setPainterState(QPainter* painter, QQuickContext2D::State state, const QPen& pen);
+    QPen makePen(const QQuickContext2D::State& state);
+    void setPainterState(QPainter* painter, const QQuickContext2D::State& state, const QPen& pen);
     int cmdIdx;
     int intIdx;
     int boolIdx;
index 791d8ad..1128fa2 100644 (file)
@@ -240,7 +240,7 @@ void QQuickContext2DTexture::paintWithoutTiles()
         p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing
                                  | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, false);
     p.setCompositionMode(QPainter::CompositionMode_SourceOver);
-    m_state = ccb->replay(&p, m_state);
+    ccb->replay(&p, m_state);
 
     ccb->clear();
     markDirtyTexture();
@@ -264,9 +264,6 @@ void QQuickContext2DTexture::paint()
     if (!m_tiledCanvas) {
         paintWithoutTiles();
     } else {
-        QQuickContext2D::State oldState = m_state;
-        QQuickContext2DCommandBuffer* ccb = m_context->buffer();
-
         lock();
         QRect tiledRegion = createTiles(m_canvasWindow.intersected(QRect(QPoint(0, 0), m_canvasSize)));
         unlock();
@@ -296,6 +293,8 @@ void QQuickContext2DTexture::paint()
             }
 
             if (beginPainting()) {
+                QQuickContext2D::State oldState = m_state;
+                QQuickContext2DCommandBuffer* ccb = m_context->buffer();
                 foreach (QQuickContext2DTile* tile, m_tiles) {
                     bool dirtyTile = false, dirtyCanvas = false, smooth = false;
 
@@ -312,7 +311,7 @@ void QQuickContext2DTexture::paint()
                         endPainting();
                         return;
                     } else if (dirtyTile) {
-                        m_state = ccb->replay(tile->createPainter(smooth), oldState);
+                        ccb->replay(tile->createPainter(smooth), oldState);
                         tile->drawFinished();
                         lock();
                         tile->markDirty(false);
@@ -323,6 +322,7 @@ void QQuickContext2DTexture::paint()
                 }
                 ccb->clear();
                 endPainting();
+                m_state = oldState;
                 markDirtyTexture();
             }
         }