1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include "qsggeometry.h"
46 #include <QtGui/QMatrix4x4>
54 #define QML_RUNTIME_TESTING
60 class QSGGeometryNode;
61 class QSGTransformNode;
64 class Q_QUICK_EXPORT QSGNode
78 // Lower 16 bites reserved for general node
79 OwnedByParent = 0x0001,
80 UsePreprocess = 0x0002,
81 ChildrenDoNotOverlap = 0x0004,
82 StaticSubtreeGeometry = 0x0008, // Subtree nodes have fixed matrix and vertex data.
84 // Upper 16 bits reserved for node subclasses
86 // QSGBasicGeometryNode
87 OwnsGeometry = 0x00010000,
88 OwnsMaterial = 0x00020000,
89 OwnsOpaqueMaterial = 0x00040000
91 Q_DECLARE_FLAGS(Flags, Flag)
94 DirtyUsePreprocess = UsePreprocess,
95 DirtyChildrenDoNotOverlap = ChildrenDoNotOverlap,
96 DirtyStaticSubtreeGeometry = StaticSubtreeGeometry,
99 DirtyClipList = 0x0200,
100 DirtyNodeAdded = 0x0400,
101 DirtyNodeRemoved = 0x0800,
102 DirtyGeometry = 0x1000,
103 DirtyMaterial = 0x2000,
104 DirtyOpacity = 0x4000,
105 DirtyForceUpdate = 0x8000,
107 DirtyPropagationMask = DirtyMatrix
114 Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)
119 QSGNode *parent() const { return m_parent; }
121 void removeChildNode(QSGNode *node);
122 void removeAllChildNodes();
123 void prependChildNode(QSGNode *node);
124 void appendChildNode(QSGNode *node);
125 void insertChildNodeBefore(QSGNode *node, QSGNode *before);
126 void insertChildNodeAfter(QSGNode *node, QSGNode *after);
128 int childCount() const;
129 QSGNode *childAtIndex(int i) const;
130 QSGNode *firstChild() const { return m_firstChild; }
131 QSGNode *lastChild() const { return m_lastChild; }
132 QSGNode *nextSibling() const { return m_nextSibling; }
133 QSGNode* previousSibling() const { return m_previousSibling; }
135 inline NodeType type() const { return m_type; }
137 void clearDirty() { m_dirtyState = 0; }
138 void markDirty(DirtyState bits);
139 DirtyState dirtyState() const { return m_dirtyState; }
141 virtual bool isSubtreeBlocked() const;
143 Flags flags() const { return m_nodeFlags; }
144 void setFlag(Flag, bool = true);
145 void setFlags(Flags, bool = true);
147 virtual void preprocess() { }
149 #ifdef QML_RUNTIME_TESTING
154 QSGNode(NodeType type);
157 friend class QSGRootNode;
164 QSGNode *m_firstChild;
165 QSGNode *m_lastChild;
166 QSGNode *m_nextSibling;
167 QSGNode *m_previousSibling;
168 int m_subtreeGeometryCount;
171 DirtyState m_dirtyState;
176 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::DirtyState)
177 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::Flags)
179 class Q_QUICK_EXPORT QSGBasicGeometryNode : public QSGNode
182 // enum UsagePattern {
187 // void setUsagePattern(UsagePattern pattern);
188 // UsagePattern usagePattern() const { return m_pattern; }
190 ~QSGBasicGeometryNode();
192 void setGeometry(QSGGeometry *geometry);
193 const QSGGeometry *geometry() const { return m_geometry; }
194 QSGGeometry *geometry() { return m_geometry; }
196 const QMatrix4x4 *matrix() const { return m_matrix; }
197 const QSGClipNode *clipList() const { return m_clip_list; }
200 QSGBasicGeometryNode(NodeType type);
203 friend class QSGNodeUpdater;
204 QSGGeometry *m_geometry;
206 int m_reserved_start_index;
207 int m_reserved_end_index;
209 const QMatrix4x4 *m_matrix;
210 const QSGClipNode *m_clip_list;
212 // UsagePattern m_pattern;
217 class Q_QUICK_EXPORT QSGGeometryNode : public QSGBasicGeometryNode
223 void setMaterial(QSGMaterial *material);
224 QSGMaterial *material() const { return m_material; }
226 void setOpaqueMaterial(QSGMaterial *material);
227 QSGMaterial *opaqueMaterial() const { return m_opaque_material; }
229 QSGMaterial *activeMaterial() const;
231 void setRenderOrder(int order);
232 int renderOrder() const { return m_render_order; }
234 void setInheritedOpacity(qreal opacity);
235 qreal inheritedOpacity() const { return m_opacity; }
238 friend class QSGNodeUpdater;
241 QSGMaterial *m_material;
242 QSGMaterial *m_opaque_material;
247 class Q_QUICK_EXPORT QSGClipNode : public QSGBasicGeometryNode
253 void setIsRectangular(bool rectHint);
254 bool isRectangular() const { return m_is_rectangular; }
256 void setClipRect(const QRectF &);
257 QRectF clipRect() const { return m_clip_rect; }
260 uint m_is_rectangular : 1;
261 uint m_reserved : 31;
267 class Q_QUICK_EXPORT QSGTransformNode : public QSGNode
273 void setMatrix(const QMatrix4x4 &matrix);
274 const QMatrix4x4 &matrix() const { return m_matrix; }
276 void setCombinedMatrix(const QMatrix4x4 &matrix);
277 const QMatrix4x4 &combinedMatrix() const { return m_combined_matrix; }
281 QMatrix4x4 m_combined_matrix;
285 class Q_QUICK_EXPORT QSGRootNode : public QSGNode
292 void notifyNodeChange(QSGNode *node, DirtyState state);
294 friend class QSGRenderer;
295 friend class QSGNode;
296 friend class QSGGeometryNode;
298 QList<QSGRenderer *> m_renderers;
302 class Q_QUICK_EXPORT QSGOpacityNode : public QSGNode
308 void setOpacity(qreal opacity);
309 qreal opacity() const { return m_opacity; }
311 void setCombinedOpacity(qreal opacity);
312 qreal combinedOpacity() const { return m_combined_opacity; }
314 bool isSubtreeBlocked() const;
318 qreal m_combined_opacity;
321 class Q_QUICK_EXPORT QSGNodeVisitor {
323 virtual ~QSGNodeVisitor();
326 virtual void enterTransformNode(QSGTransformNode *) {}
327 virtual void leaveTransformNode(QSGTransformNode *) {}
328 virtual void enterClipNode(QSGClipNode *) {}
329 virtual void leaveClipNode(QSGClipNode *) {}
330 virtual void enterGeometryNode(QSGGeometryNode *) {}
331 virtual void leaveGeometryNode(QSGGeometryNode *) {}
332 virtual void enterOpacityNode(QSGOpacityNode *) {}
333 virtual void leaveOpacityNode(QSGOpacityNode *) {}
334 virtual void visitNode(QSGNode *n);
335 virtual void visitChildren(QSGNode *n);
338 #ifndef QT_NO_DEBUG_STREAM
339 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGNode *n);
340 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGGeometryNode *n);
341 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGTransformNode *n);
342 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGOpacityNode *n);
343 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGRootNode *n);