offscreen: Enable backingstore images with alpha
Grabbing a QQuickWindow (software backend) cleared to something semi-transparent is not going to be correct otherwise. Pick-to: 6.9 6.8 Task-number: QTBUG-136755 Change-Id: I59f378b177154af25b1d7bff878435c715e3d114 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
44b5602536
commit
97f7819f1d
@ -148,7 +148,9 @@ void QOffscreenBackingStore::flush(QWindow *window, const QRegion ®ion, const
|
||||
|
||||
void QOffscreenBackingStore::resize(const QSize &size, const QRegion &)
|
||||
{
|
||||
QImage::Format format = QGuiApplication::primaryScreen()->handle()->format();
|
||||
QImage::Format format = window()->format().hasAlpha()
|
||||
? QImage::Format_ARGB32_Premultiplied
|
||||
: QGuiApplication::primaryScreen()->handle()->format();
|
||||
if (m_image.size() != size)
|
||||
m_image = QImage(size, format);
|
||||
clearHash();
|
||||
@ -167,6 +169,17 @@ bool QOffscreenBackingStore::scroll(const QRegion &area, int dx, int dy)
|
||||
return true;
|
||||
}
|
||||
|
||||
void QOffscreenBackingStore::beginPaint(const QRegion ®ion)
|
||||
{
|
||||
if (QImage::toPixelFormat(m_image.format()).alphaUsage() == QPixelFormat::UsesAlpha) {
|
||||
QPainter p(&m_image);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
const QColor blank = Qt::transparent;
|
||||
for (const QRect &r : region)
|
||||
p.fillRect(r, blank);
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap QOffscreenBackingStore::grabWindow(WId window, const QRect &rect) const
|
||||
{
|
||||
QRect area = m_windowAreaHash.value(window, QRect());
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override;
|
||||
void resize(const QSize &size, const QRegion &staticContents) override;
|
||||
bool scroll(const QRegion &area, int dx, int dy) override;
|
||||
void beginPaint(const QRegion &) override;
|
||||
|
||||
QPixmap grabWindow(WId window, const QRect &rect) const;
|
||||
QImage toImage() const override { return m_image; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user