Prevent initial clipping in Context2D
authorUlf Hermann <ulf.hermann@digia.com>
Mon, 2 Jun 2014 10:17:10 +0000 (12:17 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 3 Jun 2014 10:51:27 +0000 (12:51 +0200)
Don't set an initial clip path and only start clipping once a clip
path has manually been set.

Task-number: QTBUG-39114
Change-Id: Id277775d6eb0be87bead0e5d076f32a07ebdfe5c
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
src/quick/items/context2d/qquickcontext2d.cpp
src/quick/items/context2d/qquickcontext2d_p.h
src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp

index 3481651b1e2890d1ad3df4da40616ca53c77a30f..a7d5f7d65fff22eb119d1fef10b295cbb977b246 100644 (file)
@@ -3605,10 +3605,12 @@ void QQuickContext2D::clip()
 
     QPainterPath clipPath = m_path;
     clipPath.closeSubpath();
-    if (!state.clipPath.isEmpty())
+    if (state.clip) {
         state.clipPath = clipPath.intersected(state.clipPath);
-    else
+    } else {
+        state.clip = true;
         state.clipPath = clipPath;
+    }
     buffer()->clip(state.clipPath);
 }
 
@@ -4277,9 +4279,8 @@ void QQuickContext2D::popState()
     if (newState.miterLimit != state.miterLimit)
         buffer()->setMiterLimit(newState.miterLimit);
 
-    if (newState.clipPath != state.clipPath) {
+    if (newState.clip && (!state.clip || newState.clipPath != state.clipPath))
         buffer()->clip(newState.clipPath);
-    }
 
     if (newState.shadowBlur != state.shadowBlur)
         buffer()->setShadowBlur(newState.shadowBlur);
@@ -4307,12 +4308,6 @@ void QQuickContext2D::reset()
 
     m_path = QPainterPath();
 
-    QPainterPath defaultClipPath;
-
-    QRect r(0, 0, m_canvas->canvasSize().width(), m_canvas->canvasSize().height());
-    r = r.united(m_canvas->canvasWindow().toRect());
-    defaultClipPath.addRect(r);
-    newState.clipPath = defaultClipPath;
     newState.clipPath.setFillRule(Qt::WindingFill);
 
     m_stateStack.clear();
index ab851d302fd7abbde22502f9bd876f4773e2dd04..bd1a83ce08e733f0230ba2062bd09c5440fa0092 100644 (file)
@@ -123,6 +123,7 @@ public:
             , strokePatternRepeatX(false)
             , strokePatternRepeatY(false)
             , invertibleCTM(true)
+            , clip(false)
             , fillRule(Qt::WindingFill)
             , globalAlpha(1.0)
             , lineWidth(1)
@@ -150,6 +151,7 @@ public:
         bool strokePatternRepeatX:1;
         bool strokePatternRepeatY:1;
         bool invertibleCTM:1;
+        bool clip:1;
         Qt::FillRule fillRule;
         qreal globalAlpha;
         qreal lineWidth;
index 5697c25ff051bdb92ca23dfb3b77d795ea0aad39..cb09c9d4ffdb4350ee5161ded922c67e00ec3d07 100644 (file)
@@ -215,7 +215,8 @@ void QQuickContext2DCommandBuffer::setPainterState(QPainter* p, const QQuickCont
    if (state.globalCompositeOperation != p->compositionMode())
        p->setCompositionMode(state.globalCompositeOperation);
 
-   p->setClipPath(state.clipPath);
+   if (state.clip)
+       p->setClipPath(state.clipPath);
 }
 
 static void qt_drawImage(QPainter *p, QQuickContext2D::State& state, QImage image, const QRectF& sr, const QRectF& dr, bool shadow = false)