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
18#include "qsgrenderloop_p.h"
19#include "qsgrendererinterface.h"
20
21#include <rhi/qrhi.h>
22
23QT_BEGIN_NAMESPACE
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_PRIVATE_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);
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 defined(Q_OS_MACOS) || defined(Q_OS_IOS)
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);
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
93private:
94 QSGRhiSupport();
95 void applySettings();
96 void adjustToPlatformQuirks();
97 void preparePipelineCache(QRhi *rhi, QQuickWindow *window);
98 void finalizePipelineCache(QRhi *rhi, const QQuickGraphicsConfiguration &config);
99 struct {
100 bool valid = false;
101 QSGRendererInterface::GraphicsApi api;
102 } m_requested;
103 bool m_settingsApplied = false;
104 QRhi::Implementation m_rhiBackend = QRhi::Null;
105};
106
107QT_END_NAMESPACE
108
109#endif // QSGRHISUPPORT_P_H
110

source code of qtdeclarative/src/quick/scenegraph/qsgrhisupport_p.h