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
4#ifndef QSGSOFTWARERENDERABLENODEUPDATER_H
5#define QSGSOFTWARERENDERABLENODEUPDATER_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 "qsgsoftwarerenderablenode_p.h"
19#include "qsgabstractsoftwarerenderer_p.h"
20
21#include <private/qsgadaptationlayer_p.h>
22
23#include <QTransform>
24#include <QStack>
25#include <QRectF>
26
27QT_BEGIN_NAMESPACE
28
29class QSGSoftwareRenderableNodeUpdater : public QSGNodeVisitorEx
30{
31public:
32 QSGSoftwareRenderableNodeUpdater(QSGAbstractSoftwareRenderer *renderer);
33 virtual ~QSGSoftwareRenderableNodeUpdater();
34
35 bool visit(QSGTransformNode *) override;
36 void endVisit(QSGTransformNode *) override;
37 bool visit(QSGClipNode *) override;
38 void endVisit(QSGClipNode *) override;
39 bool visit(QSGGeometryNode *) override;
40 void endVisit(QSGGeometryNode *) override;
41 bool visit(QSGOpacityNode *) override;
42 void endVisit(QSGOpacityNode *) override;
43 bool visit(QSGInternalImageNode *) override;
44 void endVisit(QSGInternalImageNode *) override;
45 bool visit(QSGPainterNode *) override;
46 void endVisit(QSGPainterNode *) override;
47 bool visit(QSGInternalRectangleNode *) override;
48 void endVisit(QSGInternalRectangleNode *) override;
49 bool visit(QSGGlyphNode *) override;
50 void endVisit(QSGGlyphNode *) override;
51 bool visit(QSGRootNode *) override;
52 void endVisit(QSGRootNode *) override;
53#if QT_CONFIG(quick_sprite)
54 bool visit(QSGSpriteNode *) override;
55 void endVisit(QSGSpriteNode *) override;
56#endif
57 bool visit(QSGRenderNode *) override;
58 void endVisit(QSGRenderNode *) override;
59
60 void updateNodes(QSGNode *node, bool isNodeRemoved = false);
61
62private:
63 struct NodeState {
64 float opacity;
65 QRegion clip;
66 bool hasClip;
67 QTransform transform;
68 QSGNode *parent;
69 };
70
71 NodeState currentState(QSGNode *node) const;
72
73 template<class NODE>
74 bool updateRenderableNode(QSGSoftwareRenderableNode::NodeType type, NODE *node);
75
76 QSGAbstractSoftwareRenderer *m_renderer;
77 QStack<float> m_opacityState;
78 QStack<QRegion> m_clipState;
79 bool m_hasClip;
80 QStack<QTransform> m_transformState;
81 QHash<QSGNode*,NodeState> m_stateMap;
82};
83
84template<class NODE>
85bool QSGSoftwareRenderableNodeUpdater::updateRenderableNode(QSGSoftwareRenderableNode::NodeType type, NODE *node)
86{
87 //Check if we already know about node
88 auto renderableNode = m_renderer->renderableNode(node);
89 if (renderableNode == nullptr) {
90 renderableNode = new QSGSoftwareRenderableNode(type, node);
91 m_renderer->addNodeMapping(node, renderableNode);
92 }
93
94 //Update the node
95 renderableNode->setTransform(m_transformState.top());
96 renderableNode->setOpacity(m_opacityState.top());
97 renderableNode->setClipRegion(m_clipState.top(), m_hasClip);
98
99 renderableNode->update();
100 m_stateMap[node] = currentState(node);
101
102 return true;
103}
104
105QT_END_NAMESPACE
106
107#endif // QSGSOFTWARERENDERABLENODEUPDATER_H
108

source code of qtdeclarative/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenodeupdater_p.h