From f45fe58ad2aa741c90b756643da75f1a6bc2fdf6 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 2 Jun 2014 12:17:10 +0200 Subject: [PATCH] Prevent initial clipping in Context2D 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 --- src/quick/items/context2d/qquickcontext2d.cpp | 15 +++++---------- src/quick/items/context2d/qquickcontext2d_p.h | 2 ++ .../context2d/qquickcontext2dcommandbuffer.cpp | 3 ++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index 3481651b1..a7d5f7d65 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -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(); diff --git a/src/quick/items/context2d/qquickcontext2d_p.h b/src/quick/items/context2d/qquickcontext2d_p.h index ab851d302..bd1a83ce0 100644 --- a/src/quick/items/context2d/qquickcontext2d_p.h +++ b/src/quick/items/context2d/qquickcontext2d_p.h @@ -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; diff --git a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp index 5697c25ff..cb09c9d4f 100644 --- a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp +++ b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp @@ -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) -- 2.34.1