From 9ab1438359dea8210539ecb957e5f3adc20a3d21 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Thu, 17 Nov 2011 18:14:44 +1000 Subject: [PATCH] Optimization for context2d painting Avoid pass painting state by value. Change-Id: I86529ee7357b6cadbaa941b296d7ad025977f2aa Reviewed-by: Martin Jones --- .../context2d/qquickcontext2dcommandbuffer.cpp | 9 ++++----- .../context2d/qquickcontext2dcommandbuffer_p.h | 6 +++--- .../items/context2d/qquickcontext2dtexture.cpp | 10 +++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp b/src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp index e91a21c..476e7e2 100644 --- a/src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp +++ b/src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp @@ -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() diff --git a/src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h b/src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h index 46964d3..7deb2fb 100644 --- a/src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h +++ b/src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h @@ -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; diff --git a/src/declarative/items/context2d/qquickcontext2dtexture.cpp b/src/declarative/items/context2d/qquickcontext2dtexture.cpp index 791d8ad..1128fa2 100644 --- a/src/declarative/items/context2d/qquickcontext2dtexture.cpp +++ b/src/declarative/items/context2d/qquickcontext2dtexture.cpp @@ -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(); } } -- 1.7.2.5