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
qsgnode.h
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
5#ifndef QSGNODE_H
6#define QSGNODE_H
7
8#include <QtCore/qlist.h>
9#include <QtQuick/qsggeometry.h>
10#include <QtGui/QMatrix4x4>
11
12#include <float.h>
13
15
16#ifndef QT_NO_DEBUG
17#define QSG_RUNTIME_DESCRIPTION
18#endif
19
20class QSGAbstractRenderer;
21class QSGRenderer;
22
23class QSGNode;
24class QSGRootNode;
25class QSGGeometryNode;
26class QSGTransformNode;
27class QSGClipNode;
28class QSGNodePrivate;
31
32namespace QSGBatchRenderer {
33 class Renderer;
34 class Updater;
35}
36
37class Q_QUICK_EXPORT QSGNode
38{
39public:
40 enum NodeType {
41 BasicNodeType,
42 GeometryNodeType,
43 TransformNodeType,
44 ClipNodeType,
45 OpacityNodeType,
46 RootNodeType,
47 RenderNodeType
48 };
49
50 enum Flag {
51 // Lower 16 bites reserved for general node
52 OwnedByParent = 0x0001,
53 UsePreprocess = 0x0002,
54
55 // 0x00ff0000 bits reserved for node subclasses
56
57 // QSGBasicGeometryNode
58 OwnsGeometry = 0x00010000,
59 OwnsMaterial = 0x00020000,
60 OwnsOpaqueMaterial = 0x00040000,
61
62 // Uppermost 8 bits are reserved for internal use.
63 IsVisitableNode = 0x01000000
64#ifdef Q_QDOC
65 , InternalReserved = 0x01000000
66#endif
67 };
68 Q_DECLARE_FLAGS(Flags, Flag)
69
70 enum DirtyStateBit {
71 DirtySubtreeBlocked = 0x0080,
72 DirtyMatrix = 0x0100,
73 DirtyNodeAdded = 0x0400,
74 DirtyNodeRemoved = 0x0800,
75 DirtyGeometry = 0x1000,
76 DirtyMaterial = 0x2000,
77 DirtyOpacity = 0x4000,
78
79 DirtyForceUpdate = 0x8000,
80
81 DirtyUsePreprocess = UsePreprocess,
82
83 DirtyPropagationMask = DirtyMatrix
84 | DirtyNodeAdded
85 | DirtyOpacity
86 | DirtyForceUpdate
87
88 };
89 Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)
90
91 QSGNode();
92 virtual ~QSGNode();
93
94 QSGNode *parent() const { return m_parent; }
95
96 void removeChildNode(QSGNode *node);
97 void removeAllChildNodes();
98 void prependChildNode(QSGNode *node);
99 void appendChildNode(QSGNode *node);
100 void insertChildNodeBefore(QSGNode *node, QSGNode *before);
101 void insertChildNodeAfter(QSGNode *node, QSGNode *after);
102 void reparentChildNodesTo(QSGNode *newParent);
103
104 int childCount() const;
105 QSGNode *childAtIndex(int i) const;
106 QSGNode *firstChild() const { return m_firstChild; }
107 QSGNode *lastChild() const { return m_lastChild; }
108 QSGNode *nextSibling() const { return m_nextSibling; }
109 QSGNode* previousSibling() const { return m_previousSibling; }
110
111 inline NodeType type() const { return m_type; }
112
113 QT_DEPRECATED void clearDirty() { }
114 void markDirty(DirtyState bits);
115 QT_DEPRECATED DirtyState dirtyState() const { return { }; }
116
117 virtual bool isSubtreeBlocked() const;
118
119 Flags flags() const { return m_nodeFlags; }
120 void setFlag(Flag, bool = true);
121 void setFlags(Flags, bool = true);
122
123 virtual void preprocess() { }
124
125protected:
126 QSGNode(NodeType type);
127 QSGNode(QSGNodePrivate &dd, NodeType type);
128
129private:
130 friend class QSGRootNode;
131 friend class QSGBatchRenderer::Renderer;
132 friend class QSGRenderer;
133
134 void init();
135 void destroy();
136
137 QSGNode *m_parent = nullptr;
138 NodeType m_type = BasicNodeType;
139 QSGNode *m_firstChild = nullptr;
140 QSGNode *m_lastChild = nullptr;
141 QSGNode *m_nextSibling = nullptr;
142 QSGNode *m_previousSibling = nullptr;
143 int m_subtreeRenderableCount = 0;
144
145 Flags m_nodeFlags;
146
147protected:
148 friend class QSGNodePrivate;
149
150 QScopedPointer<QSGNodePrivate> d_ptr;
151};
152
153void Q_QUICK_EXPORT qsgnode_set_description(QSGNode *node, const QString &description);
154
155class Q_QUICK_EXPORT QSGBasicGeometryNode : public QSGNode
156{
157public:
158 ~QSGBasicGeometryNode() override;
159
160 void setGeometry(QSGGeometry *geometry);
161 const QSGGeometry *geometry() const { return m_geometry; }
162 QSGGeometry *geometry() { return m_geometry; }
163
164 const QMatrix4x4 *matrix() const { return m_matrix; }
165 const QSGClipNode *clipList() const { return m_clip_list; }
166
167 void setRendererMatrix(const QMatrix4x4 *m) { m_matrix = m; }
168 void setRendererClipList(const QSGClipNode *c) { m_clip_list = c; }
169
170protected:
171 QSGBasicGeometryNode(NodeType type);
172 QSGBasicGeometryNode(QSGBasicGeometryNodePrivate &dd, NodeType type);
173
174private:
175 friend class QSGNodeUpdater;
176
177 QSGGeometry *m_geometry;
178
179 Q_DECL_UNUSED_MEMBER int m_reserved_start_index;
180 Q_DECL_UNUSED_MEMBER int m_reserved_end_index;
181
182 const QMatrix4x4 *m_matrix;
183 const QSGClipNode *m_clip_list;
184};
185
186class QSGMaterial;
187
188class Q_QUICK_EXPORT QSGGeometryNode : public QSGBasicGeometryNode
189{
190public:
191 QSGGeometryNode();
192 ~QSGGeometryNode() override;
193
194 void setMaterial(QSGMaterial *material);
195 QSGMaterial *material() const { return m_material; }
196
197 void setOpaqueMaterial(QSGMaterial *material);
198 QSGMaterial *opaqueMaterial() const { return m_opaque_material; }
199
200 QSGMaterial *activeMaterial() const;
201
202 void setRenderOrder(int order);
203 int renderOrder() const { return m_render_order; }
204
205 void setInheritedOpacity(qreal opacity);
206 qreal inheritedOpacity() const { return m_opacity; }
207
208protected:
209 QSGGeometryNode(QSGGeometryNodePrivate &dd);
210
211private:
212 friend class QSGNodeUpdater;
213
214 int m_render_order = 0;
215 QSGMaterial *m_material = nullptr;
216 QSGMaterial *m_opaque_material = nullptr;
217
218 qreal m_opacity = 1;
219};
220
221class Q_QUICK_EXPORT QSGClipNode : public QSGBasicGeometryNode
222{
223public:
224 QSGClipNode();
225 ~QSGClipNode() override;
226
227 void setIsRectangular(bool rectHint);
228 bool isRectangular() const { return m_is_rectangular; }
229
230 void setClipRect(const QRectF &);
231 QRectF clipRect() const { return m_clip_rect; }
232
233private:
234 uint m_is_rectangular : 1;
235 uint m_reserved : 31;
236
237 QRectF m_clip_rect;
238};
239
240
241class Q_QUICK_EXPORT QSGTransformNode : public QSGNode
242{
243public:
244 QSGTransformNode();
245 ~QSGTransformNode() override;
246
247 void setMatrix(const QMatrix4x4 &matrix);
248 const QMatrix4x4 &matrix() const { return m_matrix; }
249
250 void setCombinedMatrix(const QMatrix4x4 &matrix);
251 const QMatrix4x4 &combinedMatrix() const { return m_combined_matrix; }
252
253private:
254 QMatrix4x4 m_matrix;
255 QMatrix4x4 m_combined_matrix;
256};
257
258
259class Q_QUICK_EXPORT QSGRootNode : public QSGNode
260{
261public:
262 QSGRootNode();
263 ~QSGRootNode() override;
264
265private:
266 void notifyNodeChange(QSGNode *node, DirtyState state);
267
268 friend class QSGAbstractRenderer;
269 friend class QSGNode;
270 friend class QSGGeometryNode;
271
272 QList<QSGAbstractRenderer *> m_renderers;
273};
274
275
276class Q_QUICK_EXPORT QSGOpacityNode : public QSGNode
277{
278public:
279 QSGOpacityNode();
280 ~QSGOpacityNode() override;
281
282 void setOpacity(qreal opacity);
283 qreal opacity() const { return m_opacity; }
284
285 void setCombinedOpacity(qreal opacity);
286 qreal combinedOpacity() const { return m_combined_opacity; }
287
288 bool isSubtreeBlocked() const override;
289
290private:
291 qreal m_opacity = 1;
292 qreal m_combined_opacity = 1;
293};
294
295class Q_QUICK_EXPORT QSGNodeVisitor {
296public:
297 virtual ~QSGNodeVisitor();
298
299protected:
300 virtual void enterTransformNode(QSGTransformNode *) {}
301 virtual void leaveTransformNode(QSGTransformNode *) {}
302 virtual void enterClipNode(QSGClipNode *) {}
303 virtual void leaveClipNode(QSGClipNode *) {}
304 virtual void enterGeometryNode(QSGGeometryNode *) {}
305 virtual void leaveGeometryNode(QSGGeometryNode *) {}
306 virtual void enterOpacityNode(QSGOpacityNode *) {}
307 virtual void leaveOpacityNode(QSGOpacityNode *) {}
308 virtual void visitNode(QSGNode *n);
309 virtual void visitChildren(QSGNode *n);
310};
311
312#ifndef QT_NO_DEBUG_STREAM
313Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGNode *n);
314Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGGeometryNode *n);
315Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGTransformNode *n);
316Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGOpacityNode *n);
317Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGRootNode *n);
318
319#endif
320
321Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::DirtyState)
322Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::Flags)
323
324QT_END_NAMESPACE
325
326#endif // QSGNODE_H
QSGAbstractRenderer gives access to the scene graph nodes and rendering.
The QSGBasicGeometryNode class serves as a baseclass for geometry based nodes.
Definition qsgnode.h:156
The QSGClipNode class implements the clipping functionality in the scene graph.
Definition qsgnode.h:222
The QSGGeometryNode class is used for all rendered content in the scene graph.
Definition qsgnode.h:189
The QSGNodeVisitor class is a helper class for traversing the scene graph.
Definition qsgnode.h:295
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:38
The QSGOpacityNode class is used to change opacity of nodes.
Definition qsgnode.h:277
The QSGRootNode is the toplevel root of any scene graph.
Definition qsgnode.h:260
The QSGTransformNode class implements transformations in the scene graph.
Definition qsgnode.h:242
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item)