QSGNode::QSGNode()
: m_parent(0)
+ , m_type(BasicNodeType)
, m_nodeFlags(OwnedByParent)
, m_flags(0)
{
+ init();
+}
+
+QSGNode::QSGNode(NodeType type)
+ : m_parent(0)
+ , m_type(type)
+ , m_nodeFlags(OwnedByParent)
+ , m_flags(0)
+{
+ init();
+}
+
+void QSGNode::init()
+{
#ifndef QT_NO_DEBUG
++qt_node_count;
static bool atexit_registered = false;
atexit_registered = true;
}
#endif
-
}
QSGNode::~QSGNode()
/*!
Creates a new basic geometry node.
*/
-QSGBasicGeometryNode::QSGBasicGeometryNode()
- : m_geometry(0)
+QSGBasicGeometryNode::QSGBasicGeometryNode(NodeType type)
+ : QSGNode(type)
+ , m_geometry(0)
, m_matrix(0)
, m_clip_list(0)
{
*/
QSGGeometryNode::QSGGeometryNode()
- : m_render_order(0)
+ : QSGBasicGeometryNode(GeometryNodeType)
+ , m_render_order(0)
, m_material(0)
, m_opaque_material(0)
, m_opacity(1)
*/
QSGClipNode::QSGClipNode()
+ : QSGBasicGeometryNode(ClipNodeType)
{
}
*/
QSGTransformNode::QSGTransformNode()
+ : QSGNode(TransformNodeType)
{
}
Creates a new root node.
*/
+QSGRootNode::QSGRootNode()
+ : QSGNode(RootNodeType)
+{
+}
/*!
The default opacity of nodes is 1.
*/
QSGOpacityNode::QSGOpacityNode()
- : m_opacity(1)
+ : QSGNode(OpacityNodeType)
+ , m_opacity(1)
, m_combined_opacity(1)
{
}
int childCount() const { return m_children.size(); }
QSGNode *childAtIndex(int i) const { return m_children.at(i); }
- virtual NodeType type() const { return BasicNodeType; }
+ inline NodeType type() const { return m_type; }
void clearDirty() { m_flags = 0; }
void markDirty(DirtyFlags flags);
#endif
protected:
+ QSGNode(NodeType type);
+
// When a node is destroyed, it will detach from the scene graph and the renderer will be
// notified about the change. If the node is detached in the base node's destructor, the
- // renderer can't check what type the node originally was because the node's type() method is
- // virtual and will return the base node type. The renderer might therefore react incorrectly
- // to the change. There are a few of ways I can think of to solve the problem:
- // - The renderer must take into account that the notify method might be called from a node's
- // destructor.
- // - The node can have a type property that is set in the constructor.
- // - All the node destructors must call a common destroy method.
- // I choose the third option since that will allow the renderer to treat the nodes as their
- // proper types.
+ // renderer can't safely cast the node to its original type, since at this point it has been
+ // partly destroyed already. To solve this problem, all the node destructors must call a common
+ // destroy method.
void destroy();
private:
+ void init();
+
QSGNode *m_parent;
+ NodeType m_type;
QList<QSGNode *> m_children;
Flags m_nodeFlags;
// void setUsagePattern(UsagePattern pattern);
// UsagePattern usagePattern() const { return m_pattern; }
- QSGBasicGeometryNode();
~QSGBasicGeometryNode();
void setGeometry(QSGGeometry *geometry);
const QMatrix4x4 *matrix() const { return m_matrix; }
const QSGClipNode *clipList() const { return m_clip_list; }
+protected:
+ QSGBasicGeometryNode(NodeType type);
+
private:
friend class QSGNodeUpdater;
QSGGeometry *m_geometry;
QSGMaterial *activeMaterial() const;
- virtual NodeType type() const { return GeometryNodeType; }
-
void setRenderOrder(int order);
int renderOrder() const { return m_render_order; }
QSGClipNode();
~QSGClipNode();
- virtual NodeType type() const { return ClipNodeType; }
-
void setIsRectangular(bool rectHint);
bool isRectangular() const { return m_is_rectangular; }
QSGTransformNode();
~QSGTransformNode();
- virtual NodeType type() const { return TransformNodeType; }
-
void setMatrix(const QMatrix4x4 &matrix);
const QMatrix4x4 &matrix() const { return m_matrix; }
class Q_DECLARATIVE_EXPORT QSGRootNode : public QSGNode
{
public:
+ QSGRootNode();
~QSGRootNode();
- NodeType type() const { return RootNodeType; }
private:
void notifyNodeChange(QSGNode *node, DirtyFlags flags);
void setCombinedOpacity(qreal opacity);
qreal combinedOpacity() const { return m_combined_opacity; }
- virtual QSGNode::NodeType type() const { return OpacityNodeType; }
-
bool isSubtreeBlocked() const;
-
private:
qreal m_opacity;
qreal m_combined_opacity;