Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsgsoftwarerenderablenodeupdater.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
5
13
14#include <QtQuick/qsgsimplerectnode.h>
15#include <QtQuick/qsgsimpletexturenode.h>
16#include <QtQuick/qsgrendernode.h>
17
19
21 : m_renderer(renderer)
22{
23 m_opacityState.push(1.0f);
24 // Invalid RectF by default for no clip
25 m_clipState.push(QRegion());
26 m_hasClip = false;
27 m_transformState.push(QTransform());
28}
29
34
36{
37 m_transformState.push(node->matrix().toTransform() * m_transformState.top());
38 m_stateMap[node] = currentState(node);
39 return true;
40}
41
46
48{
49 // Make sure to translate the clip rect into world coordinates
50 if (m_clipState.size() == 0 || (m_clipState.size() == 1 && m_clipState.top().isNull())) {
51 m_clipState.push(m_transformState.top().map(QRegion(node->clipRect().toRect())));
52 m_hasClip = true;
53 } else {
54 const QRegion transformedClipRect = m_transformState.top().map(QRegion(node->clipRect().toRect()));
55 m_clipState.push(transformedClipRect.intersected(m_clipState.top()));
56 }
57 m_stateMap[node] = currentState(node);
58 return true;
59}
60
62{
63 m_clipState.pop();
64 if (m_clipState.size() == 0 || (m_clipState.size() == 1 && m_clipState.top().isNull()))
65 m_hasClip = false;
66}
67
69{
70 if (QSGSimpleRectNode *rectNode = dynamic_cast<QSGSimpleRectNode *>(node)) {
71 return updateRenderableNode(QSGSoftwareRenderableNode::SimpleRect, rectNode);
72 } else if (QSGSimpleTextureNode *tn = dynamic_cast<QSGSimpleTextureNode *>(node)) {
73 return updateRenderableNode(QSGSoftwareRenderableNode::SimpleTexture, tn);
74 } else if (QSGNinePatchNode *nn = dynamic_cast<QSGNinePatchNode *>(node)) {
75 return updateRenderableNode(QSGSoftwareRenderableNode::NinePatch, nn);
76 } else if (QSGRectangleNode *rn = dynamic_cast<QSGRectangleNode *>(node)) {
77 return updateRenderableNode(QSGSoftwareRenderableNode::SimpleRectangle, rn);
78 } else if (QSGImageNode *n = dynamic_cast<QSGImageNode *>(node)) {
79 return updateRenderableNode(QSGSoftwareRenderableNode::SimpleImage, n);
80 } else {
81 // We dont know, so skip
82 return false;
83 }
84}
85
89
91{
92 m_opacityState.push(m_opacityState.top() * node->opacity());
93 m_stateMap[node] = currentState(node);
94 return true;
95}
96
101
103{
104 return updateRenderableNode(QSGSoftwareRenderableNode::Image, node);
105}
106
110
112{
113 return updateRenderableNode(QSGSoftwareRenderableNode::Painter, node);
114}
115
119
124
128
130{
131 return updateRenderableNode(QSGSoftwareRenderableNode::Glyph, node);
132}
133
137
139{
140 m_stateMap[node] = currentState(node);
141 return true;
142}
143
147
148#if QT_CONFIG(quick_sprite)
149bool QSGSoftwareRenderableNodeUpdater::visit(QSGSpriteNode *node)
150{
151 return updateRenderableNode(QSGSoftwareRenderableNode::SpriteNode, node);
152}
153
155{
156
157}
158#endif
159
161{
162 return updateRenderableNode(QSGSoftwareRenderableNode::RenderNode, node);
163}
164
168
170{
171 m_opacityState.clear();
172 m_clipState.clear();
173 m_transformState.clear();
174
175 auto parentNode = node->parent();
176 // If the node was deleted, it will have no parent
177 // check if the state map has the previous parent
178 if ((!parentNode || isNodeRemoved ) && m_stateMap.contains(node))
179 parentNode = m_stateMap[node].parent;
180
181 // If we find a parent, use its state for updating the new children
182 if (parentNode && m_stateMap.contains(parentNode)) {
183 auto state = m_stateMap[parentNode];
184 m_opacityState.push(state.opacity);
185 m_transformState.push(state.transform);
186 m_clipState.push(state.clip);
187 m_hasClip = state.hasClip;
188 } else {
189 // There is no parent, and no previous parent, so likely a root node
190 m_opacityState.push(1.0f);
191 m_transformState.push(QTransform());
192 m_clipState.push(QRegion());
193 m_hasClip = false;
194 }
195
196 // If the node is being removed, then cleanup the state data
197 // Then just visit the children without visiting the now removed node
198 if (isNodeRemoved) {
199 m_stateMap.remove(node);
200 return;
201 }
202
203 // Visit the current node itself first
204 switch (node->type()) {
206 QSGClipNode *c = static_cast<QSGClipNode*>(node);
207 if (visit(c))
209 endVisit(c);
210 break;
211 }
213 QSGTransformNode *c = static_cast<QSGTransformNode*>(node);
214 if (visit(c))
216 endVisit(c);
217 break;
218 }
220 QSGOpacityNode *c = static_cast<QSGOpacityNode*>(node);
221 if (visit(c))
223 endVisit(c);
224 break;
225 }
227 if (node->flags() & QSGNode::IsVisitableNode) {
228 QSGVisitableNode *v = static_cast<QSGVisitableNode*>(node);
229 v->accept(this);
230 } else {
231 QSGGeometryNode *c = static_cast<QSGGeometryNode*>(node);
232 if (visit(c))
234 endVisit(c);
235 }
236 break;
237 }
239 QSGRootNode *root = static_cast<QSGRootNode*>(node);
240 if (visit(root))
241 visitChildren(root);
242 endVisit(root);
243 break;
244 }
246 visitChildren(node);
247 break;
248 }
250 QSGRenderNode *r = static_cast<QSGRenderNode*>(node);
251 if (visit(r))
253 endVisit(r);
254 break;
255 }
256 default:
257 Q_UNREACHABLE();
258 break;
259 }
260}
261
262QSGSoftwareRenderableNodeUpdater::NodeState QSGSoftwareRenderableNodeUpdater::currentState(QSGNode *node) const
263{
264 NodeState state;
265 state.opacity = m_opacityState.top();
266 state.clip = m_clipState.top();
267 state.hasClip = m_hasClip;
268 state.transform = m_transformState.top();
269 state.parent = node->parent();
270 return state;
271}
272
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:958
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
qsizetype size() const noexcept
Definition qlist.h:397
void clear()
Definition qlist.h:434
QTransform toTransform() const
Returns the conventional Qt 2D transformation matrix that corresponds to this matrix.
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
Definition qrect.h:859
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
bool isNull() const
The QSGClipNode class implements the clipping functionality in the scene graph.
Definition qsgnode.h:221
QRectF clipRect() const
Returns the clip rect of this node.
Definition qsgnode.h:230
The QSGGeometryNode class is used for all rendered content in the scene graph.
Definition qsgnode.h:188
The QSGImageNode class is provided for convenience to easily draw textured content using the QML scen...
\inmodule QtQuick
void visitChildren(QSGNode *node)
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
Flags flags() const
Returns the set of flags for this node.
Definition qsgnode.h:118
@ IsVisitableNode
Definition qsgnode.h:62
@ BasicNodeType
Definition qsgnode.h:40
@ TransformNodeType
Definition qsgnode.h:42
@ RootNodeType
Definition qsgnode.h:45
@ GeometryNodeType
Definition qsgnode.h:41
@ RenderNodeType
Definition qsgnode.h:46
@ ClipNodeType
Definition qsgnode.h:43
@ OpacityNodeType
Definition qsgnode.h:44
QSGNode * parent() const
Returns the parent node of this node.
Definition qsgnode.h:93
NodeType type() const
Returns the type of this node.
Definition qsgnode.h:110
The QSGOpacityNode class is used to change opacity of nodes.
Definition qsgnode.h:276
qreal opacity() const
Returns this opacity node's opacity.
Definition qsgnode.h:282
The QSGRectangleNode class is a convenience class for drawing solid filled rectangles using scenegrap...
The QSGRenderNode class represents a set of custom rendering commands targeting the graphics API that...
The QSGRootNode is the toplevel root of any scene graph.
Definition qsgnode.h:259
The QSGSimpleRectNode class is a convenience class for drawing solid filled rectangles using scenegra...
The QSGSimpleTextureNode class is provided for convenience to easily draw textured content using the ...
QSGSoftwareRenderableNodeUpdater(QSGAbstractSoftwareRenderer *renderer)
void updateNodes(QSGNode *node, bool isNodeRemoved=false)
The QSGTransformNode class implements transformations in the scene graph.
Definition qsgnode.h:241
const QMatrix4x4 & matrix() const
Returns this transform node's matrix.
Definition qsgnode.h:247
virtual void accept(QSGNodeVisitorEx *)=0
T & top()
Returns a reference to the stack's top item.
Definition qstack.h:19
T pop()
Removes the top item from the stack and returns it.
Definition qstack.h:18
void push(const T &t)
Adds element t to the top of the stack.
Definition qstack.h:17
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QPoint map(const QPoint &p) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
else opt state
[0]
Combined button and popup list for selecting options.
GLsizei const GLfloat * v
[13]
GLboolean r
[2]
GLfloat n
const GLubyte * c
QSvgRenderer * renderer
[0]