summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgraphicsshadereffect.cpp
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-29 13:46:13 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-29 13:46:13 (GMT)
commit24f041b30f576a2f6ca1cd9e07cba91fc32fac59 (patch)
treef068c9beff2b5c38863cc00092e748552501ebe0 /src/opengl/qgraphicsshadereffect.cpp
parent07c2b17276057a8b47c3be57ab7c2cf66dac0edd (diff)
downloadQt-24f041b30f576a2f6ca1cd9e07cba91fc32fac59.zip
Qt-24f041b30f576a2f6ca1cd9e07cba91fc32fac59.tar.gz
Qt-24f041b30f576a2f6ca1cd9e07cba91fc32fac59.tar.bz2
Conflicts after merge commit 07c2b17276057a8b47c3be57ab7c2cf66dac0edd
Makes QGraphicsShaderEffect compatible with the new QGraphicsEffect API.
Diffstat (limited to 'src/opengl/qgraphicsshadereffect.cpp')
-rw-r--r--src/opengl/qgraphicsshadereffect.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/opengl/qgraphicsshadereffect.cpp b/src/opengl/qgraphicsshadereffect.cpp
index d4f5fa0..e8d9ae3 100644
--- a/src/opengl/qgraphicsshadereffect.cpp
+++ b/src/opengl/qgraphicsshadereffect.cpp
@@ -246,25 +246,11 @@ void QGraphicsShaderEffect::setPixelShaderFragment(const QByteArray& code)
/*!
\reimp
*/
-void QGraphicsShaderEffect::draw(QPainter *painter)
+void QGraphicsShaderEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsShaderEffect);
#ifdef QGL_HAVE_CUSTOM_SHADERS
- // Find the item's bounds in device coordinates.
- QTransform itemToPixmapTransform(painter->worldTransform());
- QRectF deviceBounds = itemToPixmapTransform.mapRect(sourceBoundingRect());
- QRect deviceRect = deviceBounds.toRect().adjusted(-1, -1, 1, 1);
- if (deviceRect.isEmpty())
- return;
-
- if (deviceRect.x() != 0 || deviceRect.y() != 0)
- itemToPixmapTransform *= QTransform::fromTranslate(-deviceRect.x(), -deviceRect.y());
-
- QPixmap pixmap(deviceRect.size());
- if (!d->source->drawIntoPixmap(&pixmap, itemToPixmapTransform))
- return;
-
// Set the custom shader on the paint engine. The setOnPainter()
// call may fail if the paint engine is not GL2. In that case,
// we fall through to drawing the pixmap normally.
@@ -274,17 +260,25 @@ void QGraphicsShaderEffect::draw(QPainter *painter)
}
bool usingShader = d->customShaderStage->setOnPainter(painter);
- // Draw using an untransformed painter.
- QTransform restoreTransform = painter->worldTransform();
- painter->setWorldTransform(QTransform());
- painter->drawPixmap(deviceRect.topLeft(), pixmap);
- painter->setWorldTransform(restoreTransform);
+ QPoint offset;
+ if (source->isPixmap()) {
+ // No point in drawing in device coordinates (pixmap will be scaled anyways).
+ const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset);
+ painter->drawPixmap(offset, pixmap);
+ } else {
+ // Draw pixmap in device coordinates to avoid pixmap scaling.
+ const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset);
+ QTransform restoreTransform = painter->worldTransform();
+ painter->setWorldTransform(QTransform());
+ painter->drawPixmap(offset, pixmap);
+ painter->setWorldTransform(restoreTransform);
+ }
// Remove the custom shader to return to normal painting operations.
if (usingShader)
d->customShaderStage->removeFromPainter(painter);
#else
- drawSource(painter);
+ source->draw(painter);
#endif
}