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 static QRhiRenderBuffer::Flags depthStencilBufferFlags();
48
49#if QT_CONFIG(opengl)
50 static QRhiTexture::Format toRhiTextureFormatFromGL(uint format, QRhiTexture::Flags *flags);
51#endif
52
53#if QT_CONFIG(vulkan)
54 static QRhiTexture::Format toRhiTextureFormatFromVulkan(uint format, QRhiTexture::Flags *flags);
55#endif
56
57#if defined(Q_OS_WIN)
58 static QRhiTexture::Format toRhiTextureFormatFromDXGI(uint format, QRhiTexture::Flags *flags);
59#endif
60
61#if QT_CONFIG(metal)
62 static QRhiTexture::Format toRhiTextureFormatFromMetal(uint format, QRhiTexture::Flags *flags);
63#endif
64
65 void configure(QSGRendererInterface::GraphicsApi api);
66
67 QRhi::Implementation rhiBackend() const { return m_rhiBackend; }
68 QString rhiBackendName() const;
69 QSGRendererInterface::GraphicsApi graphicsApi() const;
70
71 QSurface::SurfaceType windowSurfaceType() const;
72
73 const void *rifResource(QSGRendererInterface::Resource res,
74 const QSGDefaultRenderContext *rc,
75 const QQuickWindow *w);
76
77 QOffscreenSurface *maybeCreateOffscreenSurface(QWindow *window);
78 struct RhiCreateResult {
79 QRhi *rhi;
80 bool own;
81 };
82 RhiCreateResult createRhi(QQuickWindow *window, QSurface *offscreenSurface, bool forcePreferSwRenderer = false);
83 void destroyRhi(QRhi *rhi, const QQuickGraphicsConfiguration &config);
84 void prepareWindowForRhi(QQuickWindow *window);
85
86 QImage grabOffscreen(QQuickWindow *window);
87#ifdef Q_OS_WEBOS
88 QImage grabOffscreenForProtectedContent(QQuickWindow *window);
89#endif
90
91 void applySwapChainFormat(QRhiSwapChain *scWithWindowSet, QQuickWindow *window);
92
93 QRhiTexture::Format toRhiTextureFormat(uint nativeFormat, QRhiTexture::Flags *flags) const;
94
95 bool attemptReinitWithSwRastUponFail() const;
96
97private:
98 QSGRhiSupport();
99 void applySettings();
100 void adjustToPlatformQuirks();
101 void preparePipelineCache(QRhi *rhi, QQuickWindow *window);
102 void finalizePipelineCache(QRhi *rhi, const QQuickGraphicsConfiguration &config);
103 struct {
104 bool valid = false;
105 QSGRendererInterface::GraphicsApi api;
106 } m_requested;
107 bool m_settingsApplied = false;
108 QRhi::Implementation m_rhiBackend = QRhi::Null;
109};
110
111QT_END_NAMESPACE
112
113#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)