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
qquickgraphicsinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
6#include <private/qquickitem_p.h>
7#include <qopenglcontext.h>
8
10
11/*!
12 \qmltype GraphicsInfo
13 \nativetype QQuickGraphicsInfo
14 \inqmlmodule QtQuick
15 \ingroup qtquick-visual
16 \since 5.8
17 \since QtQuick 2.8
18 \brief Provides information about the scenegraph backend and the graphics API used by Qt Quick.
19
20 The GraphicsInfo attached type provides information about the scenegraph
21 backend and the graphics API used to render the contents of the associated window.
22
23 If the item to which the properties are attached is not currently
24 associated with any window, the properties are set to default values. When
25 the associated window changes, the properties will update.
26 */
27
29 : QObject(item)
30 , m_window(nullptr)
31 , m_api(Unknown)
32 , m_shaderType(UnknownShadingLanguage)
33 , m_shaderCompilationType(ShaderCompilationType(0))
34 , m_shaderSourceType(ShaderSourceType(0))
35 , m_majorVersion(2)
36 , m_minorVersion(0)
37 , m_profile(OpenGLNoProfile)
38 , m_renderableType(SurfaceFormatUnspecified)
39{
40 if (Q_LIKELY(item)) {
41 connect(item, &QQuickItem::windowChanged, this, &QQuickGraphicsInfo::setWindow);
42 setWindow(item->window());
43 }
44}
45
46QQuickGraphicsInfo *QQuickGraphicsInfo::qmlAttachedProperties(QObject *object)
47{
48 if (QQuickItem *item = qobject_cast<QQuickItem *>(object))
49 return new QQuickGraphicsInfo(item);
50
51 return nullptr;
52}
53
54/*!
55 \qmlproperty enumeration QtQuick::GraphicsInfo::api
56
57 This property describes the graphics API that is currently in use.
58
59 The possible values are:
60
61 \value GraphicsInfo.Unknown the default value when no active scenegraph is associated with the item
62 \value GraphicsInfo.Software Qt Quick's software renderer based on QPainter with the raster paint engine
63 \value GraphicsInfo.OpenVG OpenVG
64 \value GraphicsInfo.OpenGL OpenGL or OpenGL ES on top of QRhi, a graphics abstraction layer
65 \value GraphicsInfo.Direct3D11 Direct3D 11 on top of QRhi, a graphics abstraction layer
66 \value GraphicsInfo.Direct3D12 Direct3D 12 on top of QRhi, a graphics abstraction layer
67 \value GraphicsInfo.Vulkan Vulkan on top of QRhi, a graphics abstraction layer
68 \value GraphicsInfo.Metal Metal on top of QRhi, a graphics abstraction layer
69 \value GraphicsInfo.Null Null (no output) on top of QRhi, a graphics abstraction layer
70 */
71
72/*!
73 \qmlproperty enumeration QtQuick::GraphicsInfo::shaderType
74
75 This property contains the shading language supported by the Qt Quick
76 backend the application is using.
77
78 \value GraphicsInfo.UnknownShadingLanguage Not yet known due to no window and scenegraph associated
79 \value GraphicsInfo.GLSL GLSL or GLSL ES
80 \value GraphicsInfo.HLSL HLSL
81 \value GraphicsInfo.RhiShader QShader
82
83 \note The value is only up-to-date once the item is associated with a
84 window. Bindings relying on the value have to keep this in mind since the
85 value may change from GraphicsInfo.UnknownShadingLanguage to the actual
86 value after component initialization is complete. This is particularly
87 relevant for ShaderEffect items inside ShaderEffectSource items set as
88 property values.
89
90 \since 5.8
91 \since QtQuick 2.8
92
93 \sa shaderCompilationType, shaderSourceType
94*/
95
96/*!
97 \qmlproperty enumeration QtQuick::GraphicsInfo::shaderCompilationType
98
99 This property contains a bitmask of the shader compilation approaches
100 supported by the Qt Quick backend the application is using.
101
102 \value GraphicsInfo.RuntimeCompilation
103 \value GraphicsInfo.OfflineCompilation
104
105 With OpenGL the value is GraphicsInfo.RuntimeCompilation, which corresponds
106 to the traditional way of using ShaderEffect. Non-OpenGL backends are
107 expected to focus more on GraphicsInfo.OfflineCompilation, however.
108
109 \note The value is only up-to-date once the item is associated with a
110 window. Bindings relying on the value have to keep this in mind since the
111 value may change from \c 0 to the actual bitmask after component
112 initialization is complete. This is particularly relevant for ShaderEffect
113 items inside ShaderEffectSource items set as property values.
114
115 \since 5.8
116 \since QtQuick 2.8
117
118 \sa shaderType, shaderSourceType
119*/
120
121/*!
122 \qmlproperty enumeration QtQuick::GraphicsInfo::shaderSourceType
123
124 This property contains a bitmask of the supported ways of providing shader
125 sources.
126
127 \value GraphicsInfo.ShaderSourceString
128 \value GraphicsInfo.ShaderSourceFile
129 \value GraphicsInfo.ShaderByteCode
130
131 With OpenGL the value is GraphicsInfo.ShaderSourceString, which corresponds
132 to the traditional way of inlining GLSL source code into QML. Other,
133 non-OpenGL Qt Quick backends may however decide not to support inlined
134 shader sources, or even shader sources at all. In this case shaders are
135 expected to be pre-compiled into formats like SPIR-V or D3D shader
136 bytecode.
137
138 \note The value is only up-to-date once the item is associated with a
139 window. Bindings relying on the value have to keep this in mind since the
140 value may change from \c 0 to the actual bitmask after component
141 initialization is complete. This is particularly relevant for ShaderEffect
142 items inside ShaderEffectSource items set as property values.
143
144 \since 5.8
145 \since QtQuick 2.8
146
147 \sa shaderType, shaderCompilationType
148*/
149
150/*!
151 \qmlproperty int QtQuick::GraphicsInfo::majorVersion
152
153 This property holds the major version of the graphics API in use.
154
155 With OpenGL the default version is \c 2.0.
156
157 \note This is applicable only to OpenGL.
158
159 \sa minorVersion, profile
160 */
161
162/*!
163 \qmlproperty int QtQuick::GraphicsInfo::minorVersion
164
165 This property holds the minor version of the graphics API in use.
166
167 With OpenGL the default version is \c 2.0.
168
169 \note This is applicable only to OpenGL.
170
171 \sa majorVersion, profile
172 */
173
174/*!
175 \qmlproperty enumeration QtQuick::GraphicsInfo::profile
176
177 This property holds the configured OpenGL context profile.
178
179 The possible values are:
180
181 \value GraphicsInfo.OpenGLNoProfile (default) OpenGL version is lower than 3.2 or OpenGL is not in use.
182 \value GraphicsInfo.OpenGLCoreProfile Functionality deprecated in OpenGL version 3.0 is not available.
183 \value GraphicsInfo.OpenGLCompatibilityProfile Functionality from earlier OpenGL versions is available.
184
185 Reusable QML components will typically use this property in bindings in order to
186 choose between core and non core profile compatible shader sources.
187
188 \note This is applicable only to OpenGL.
189
190 \sa majorVersion, minorVersion, QSurfaceFormat
191 */
192
193/*!
194 \qmlproperty enumeration QtQuick::GraphicsInfo::renderableType
195
196 This property holds the renderable type. The value has no meaning for APIs
197 other than OpenGL.
198
199 The possible values are:
200
201 \value GraphicsInfo.SurfaceFormatUnspecified (default) Unspecified rendering method
202 \value GraphicsInfo.SurfaceFormatOpenGL Desktop OpenGL or other graphics API
203 \value GraphicsInfo.SurfaceFormatOpenGLES OpenGL ES
204
205 \note This is applicable only to OpenGL.
206
207 \sa QSurfaceFormat
208 */
209
210void QQuickGraphicsInfo::updateInfo()
211{
212 // The queries via the RIF do not depend on isSceneGraphInitialized(), they only need a window.
213 if (m_window) {
214 QSGRendererInterface *rif = m_window->rendererInterface();
215 if (rif) {
216 GraphicsApi newAPI = GraphicsApi(rif->graphicsApi());
217 if (m_api != newAPI) {
218 m_api = newAPI;
219 emit apiChanged();
220 m_shaderType = ShaderType(rif->shaderType());
221 emit shaderTypeChanged();
222 m_shaderCompilationType = ShaderCompilationType(int(rif->shaderCompilationType()));
223 emit shaderCompilationTypeChanged();
224 m_shaderSourceType = ShaderSourceType(int(rif->shaderSourceType()));
225 emit shaderSourceTypeChanged();
226 }
227 }
228 }
229
230 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
231#if QT_CONFIG(opengl)
232 if (m_window && m_window->isSceneGraphInitialized()) {
233 QOpenGLContext *context = QQuickWindowPrivate::get(m_window)->openglContext();
234 if (context)
235 format = context->format();
236 }
237#endif
238 if (m_majorVersion != format.majorVersion()) {
239 m_majorVersion = format.majorVersion();
240 emit majorVersionChanged();
241 }
242 if (m_minorVersion != format.minorVersion()) {
243 m_minorVersion = format.minorVersion();
244 emit minorVersionChanged();
245 }
246 OpenGLContextProfile profile = static_cast<OpenGLContextProfile>(format.profile());
247 if (m_profile != profile) {
248 m_profile = profile;
249 emit profileChanged();
250 }
251 RenderableType renderableType = static_cast<RenderableType>(format.renderableType());
252 if (m_renderableType != renderableType) {
253 m_renderableType = renderableType;
254 emit renderableTypeChanged();
255 }
256}
257
258void QQuickGraphicsInfo::setWindow(QQuickWindow *window)
259{
260 if (m_window != window) {
261 if (m_window) {
262 disconnect(m_window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo()));
263 disconnect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo()));
264 }
265 if (window) {
266 connect(window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo()));
267 connect(window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo()));
268 }
269 m_window = window;
270 }
271 updateInfo();
272}
273
274QT_END_NAMESPACE
275
276#include "moc_qquickgraphicsinfo_p.cpp"
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
QGraphicsItem * item