From: Kim Motoyoshi Kalland Date: Fri, 20 May 2011 12:50:59 +0000 (+0200) Subject: Removed virtual type() from QSGNode, member variable instead. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=da6c903c9fe5de8d71c172866bb583b2f696d622;p=konrad%2Fqtdeclarative.git Removed virtual type() from QSGNode, member variable instead. --- diff --git a/src/declarative/scenegraph/coreapi/qsgnode.cpp b/src/declarative/scenegraph/coreapi/qsgnode.cpp index 7e19339..3472c93 100644 --- a/src/declarative/scenegraph/coreapi/qsgnode.cpp +++ b/src/declarative/scenegraph/coreapi/qsgnode.cpp @@ -83,9 +83,24 @@ static void qt_print_node_count() 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; @@ -94,7 +109,6 @@ QSGNode::QSGNode() atexit_registered = true; } #endif - } QSGNode::~QSGNode() @@ -369,8 +383,9 @@ void QSGNode::markDirty(DirtyFlags flags) /*! 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) { @@ -443,7 +458,8 @@ void QSGBasicGeometryNode::setGeometry(QSGGeometry *geometry) */ QSGGeometryNode::QSGGeometryNode() - : m_render_order(0) + : QSGBasicGeometryNode(GeometryNodeType) + , m_render_order(0) , m_material(0) , m_opaque_material(0) , m_opacity(1) @@ -608,6 +624,7 @@ void QSGGeometryNode::setInheritedOpacity(qreal opacity) */ QSGClipNode::QSGClipNode() + : QSGBasicGeometryNode(ClipNodeType) { } @@ -686,6 +703,7 @@ void QSGClipNode::setClipRect(const QRectF &rect) */ QSGTransformNode::QSGTransformNode() + : QSGNode(TransformNodeType) { } @@ -754,6 +772,10 @@ void QSGTransformNode::setCombinedMatrix(const QMatrix4x4 &matrix) Creates a new root node. */ +QSGRootNode::QSGRootNode() + : QSGNode(RootNodeType) +{ +} /*! @@ -812,7 +834,8 @@ void QSGRootNode::notifyNodeChange(QSGNode *node, DirtyFlags flags) The default opacity of nodes is 1. */ QSGOpacityNode::QSGOpacityNode() - : m_opacity(1) + : QSGNode(OpacityNodeType) + , m_opacity(1) , m_combined_opacity(1) { } diff --git a/src/declarative/scenegraph/coreapi/qsgnode.h b/src/declarative/scenegraph/coreapi/qsgnode.h index a905696..a391b55 100644 --- a/src/declarative/scenegraph/coreapi/qsgnode.h +++ b/src/declarative/scenegraph/coreapi/qsgnode.h @@ -126,7 +126,7 @@ public: 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); @@ -145,22 +145,21 @@ public: #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 m_children; Flags m_nodeFlags; @@ -183,7 +182,6 @@ public: // void setUsagePattern(UsagePattern pattern); // UsagePattern usagePattern() const { return m_pattern; } - QSGBasicGeometryNode(); ~QSGBasicGeometryNode(); void setGeometry(QSGGeometry *geometry); @@ -193,6 +191,9 @@ public: 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; @@ -222,8 +223,6 @@ public: QSGMaterial *activeMaterial() const; - virtual NodeType type() const { return GeometryNodeType; } - void setRenderOrder(int order); int renderOrder() const { return m_render_order; } @@ -246,8 +245,6 @@ public: QSGClipNode(); ~QSGClipNode(); - virtual NodeType type() const { return ClipNodeType; } - void setIsRectangular(bool rectHint); bool isRectangular() const { return m_is_rectangular; } @@ -268,8 +265,6 @@ public: QSGTransformNode(); ~QSGTransformNode(); - virtual NodeType type() const { return TransformNodeType; } - void setMatrix(const QMatrix4x4 &matrix); const QMatrix4x4 &matrix() const { return m_matrix; } @@ -285,8 +280,8 @@ private: class Q_DECLARATIVE_EXPORT QSGRootNode : public QSGNode { public: + QSGRootNode(); ~QSGRootNode(); - NodeType type() const { return RootNodeType; } private: void notifyNodeChange(QSGNode *node, DirtyFlags flags); @@ -311,11 +306,8 @@ public: 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;