From 8a4fd01bf39b13fb189784596521d4752b08dfda Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 20 Oct 2023 16:56:02 +0200 Subject: [PATCH] Do automatic r-b swap in QVulkanWindow's grab for BGRA8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it would also be acceptable to leave this conversion to the user, the returned image's format (that it's QImage::Format_RGBA8888) is not documented. That needs to be corrected in any case. Then, we may just as well add and document that for the most commonly used swapchain color buffer format the r-b swap is performed automatically. Pick-to: 6.5 6.2 Fixes: QTBUG-118244 Change-Id: I7ec8324ec3a0f5c1f2a7a592501d5ff59e3e8cc5 Reviewed-by: Kristoffer Skau Reviewed-by: Christian Strømme (cherry picked from commit 7a3261c196e5e7d5b13ff2746faeedb979944d22) Reviewed-by: Qt Cherry-pick Bot --- src/gui/vulkan/qvulkanwindow.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/vulkan/qvulkanwindow.cpp b/src/gui/vulkan/qvulkanwindow.cpp index 3efc37e7a6b..185ec507c7d 100644 --- a/src/gui/vulkan/qvulkanwindow.cpp +++ b/src/gui/vulkan/qvulkanwindow.cpp @@ -1927,7 +1927,7 @@ void QVulkanWindowPrivate::beginFrame() } if (frameGrabbing) - frameGrabTargetImage = QImage(swapChainImageSize, QImage::Format_RGBA8888); + frameGrabTargetImage = QImage(swapChainImageSize, QImage::Format_RGBA8888); // the format is as documented if (renderer) { framePending = true; @@ -2714,6 +2714,12 @@ bool QVulkanWindow::supportsGrab() const incomplete image, that has the correct size but not the content yet. The content will be delivered via the frameGrabbed() signal in the latter case. + The returned QImage always has a format of QImage::Format_RGBA8888. If the + colorFormat() is \c VK_FORMAT_B8G8R8A8_UNORM, the red and blue channels are + swapped automatically since this format is commonly used as the default + choice for swapchain color buffers. With any other color buffer format, + there is no conversion performed by this function. + \note This function should not be called when a frame is in progress (that is, frameReady() has not yet been called back by the application). @@ -2742,6 +2748,9 @@ QImage QVulkanWindow::grab() d->frameGrabbing = true; d->beginFrame(); + if (d->colorFormat == VK_FORMAT_B8G8R8A8_UNORM) + d->frameGrabTargetImage = d->frameGrabTargetImage.rgbSwapped(); + return d->frameGrabTargetImage; }