From aa4fe3286d50e05bf7d521ad8d579062f250bd0a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 27 Oct 2023 11:09:18 +0200 Subject: Fix alpha channel logic in QRhiBackingStore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirror what other platforms such as Windows or xcb do. Those all unconditionally upgrade a non-alpha format such as RGB32 to something like ARGB32_Premultiplied (or whatever qt_maybeAlphaVersionWithSameDepth returns). Without this, there is a discrepancy between macOS and the other platforms when using QOpenGLWidget or QQuickWidget (which trigger the usage of QRhiBackingStore). For example, attempting to have semi-transparent raster widget content over the RHI-based widgets will render incorrectly. This is visible in 6.7 (dev) with the cuberhiwidget example as well: the red semi-transparent overlay is rendered incorrectly on macOS since QRhiBackingStore sticking with a QImage of RGB32 has far-reaching consequences. Upgrading to an alpha format is also required by the "hole punching" mechanism the texture-based widget system relies on, although there is a suspicion that that just happens to look correct with RGB32 as well since there is an alpha channel technically with that format, and alpha writes may not be masked out, depending on painting internals, ending up with RGBA content in practice. But in other cases, like in the report and the one mentioned above this clearly breaks down. Fixes: QTBUG-118553 Pick-to: 6.6 6.5 Change-Id: I4b5b7a4f720377d64903e948b866f8d1c443a2d2 Reviewed-by: Qt CI Bot Reviewed-by: Tor Arne Vestbø --- src/gui/painting/qrhibackingstore.cpp | 14 ++++++++++++++ src/gui/painting/qrhibackingstore_p.h | 1 + 2 files changed, 15 insertions(+) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qrhibackingstore.cpp b/src/gui/painting/qrhibackingstore.cpp index fd7045e3f6..cf13df3765 100644 --- a/src/gui/painting/qrhibackingstore.cpp +++ b/src/gui/painting/qrhibackingstore.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qrhibackingstore_p.h" +#include QT_BEGIN_NAMESPACE @@ -43,4 +44,17 @@ void QRhiBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoin rhiFlush(window, window->devicePixelRatio(), region, offset, &emptyTextureList, translucentBackground); } +QImage::Format QRhiBackingStore::format() const +{ + QImage::Format fmt = QRasterBackingStore::format(); + + // With render-to-texture widgets and QRhi-based flushing the backingstore + // image must have an alpha channel. Hence upgrading the format. Matches + // what other platforms (Windows, xcb) do. + if (QImage::toPixelFormat(fmt).alphaUsage() != QPixelFormat::UsesAlpha) + fmt = qt_maybeAlphaVersionWithSameDepth(fmt); + + return fmt; +} + QT_END_NAMESPACE diff --git a/src/gui/painting/qrhibackingstore_p.h b/src/gui/painting/qrhibackingstore_p.h index 95778fa74c..f222db860f 100644 --- a/src/gui/painting/qrhibackingstore_p.h +++ b/src/gui/painting/qrhibackingstore_p.h @@ -26,6 +26,7 @@ public: ~QRhiBackingStore(); void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override; + QImage::Format format() const override; }; QT_END_NAMESPACE -- cgit v1.2.3