From 27c99302d0b44c6e9cd0eda6ba888b6a6f5bea38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Thu, 29 Oct 2009 18:50:55 +0100 Subject: Get rid of QPainter warnings generated from QGraphicsOpacityEffect. Problem was that we painted on null pixmap. We also want to use the pixmap cache (QGraphicsEffectSource::pixmap()) to improve performance. Reported by Andrew Baldwin's performance team. --- src/gui/effects/qgraphicseffect.cpp | 69 +++++++++++-------------------------- 1 file changed, 20 insertions(+), 49 deletions(-) diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 96d35b0..969b6b5 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -1235,64 +1235,35 @@ void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *sour return; } - painter->save(); - painter->setOpacity(d->opacity); QPoint offset; - if (source->isPixmap()) { - // No point in drawing in device coordinates (pixmap will be scaled anyways). - if (!d->hasOpacityMask) { - const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset); - painter->drawPixmap(offset, pixmap); - } else { - QRect srcBrect = source->boundingRect().toAlignedRect(); - offset = srcBrect.topLeft(); - QPixmap pixmap(srcBrect.size()); - pixmap.fill(Qt::transparent); + Qt::CoordinateSystem system = source->isPixmap() ? Qt::LogicalCoordinates : Qt::DeviceCoordinates; + QPixmap pixmap = source->pixmap(system, &offset); + if (pixmap.isNull()) + return; - QPainter pixmapPainter(&pixmap); - pixmapPainter.setRenderHints(painter->renderHints()); - pixmapPainter.translate(-offset); - source->draw(&pixmapPainter); - pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - pixmapPainter.fillRect(srcBrect, d->opacityMask); - pixmapPainter.end(); + painter->save(); + painter->setOpacity(d->opacity); - painter->drawPixmap(offset, pixmap); - } - } else { - // Draw pixmap in device coordinates to avoid pixmap scaling; - if (!d->hasOpacityMask) { - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); - painter->setWorldTransform(QTransform()); - painter->drawPixmap(offset, pixmap); - } else { + if (d->hasOpacityMask) { + QPainter pixmapPainter(&pixmap); + pixmapPainter.setRenderHints(painter->renderHints()); + pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); + if (system == Qt::DeviceCoordinates) { QTransform worldTransform = painter->worldTransform(); - - // Calculate source bounding rect in logical and device coordinates. - QRectF srcBrect = source->boundingRect(); - QRect srcDeviceBrect = worldTransform.mapRect(srcBrect).toAlignedRect(); - srcDeviceBrect &= source->deviceRect(); - - offset = srcDeviceBrect.topLeft(); - worldTransform *= QTransform::fromTranslate(-srcDeviceBrect.x(), -srcDeviceBrect.y()); - - QPixmap pixmap(srcDeviceBrect.size()); - pixmap.fill(Qt::transparent); - - QPainter pixmapPainter(&pixmap); - pixmapPainter.setRenderHints(painter->renderHints()); + worldTransform *= QTransform::fromTranslate(-offset.x(), -offset.y()); pixmapPainter.setWorldTransform(worldTransform); - source->draw(&pixmapPainter); - pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - pixmapPainter.fillRect(srcBrect, d->opacityMask); - pixmapPainter.end(); - - painter->setWorldTransform(QTransform()); - painter->drawPixmap(offset, pixmap); + pixmapPainter.fillRect(source->boundingRect(), d->opacityMask); + } else { + pixmapPainter.translate(-offset); + pixmapPainter.fillRect(pixmap.rect(), d->opacityMask); } } + if (system == Qt::DeviceCoordinates) + painter->setWorldTransform(QTransform()); + + painter->drawPixmap(offset, pixmap); painter->restore(); } -- cgit v0.12