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