From 1172e18c3c180f2f3641e6c29688199eb5c46650 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 14 Jan 2016 17:48:38 +0100 Subject: Promote backingstore image format to alpha Like xcb does since 1bcfc3de7586ddb9f5d1b778b97b26ae3dc9584d. For TranslucentBackground (ARGB32_Premultiplied) there is no change in practice. For RGB32 we will promote to ARGB32_Premultiplied but everything should behave like before, except that we do not rely on undefined behavior anymore when QOpenGL/QuickWidget is in use. For RGB16 this will enable QOpenGL/QuickWidget since there the hole punching mechanism needs an alpha channel always. Change-Id: Id04ea548cee245ec91642f1358a5e501b62ff64c Reviewed-by: Friedemann Kleint Reviewed-by: Allan Sandfeld Jensen --- src/plugins/platforms/windows/qwindowsbackingstore.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowsbackingstore.cpp') diff --git a/src/plugins/platforms/windows/qwindowsbackingstore.cpp b/src/plugins/platforms/windows/qwindowsbackingstore.cpp index 135c9eb601..a6b1d0af26 100644 --- a/src/plugins/platforms/windows/qwindowsbackingstore.cpp +++ b/src/plugins/platforms/windows/qwindowsbackingstore.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -52,7 +53,8 @@ QT_BEGIN_NAMESPACE */ QWindowsBackingStore::QWindowsBackingStore(QWindow *window) : - QPlatformBackingStore(window) + QPlatformBackingStore(window), + m_alphaNeedsFill(false) { qCDebug(lcQpaBackingStore) << __FUNCTION__ << this << window; } @@ -144,8 +146,16 @@ void QWindowsBackingStore::resize(const QSize &size, const QRegion ®ion) << " from: " << (m_image.isNull() ? QSize() : m_image->image().size()); } #endif - const QImage::Format format = window()->format().hasAlpha() ? - QImage::Format_ARGB32_Premultiplied : QWindowsNativeImage::systemFormat(); + QImage::Format format = window()->format().hasAlpha() ? + QImage::Format_ARGB32_Premultiplied : QWindowsNativeImage::systemFormat(); + + // The backingstore composition (enabling render-to-texture widgets) + // punches holes in the backingstores using the alpha channel. Hence + // the need for a true alpha format. + if (QImage::toPixelFormat(format).alphaUsage() == QPixelFormat::UsesAlpha) + m_alphaNeedsFill = true; + else // upgrade but here we know app painting does not rely on alpha hence no need to fill + format = qt_alphaVersionForPainting(format); QWindowsNativeImage *oldwni = m_image.data(); QWindowsNativeImage *newwni = new QWindowsNativeImage(size.width(), size.height(), format); @@ -186,7 +196,7 @@ void QWindowsBackingStore::beginPaint(const QRegion ®ion) if (QWindowsContext::verbose > 1) qCDebug(lcQpaBackingStore) <<__FUNCTION__ << region; - if (m_image->image().hasAlphaChannel()) { + if (m_alphaNeedsFill) { QPainter p(&m_image->image()); p.setCompositionMode(QPainter::CompositionMode_Source); const QColor blank = Qt::transparent; -- cgit v1.2.3