summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2018-03-22 16:45:01 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-03-26 16:00:43 +0000
commitc7c41fa1c6bced218e9a44859feb593624340228 (patch)
treeb9560b4aeea9c2604efe0ab8402a30046439c7ce
parent50cfbd6112a2682228cdf34cd72b5abae967cdb2 (diff)
Fix QPainter save/restore of clipping enabled state
Clipping enabled state would not always be correctly restored for the raster engine (other engines work fine). The raster engine's QClipData object is sometimes shared between painter state objects on the save/restore stack. QClipData has its own enabled flag, and this could then come out of sync. Fix by making sure we sync the enabled state on restore. Task-number: QTBUG-58789 Change-Id: I81e6254ebb93df6e153bbef58e32a885273e3224 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp5
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp30
2 files changed, 35 insertions, 0 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 33fde8c61a..6336b2943e 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -698,6 +698,11 @@ void QRasterPaintEngine::setState(QPainterState *s)
{
Q_D(QRasterPaintEngine);
QPaintEngineEx::setState(s);
+ QRasterPaintEngineState *t = state();
+ if (t->clip && t->clip->enabled != t->clipEnabled) {
+ // Since we do not "detach" clipdata when changing only enabled state, we need to resync state here
+ t->clip->enabled = t->clipEnabled;
+ }
d->rasterBuffer->compositionMode = s->composition_mode;
}
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index 8dfaa6f5cd..ba405e2860 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -153,6 +153,7 @@ private slots:
void setEqualClipRegionAndPath();
void clipRectSaveRestore();
+ void clipStateSaveRestore();
void clippedFillPath_data();
void clippedFillPath();
@@ -3425,6 +3426,35 @@ void tst_QPainter::clipRectSaveRestore()
QCOMPARE(img.pixel(0, 0), QColor(Qt::black).rgba());
}
+void tst_QPainter::clipStateSaveRestore()
+{
+ QImage img(16, 16, QImage::Format_RGB32);
+ img.fill(Qt::blue);
+ {
+ QPainter p(&img);
+ p.setClipRect(QRect(5, 5, 10, 10));
+ p.save();
+ p.setClipping(false);
+ p.restore();
+ p.fillRect(0, 0, 16, 16, Qt::red);
+ p.end();
+ QCOMPARE(img.pixel(0, 0), QColor(Qt::blue).rgb());
+ }
+
+ img.fill(Qt::blue);
+ {
+ QPainter p(&img);
+ p.setClipRect(QRect(5, 5, 10, 10));
+ p.setClipping(false);
+ p.save();
+ p.setClipping(true);
+ p.restore();
+ p.fillRect(0, 0, 16, 16, Qt::red);
+ p.end();
+ QCOMPARE(img.pixel(0, 0), QColor(Qt::red).rgb());
+ }
+}
+
void tst_QPainter::clippedImage()
{
QImage img(16, 16, QImage::Format_ARGB32_Premultiplied);