From 285855b8fbbdc7ad428a0c66f6c4469d97e55769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 8 Nov 2010 17:33:49 +0100 Subject: Fixed text rendering bug in raster engine when opacity != 1.0. If opacity is updated independently from the pen properties sometimes the raster engine's fast_text flag would not be updated correctly, causing it to use a rendering path which doesn't support alpha. Reviewed-by: Robin Burchell Reviewed-by: Andreas Kling --- src/gui/painting/qpaintengine_raster.cpp | 4 +++- tests/auto/qpainter/tst_qpainter.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 161ced5..89202ac 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -875,9 +875,10 @@ void QRasterPaintEngine::updateState() if (s->dirty & DirtyTransform) updateMatrix(s->matrix); - if (s->dirty & (DirtyPen|DirtyCompositionMode)) { + if (s->dirty & (DirtyPen|DirtyCompositionMode|DirtyOpacity)) { const QPainter::CompositionMode mode = s->composition_mode; s->flags.fast_text = (s->penData.type == QSpanData::Solid) + && s->intOpacity == 256 && (mode == QPainter::CompositionMode_Source || (mode == QPainter::CompositionMode_SourceOver && qAlpha(s->penData.solid.color) == 255)); @@ -901,6 +902,7 @@ void QRasterPaintEngine::opacityChanged() s->fillFlags |= DirtyOpacity; s->strokeFlags |= DirtyOpacity; s->pixmapFlags |= DirtyOpacity; + s->dirty |= DirtyOpacity; s->intOpacity = (int) (s->opacity * 256); } diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index ff9bf1c..83ff9a9 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -256,6 +256,7 @@ private slots: void drawPointScaled(); void QTBUG14614_gradientCacheRaceCondition(); + void drawTextOpacity(); private: void fillData(); @@ -4576,6 +4577,30 @@ void tst_QPainter::QTBUG14614_gradientCacheRaceCondition() producers[i].wait(); } +void tst_QPainter::drawTextOpacity() +{ + QImage image(32, 32, QImage::Format_RGB32); + image.fill(0xffffffff); + + QPainter p(&image); + p.setPen(QColor("#6F6F6F")); + p.setOpacity(0.5); + p.drawText(5, 30, QLatin1String("Qt")); + p.end(); + + QImage copy = image; + image.fill(0xffffffff); + + p.begin(&image); + p.setPen(QColor("#6F6F6F")); + p.drawLine(-10, -10, -1, -1); + p.setOpacity(0.5); + p.drawText(5, 30, QLatin1String("Qt")); + p.end(); + + QCOMPARE(image, copy); +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" -- cgit v0.12