Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qrhibackingstore.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qpa/qplatformwindow.h"
6#include <private/qimage_p.h>
7
9
10QRhiBackingStore::QRhiBackingStore(QWindow *window)
11 : QRasterBackingStore(window)
12{
13}
14
15QRhiBackingStore::~QRhiBackingStore()
16{
17}
18
19void QRhiBackingStore::flush(QWindow *flushedWindow, const QRegion &region, const QPoint &offset)
20{
21 Q_UNUSED(region);
22 Q_UNUSED(offset);
23
24 if (!rhi(flushedWindow)) {
25 QPlatformBackingStoreRhiConfig rhiConfig;
26 switch (flushedWindow->surfaceType()) {
27 case QSurface::OpenGLSurface:
28 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::OpenGL);
29 break;
30 case QSurface::MetalSurface:
31 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::Metal);
32 break;
33 case QSurface::Direct3DSurface:
34 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::D3D11);
35 break;
36 case QSurface::VulkanSurface:
37 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::Vulkan);
38 break;
39 default:
40 Q_UNREACHABLE();
41 }
42
43 rhiConfig.setEnabled(true);
44 createRhi(flushedWindow, rhiConfig);
45 }
46
47 // The backing store operates on behalf of its window(), even if we're
48 // flushing a child window, so pull the source DPR from the window().
49 const qreal sourceDevicePixelRatio = window()->devicePixelRatio();
50
51 // QBackingStore::flush will convert the region and offset from device independent
52 // pixels to native pixels before calling QPlatformBackingStore::flush, which means
53 // we can't pass on the window's DPR as the sourceTransformFactor, as that will include
54 // the Qt scale factor, which has already been applied. Instead we ask the platform
55 // window, which only reflect the remaining scale factor from the OS.
56 const qreal sourceTransformFactor = flushedWindow->handle()->devicePixelRatio();
57
58 static QPlatformTextureList emptyTextureList;
59 bool translucentBackground = m_image.hasAlphaChannel();
60 rhiFlush(flushedWindow, sourceDevicePixelRatio,
61 region, offset, &emptyTextureList, translucentBackground,
62 sourceTransformFactor);
63}
64
65QImage::Format QRhiBackingStore::format() const
66{
67 QImage::Format fmt = QRasterBackingStore::format();
68
69 // With render-to-texture widgets and QRhi-based flushing the backingstore
70 // image must have an alpha channel. Hence upgrading the format. Matches
71 // what other platforms (Windows, xcb) do.
72 if (QImage::toPixelFormat(fmt).alphaUsage() != QPixelFormat::UsesAlpha)
73 fmt = qt_maybeDataCompatibleAlphaVersion(fmt);
74
75 return fmt;
76}
77
78QT_END_NAMESPACE