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// Qt-Security score:significant reason:default
4
5#ifndef QSGRHISUPPORT_P_H
6#define QSGRHISUPPORT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
21
22#include <rhi/qrhi.h>
23
25
26class QSGDefaultRenderContext;
27class QOffscreenSurface;
28class QQuickGraphicsConfiguration;
29
30// Opting in/out of QRhi and choosing the default/requested backend is managed
31// by this singleton. This is because this information may be needed before
32// creating a render loop. A well-written render loop sets up its QRhi and
33// related machinery using the helper functions in here.
34//
35// In addition, the class provides handy conversion and query stuff for the
36// renderloop and the QSGRendererInterface implementations.
37//
38class Q_QUICK_EXPORT QSGRhiSupport
39{
40public:
41 static QSGRhiSupport *instance_internal();
42 static QSGRhiSupport *instance();
43 static int chooseSampleCount(int samples, QRhi *rhi);
44 static int chooseSampleCountForWindowWithRhi(QWindow *window, QRhi *rhi);
45 static QImage grabAndBlockInCurrentFrame(QRhi *rhi, QRhiCommandBuffer *cb, QRhiTexture *src = nullptr);
46 static void checkEnvQSgInfo();
47
48#if QT_CONFIG(opengl)
49 static QRhiTexture::Format toRhiTextureFormatFromGL(uint format, QRhiTexture::Flags *flags);
50#endif
51
52#if QT_CONFIG(vulkan)
53 static QRhiTexture::Format toRhiTextureFormatFromVulkan(uint format, QRhiTexture::Flags *flags);
54#endif
55
56#if defined(Q_OS_WIN)
57 static QRhiTexture::Format toRhiTextureFormatFromDXGI(uint format, QRhiTexture::Flags *flags);
58#endif
59
60#if QT_CONFIG(metal)
61 static QRhiTexture::Format toRhiTextureFormatFromMetal(uint format, QRhiTexture::Flags *flags);
62#endif
63
64 void configure(QSGRendererInterface::GraphicsApi api);
65
66 QRhi::Implementation rhiBackend() const { return m_rhiBackend; }
67 QString rhiBackendName() const;
68 QSGRendererInterface::GraphicsApi graphicsApi() const;
69
70 QSurface::SurfaceType windowSurfaceType() const;
71
72 const void *rifResource(QSGRendererInterface::Resource res,
73 const QSGDefaultRenderContext *rc,
74 const QQuickWindow *w);
75
76 QOffscreenSurface *maybeCreateOffscreenSurface(QWindow *window);
77 struct RhiCreateResult {
78 QRhi *rhi;
79 bool own;
80 };
81 RhiCreateResult createRhi(QQuickWindow *window, QSurface *offscreenSurface, bool forcePreferSwRenderer = false);
82 void destroyRhi(QRhi *rhi, const QQuickGraphicsConfiguration &config);
83 void prepareWindowForRhi(QQuickWindow *window);
84
85 QImage grabOffscreen(QQuickWindow *window);
86#ifdef Q_OS_WEBOS
87 QImage grabOffscreenForProtectedContent(QQuickWindow *window);
88#endif
89
90 void applySwapChainFormat(QRhiSwapChain *scWithWindowSet, QQuickWindow *window);
91
92 QRhiTexture::Format toRhiTextureFormat(uint nativeFormat, QRhiTexture::Flags *flags) const;
93
94 bool attemptReinitWithSwRastUponFail() const;
95
96private:
97 QSGRhiSupport();
98 void applySettings();
99 void adjustToPlatformQuirks();
100 void preparePipelineCache(QRhi *rhi, QQuickWindow *window);
101 void finalizePipelineCache(QRhi *rhi, const QQuickGraphicsConfiguration &config);
102 struct {
103 bool valid = false;
104 QSGRendererInterface::GraphicsApi api;
105 } m_requested;
106 bool m_settingsApplied = false;
107 QRhi::Implementation m_rhiBackend = QRhi::Null;
108};
109
110QT_END_NAMESPACE
111
112#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
Combined button and popup list for selecting options.
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)