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
qsgrhisupport_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 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 QSGRHISUPPORT_P_H
5#define QSGRHISUPPORT_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
20
21#include <rhi/qrhi.h>
22
24
25class QSGDefaultRenderContext;
26class QOffscreenSurface;
27class QQuickGraphicsConfiguration;
28
29// Opting in/out of QRhi and choosing the default/requested backend is managed
30// by this singleton. This is because this information may be needed before
31// creating a render loop. A well-written render loop sets up its QRhi and
32// related machinery using the helper functions in here.
33//
34// In addition, the class provides handy conversion and query stuff for the
35// renderloop and the QSGRendererInterface implementations.
36//
37class Q_QUICK_EXPORT QSGRhiSupport
38{
39public:
40 static QSGRhiSupport *instance_internal();
41 static QSGRhiSupport *instance();
42 static int chooseSampleCount(int samples, QRhi *rhi);
43 static int chooseSampleCountForWindowWithRhi(QWindow *window, QRhi *rhi);
44 static QImage grabAndBlockInCurrentFrame(QRhi *rhi, QRhiCommandBuffer *cb, QRhiTexture *src = nullptr);
45 static void checkEnvQSgInfo();
46
47#if QT_CONFIG(opengl)
48 static QRhiTexture::Format toRhiTextureFormatFromGL(uint format, QRhiTexture::Flags *flags);
49#endif
50
51#if QT_CONFIG(vulkan)
52 static QRhiTexture::Format toRhiTextureFormatFromVulkan(uint format, QRhiTexture::Flags *flags);
53#endif
54
55#if defined(Q_OS_WIN)
56 static QRhiTexture::Format toRhiTextureFormatFromDXGI(uint format, QRhiTexture::Flags *flags);
57#endif
58
59#if QT_CONFIG(metal)
60 static QRhiTexture::Format toRhiTextureFormatFromMetal(uint format, QRhiTexture::Flags *flags);
61#endif
62
63 void configure(QSGRendererInterface::GraphicsApi api);
64
65 QRhi::Implementation rhiBackend() const { return m_rhiBackend; }
66 QString rhiBackendName() const;
67 QSGRendererInterface::GraphicsApi graphicsApi() const;
68
69 QSurface::SurfaceType windowSurfaceType() const;
70
71 const void *rifResource(QSGRendererInterface::Resource res,
72 const QSGDefaultRenderContext *rc,
73 const QQuickWindow *w);
74
75 QOffscreenSurface *maybeCreateOffscreenSurface(QWindow *window);
76 struct RhiCreateResult {
77 QRhi *rhi;
78 bool own;
79 };
80 RhiCreateResult createRhi(QQuickWindow *window, QSurface *offscreenSurface, bool forcePreferSwRenderer = false);
81 void destroyRhi(QRhi *rhi, const QQuickGraphicsConfiguration &config);
82 void prepareWindowForRhi(QQuickWindow *window);
83
84 QImage grabOffscreen(QQuickWindow *window);
85#ifdef Q_OS_WEBOS
86 QImage grabOffscreenForProtectedContent(QQuickWindow *window);
87#endif
88
89 void applySwapChainFormat(QRhiSwapChain *scWithWindowSet, QQuickWindow *window);
90
91 QRhiTexture::Format toRhiTextureFormat(uint nativeFormat, QRhiTexture::Flags *flags) const;
92
93 bool attemptReinitWithSwRastUponFail() const;
94
95private:
96 QSGRhiSupport();
97 void applySettings();
98 void adjustToPlatformQuirks();
99 void preparePipelineCache(QRhi *rhi, QQuickWindow *window);
100 void finalizePipelineCache(QRhi *rhi, const QQuickGraphicsConfiguration &config);
101 struct {
102 bool valid = false;
103 QSGRendererInterface::GraphicsApi api;
104 } m_requested;
105 bool m_settingsApplied = false;
106 QRhi::Implementation m_rhiBackend = QRhi::Null;
107};
108
109QT_END_NAMESPACE
110
111#endif // QSGRHISUPPORT_P_H
QAnimationDriver * animationDriver() const override
void update(QQuickWindow *window) override
void renderWindow(QQuickWindow *window)
void releaseSwapchain(QQuickWindow *window)
void show(QQuickWindow *window) override
bool eventFilter(QObject *watched, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
QSGRenderContext * createRenderContext(QSGContext *) const override
void windowDestroyed(QQuickWindow *window) override
bool ensureRhi(QQuickWindow *window, WindowData &data)
QOffscreenSurface * offscreenSurface
void releaseResources(QQuickWindow *) override
void exposureChanged(QQuickWindow *window) override
QSGContext * sceneGraphContext() const override
QHash< QQuickWindow *, WindowData > m_windows
QSet< QSGRenderContext * > pendingRenderContexts
void handleUpdateRequest(QQuickWindow *) override
void hide(QQuickWindow *window) override
QImage grab(QQuickWindow *window) override
void maybeUpdate(QQuickWindow *window) override
bool interleaveIncubation() const override
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QImage grab(QQuickWindow *) override
QSGRenderContext * createRenderContext(QSGContext *) const override
void show(QQuickWindow *) override
bool eventFilter(QObject *watched, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
void postJob(QQuickWindow *window, QRunnable *job) override
QSGContext * sceneGraphContext() const override
void resize(QQuickWindow *window) override
void update(QQuickWindow *window) override
void handleUpdateRequest(QQuickWindow *window) override
QAnimationDriver * animationDriver() const override
void maybeUpdate(QQuickWindow *window) override
void exposureChanged(QQuickWindow *window) override
void releaseResources(QQuickWindow *window) override
void hide(QQuickWindow *) override
void windowDestroyed(QQuickWindow *window) override
bool qsg_useConsistentTiming()
#define ENABLE_DEFAULT_BACKEND
QSGRenderLoopType
@ BasicRenderLoop
@ ThreadedRenderLoop
QSGCustomEvents
@ WM_Exposed
@ WM_Obscure
@ WM_Grab
@ WM_PostJob
@ WM_TryRelease
@ WM_ReleaseSwapchain
@ WM_RequestSync
DEFINE_BOOL_CONFIG_OPTION(forceDiskCache, QML_FORCE_DISK_CACHE)