1 | // Copyright (C) 2021 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 | |
4 | #ifndef QBACKINGSTORERHISUPPORT_P_H |
5 | #define QBACKINGSTORERHISUPPORT_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtGui/private/qtguiglobal_p.h> |
19 | #include <QtGui/qwindow.h> |
20 | #include <QtGui/qsurfaceformat.h> |
21 | #include <QtGui/qoffscreensurface.h> |
22 | #include <rhi/qrhi.h> |
23 | #include <qpa/qplatformbackingstore.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class Q_GUI_EXPORT QBackingStoreRhiSupport |
28 | { |
29 | public: |
30 | ~QBackingStoreRhiSupport(); |
31 | |
32 | void reset(); |
33 | |
34 | void setFormat(const QSurfaceFormat &format) { m_format = format; } |
35 | void setWindow(QWindow *window) { m_window = window; } |
36 | void setConfig(const QPlatformBackingStoreRhiConfig &config) { m_config = config; } |
37 | |
38 | bool create(); |
39 | |
40 | QRhiSwapChain *swapChainForWindow(QWindow *window); |
41 | |
42 | static QSurface::SurfaceType surfaceTypeForConfig(const QPlatformBackingStoreRhiConfig &config); |
43 | |
44 | static bool checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType); |
45 | |
46 | static QRhi::Implementation apiToRhiBackend(QPlatformBackingStoreRhiConfig::Api api); |
47 | |
48 | QRhi *rhi() const { return m_rhi; } |
49 | |
50 | private: |
51 | QSurfaceFormat m_format; |
52 | QWindow *m_window = nullptr; |
53 | QPlatformBackingStoreRhiConfig m_config; |
54 | QRhi *m_rhi = nullptr; |
55 | QOffscreenSurface *m_openGLFallbackSurface = nullptr; |
56 | struct SwapchainData { |
57 | QRhiSwapChain *swapchain = nullptr; |
58 | QRhiRenderPassDescriptor *renderPassDescriptor = nullptr; |
59 | QObject *windowWatcher = nullptr; |
60 | void reset(); |
61 | }; |
62 | QHash<QWindow *, SwapchainData> m_swapchains; |
63 | friend class QBackingStoreRhiSupportWindowWatcher; |
64 | }; |
65 | |
66 | class QBackingStoreRhiSupportWindowWatcher : public QObject |
67 | { |
68 | public: |
69 | QBackingStoreRhiSupportWindowWatcher(QBackingStoreRhiSupport *rhiSupport) : m_rhiSupport(rhiSupport) { } |
70 | bool eventFilter(QObject *obj, QEvent *ev) override; |
71 | private: |
72 | QBackingStoreRhiSupport *m_rhiSupport; |
73 | }; |
74 | |
75 | QT_END_NAMESPACE |
76 | |
77 | #endif // QBACKINGSTORERHISUPPORT_P_H |
78 |