mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
plasma: assume QPixmap paint engines support composition
the backbone of QPixmap is QImage Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
2ad07c5a86
commit
174f6a30e0
1 changed files with 19 additions and 48 deletions
|
@ -215,60 +215,31 @@ QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
|
||||||
targetRect.moveCenter(toRect.center());
|
targetRect.moveCenter(toRect.center());
|
||||||
startRect.moveCenter(toRect.center());
|
startRect.moveCenter(toRect.center());
|
||||||
|
|
||||||
//paint to in the center of from, skipping setAlphaF()
|
// paint to in the center of from, skipping setAlphaF()
|
||||||
QColor color(0, 0, 0, amount);
|
QColor color(0, 0, 0, amount);
|
||||||
|
|
||||||
// If the native paint engine supports Porter/Duff compositing and CompositionMode_Plus
|
QPixmap startPixmap(pixmapSize);
|
||||||
QPaintEngine *paintEngine = from.paintEngine();
|
startPixmap.fill(Qt::transparent);
|
||||||
if (paintEngine &&
|
|
||||||
paintEngine->hasFeature(QPaintEngine::PorterDuff) &&
|
|
||||||
paintEngine->hasFeature(QPaintEngine::BlendModes)) {
|
|
||||||
QPixmap startPixmap(pixmapSize);
|
|
||||||
startPixmap.fill(Qt::transparent);
|
|
||||||
|
|
||||||
QPixmap targetPixmap(pixmapSize);
|
QPixmap targetPixmap(pixmapSize);
|
||||||
targetPixmap.fill(Qt::transparent);
|
targetPixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
QPainter p;
|
QPainter p;
|
||||||
p.begin(&targetPixmap);
|
p.begin(&targetPixmap);
|
||||||
p.drawPixmap(targetRect, to);
|
p.drawPixmap(targetRect, to);
|
||||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||||
p.fillRect(targetRect, color);
|
p.fillRect(targetRect, color);
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
p.begin(&startPixmap);
|
p.begin(&startPixmap);
|
||||||
p.drawPixmap(startRect, from);
|
p.drawPixmap(startRect, from);
|
||||||
p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
|
p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
|
||||||
p.fillRect(startRect, color);
|
p.fillRect(startRect, color);
|
||||||
p.setCompositionMode(QPainter::CompositionMode_Plus);
|
p.setCompositionMode(QPainter::CompositionMode_Plus);
|
||||||
p.drawPixmap(targetRect, targetPixmap);
|
p.drawPixmap(targetRect, targetPixmap);
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
return startPixmap;
|
return startPixmap;
|
||||||
} else {
|
|
||||||
// Fall back to using QRasterPaintEngine to do the transition.
|
|
||||||
QImage under(pixmapSize, QImage::Format_ARGB32_Premultiplied);
|
|
||||||
under.fill(Qt::transparent);
|
|
||||||
QImage over(pixmapSize, QImage::Format_ARGB32_Premultiplied);
|
|
||||||
over.fill(Qt::transparent);
|
|
||||||
|
|
||||||
QPainter p;
|
|
||||||
p.begin(&over);
|
|
||||||
p.drawPixmap(targetRect, to);
|
|
||||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
||||||
p.fillRect(over.rect(), color);
|
|
||||||
p.end();
|
|
||||||
|
|
||||||
p.begin(&under);
|
|
||||||
p.drawPixmap(startRect, from);
|
|
||||||
p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
|
|
||||||
p.fillRect(startRect, color);
|
|
||||||
p.setCompositionMode(QPainter::CompositionMode_Plus);
|
|
||||||
p.drawImage(toRect.topLeft(), over);
|
|
||||||
p.end();
|
|
||||||
|
|
||||||
return QPixmap::fromImage(under);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // PaintUtils namespace
|
} // PaintUtils namespace
|
||||||
|
|
Loading…
Add table
Reference in a new issue