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// Qt-Security score:significant reason:default
4
6#include "qpa/qplatformwindow.h"
7#include <private/qimage_p.h>
8
10
11QRhiBackingStore::QRhiBackingStore(QWindow *window)
12 : QRasterBackingStore(window)
13{
14}
15
16QRhiBackingStore::~QRhiBackingStore()
17{
18}
19
20void QRhiBackingStore::flush(QWindow *flushedWindow, const QRegion &region, const QPoint &offset)
21{
22 Q_UNUSED(region);
23 Q_UNUSED(offset);
24
25 if (!rhi(flushedWindow)) {
26 QPlatformBackingStoreRhiConfig rhiConfig;
27 switch (flushedWindow->surfaceType()) {
28 case QSurface::OpenGLSurface:
29 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::OpenGL);
30 break;
31 case QSurface::MetalSurface:
32 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::Metal);
33 break;
34 case QSurface::Direct3DSurface:
35 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::D3D11);
36 break;
37 case QSurface::VulkanSurface:
38 rhiConfig.setApi(QPlatformBackingStoreRhiConfig::Vulkan);
39 break;
40 default:
41 Q_UNREACHABLE();
42 }
43
44 rhiConfig.setEnabled(true);
45 createRhi(flushedWindow, rhiConfig);
46 }
47
48 // The backing store operates on behalf of its window(), even if we're
49 // flushing a child window, so pull the source DPR from the window().
50 const qreal sourceDevicePixelRatio = window()->devicePixelRatio();
51
52 // QBackingStore::flush will convert the region and offset from device independent
53 // pixels to native pixels before calling QPlatformBackingStore::flush, which means
54 // we can't pass on the window's DPR as the sourceTransformFactor, as that will include
55 // the Qt scale factor, which has already been applied. Instead we ask the platform
56 // window, which only reflect the remaining scale factor from the OS.
57 const qreal sourceTransformFactor = flushedWindow->handle()->devicePixelRatio();
58
59 static QPlatformTextureList emptyTextureList;
60 bool translucentBackground = m_image.hasAlphaChannel();
61 rhiFlush(flushedWindow, sourceDevicePixelRatio,
62 region, offset, &emptyTextureList, translucentBackground,
63 sourceTransformFactor);
64}
65
66QImage::Format QRhiBackingStore::format() const
67{
68 QImage::Format fmt = QRasterBackingStore::format();
69
70 // With render-to-texture widgets and QRhi-based flushing the backingstore
71 // image must have an alpha channel. Hence upgrading the format. Matches
72 // what other platforms (Windows, xcb) do.
73 if (QImage::toPixelFormat(fmt).alphaUsage() != QPixelFormat::UsesAlpha)
74 fmt = qt_maybeDataCompatibleAlphaVersion(fmt);
75
76 return fmt;
77}
78
79QT_END_NAMESPACE
Combined button and popup list for selecting options.