summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-10-29 17:50:55 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-10-29 18:07:59 (GMT)
commit27c99302d0b44c6e9cd0eda6ba888b6a6f5bea38 (patch)
tree807ffa3025541fc3d12db98d5166bab5994dbe5b /src/gui
parent02d815b4bd497a5c7f07330576a5e3c3da3f46ab (diff)
downloadQt-27c99302d0b44c6e9cd0eda6ba888b6a6f5bea38.zip
Qt-27c99302d0b44c6e9cd0eda6ba888b6a6f5bea38.tar.gz
Qt-27c99302d0b44c6e9cd0eda6ba888b6a6f5bea38.tar.bz2
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.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/effects/qgraphicseffect.cpp69
1 files 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();
}