diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-10-27 11:09:18 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-10-31 20:20:11 +0200 |
commit | aa4fe3286d50e05bf7d521ad8d579062f250bd0a (patch) | |
tree | 3e7ac25aecf5347613cf392e2735a39e854b8286 /src/gui/painting | |
parent | 522d9fcfe40a107779f6e21d83195fafa67fb064 (diff) |
Fix alpha channel logic in QRhiBackingStore
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qrhibackingstore.cpp | 14 | ||||
-rw-r--r-- | src/gui/painting/qrhibackingstore_p.h | 1 |
2 files changed, 15 insertions, 0 deletions
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 <private/qimage_p.h> 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 |