From c78925f487c82f6ffbf9a8bceda8bef4b214bc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Tue, 12 Apr 2022 12:43:07 +0200 Subject: [PATCH] wasm: propagate QWindow format to backing store Qt backing store images should have alpha iff that was requested by the QWindow's surface format. This changes wasm to be in line with the other platforms, and enables use of transparency for Qt windows. Change beginPaint() to clear the backing store only if the format/image has alpha. This is also established behavior Qt's backing stores. Change-Id: Idafe658e24d864f7c4f9e68ee39cb409982b5852 Reviewed-by: Lorn Potter Reviewed-by: David Skoland --- src/plugins/platforms/wasm/qwasmbackingstore.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmbackingstore.cpp b/src/plugins/platforms/wasm/qwasmbackingstore.cpp index 90fb168288..83afa568fb 100644 --- a/src/plugins/platforms/wasm/qwasmbackingstore.cpp +++ b/src/plugins/platforms/wasm/qwasmbackingstore.cpp @@ -156,17 +156,22 @@ void QWasmBackingStore::beginPaint(const QRegion ®ion) resize(backingStore()->size(), backingStore()->staticContents()); QPainter painter(&m_image); - painter.setCompositionMode(QPainter::CompositionMode_Source); - const QColor blank = Qt::transparent; - for (const QRect &rect : region) - painter.fillRect(rect, blank); + + if (m_image.hasAlphaChannel()) { + painter.setCompositionMode(QPainter::CompositionMode_Source); + const QColor blank = Qt::transparent; + for (const QRect &rect : region) + painter.fillRect(rect, blank); + } } void QWasmBackingStore::resize(const QSize &size, const QRegion &staticContents) { Q_UNUSED(staticContents); - m_image = QImage(size * window()->devicePixelRatio(), QImage::Format_RGB32); + QImage::Format format = window()->format().hasAlpha() ? + QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; + m_image = QImage(size * window()->devicePixelRatio(), format); m_image.setDevicePixelRatio(window()->devicePixelRatio()); m_recreateTexture = true; }