1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include "qsggeometry.h"
46 #include <QtGui/QMatrix4x4>
54 QT_MODULE(Declarative)
56 #define QML_RUNTIME_TESTING
62 class QSGGeometryNode;
63 class QSGTransformNode;
66 class Q_DECLARATIVE_EXPORT QSGNode
81 DirtyClipList = 0x0002,
82 DirtyNodeAdded = 0x0004,
83 DirtyNodeRemoved = 0x0008,
84 DirtyGeometry = 0x0010,
85 DirtyMaterial = 0x0040,
86 DirtyOpacity = 0x0080,
87 DirtyForceUpdate = 0x0100,
89 DirtyPropagationMask = DirtyMatrix
96 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
99 // Lower 16 bites reserved for general node
100 OwnedByParent = 0x0001,
101 UsePreprocess = 0x0002,
102 ChildrenDoNotOverlap = 0x0004,
104 // Upper 16 bits reserved for node subclasses
106 // QSGBasicGeometryNode
107 OwnsGeometry = 0x00010000,
108 OwnsMaterial = 0x00020000,
109 OwnsOpaqueMaterial = 0x00040000
111 Q_DECLARE_FLAGS(Flags, Flag)
116 QSGNode *parent() const { return m_parent; }
118 void removeChildNode(QSGNode *node);
119 void removeAllChildNodes();
120 void prependChildNode(QSGNode *node);
121 void appendChildNode(QSGNode *node);
122 void insertChildNodeBefore(QSGNode *node, QSGNode *before);
123 void insertChildNodeAfter(QSGNode *node, QSGNode *after);
125 int childCount() const;
126 QSGNode *childAtIndex(int i) const;
127 QSGNode *firstChild() const { return m_firstChild; }
128 QSGNode *lastChild() const { return m_lastChild; }
129 QSGNode *nextSibling() const { return m_nextSibling; }
130 QSGNode* previousSibling() const { return m_previousSibling; }
132 inline NodeType type() const { return m_type; }
134 void clearDirty() { m_flags = 0; }
135 void markDirty(DirtyFlags flags);
136 DirtyFlags dirtyFlags() const { return m_flags; }
138 virtual bool isSubtreeBlocked() const;
140 Flags flags() const { return m_nodeFlags; }
141 void setFlag(Flag, bool = true);
142 void setFlags(Flags, bool = true);
144 virtual void preprocess() { }
146 #ifdef QML_RUNTIME_TESTING
151 QSGNode(NodeType type);
154 friend class QSGRootNode;
161 QSGNode *m_firstChild;
162 QSGNode *m_lastChild;
163 QSGNode *m_nextSibling;
164 QSGNode *m_previousSibling;
165 int m_subtreeGeometryCount;
173 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::DirtyFlags);
174 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::Flags);
176 class Q_DECLARATIVE_EXPORT QSGBasicGeometryNode : public QSGNode
179 // enum UsagePattern {
184 // void setUsagePattern(UsagePattern pattern);
185 // UsagePattern usagePattern() const { return m_pattern; }
187 ~QSGBasicGeometryNode();
189 void setGeometry(QSGGeometry *geometry);
190 const QSGGeometry *geometry() const { return m_geometry; }
191 QSGGeometry *geometry() { return m_geometry; }
193 const QMatrix4x4 *matrix() const { return m_matrix; }
194 const QSGClipNode *clipList() const { return m_clip_list; }
197 QSGBasicGeometryNode(NodeType type);
200 friend class QSGNodeUpdater;
201 QSGGeometry *m_geometry;
203 int m_reserved_start_index;
204 int m_reserved_end_index;
206 const QMatrix4x4 *m_matrix;
207 const QSGClipNode *m_clip_list;
209 // UsagePattern m_pattern;
214 class Q_DECLARATIVE_EXPORT QSGGeometryNode : public QSGBasicGeometryNode
220 void setMaterial(QSGMaterial *material);
221 QSGMaterial *material() const { return m_material; }
223 void setOpaqueMaterial(QSGMaterial *material);
224 QSGMaterial *opaqueMaterial() const { return m_opaque_material; }
226 QSGMaterial *activeMaterial() const;
228 void setRenderOrder(int order);
229 int renderOrder() const { return m_render_order; }
231 void setInheritedOpacity(qreal opacity);
232 qreal inheritedOpacity() const { return m_opacity; }
235 friend class QSGNodeUpdater;
238 QSGMaterial *m_material;
239 QSGMaterial *m_opaque_material;
244 class Q_DECLARATIVE_EXPORT QSGClipNode : public QSGBasicGeometryNode
250 void setIsRectangular(bool rectHint);
251 bool isRectangular() const { return m_is_rectangular; }
253 void setClipRect(const QRectF &);
254 QRectF clipRect() const { return m_clip_rect; }
257 uint m_is_rectangular : 1;
258 uint m_reserved : 31;
264 class Q_DECLARATIVE_EXPORT QSGTransformNode : public QSGNode
270 void setMatrix(const QMatrix4x4 &matrix);
271 const QMatrix4x4 &matrix() const { return m_matrix; }
273 void setCombinedMatrix(const QMatrix4x4 &matrix);
274 const QMatrix4x4 &combinedMatrix() const { return m_combined_matrix; }
278 QMatrix4x4 m_combined_matrix;
282 class Q_DECLARATIVE_EXPORT QSGRootNode : public QSGNode
289 void notifyNodeChange(QSGNode *node, DirtyFlags flags);
291 friend class QSGRenderer;
292 friend class QSGNode;
293 friend class QSGGeometryNode;
295 QList<QSGRenderer *> m_renderers;
299 class Q_DECLARATIVE_EXPORT QSGOpacityNode : public QSGNode
305 void setOpacity(qreal opacity);
306 qreal opacity() const { return m_opacity; }
308 void setCombinedOpacity(qreal opacity);
309 qreal combinedOpacity() const { return m_combined_opacity; }
311 bool isSubtreeBlocked() const;
315 qreal m_combined_opacity;
318 class Q_DECLARATIVE_EXPORT QSGNodeVisitor {
320 virtual ~QSGNodeVisitor();
323 virtual void enterTransformNode(QSGTransformNode *) {}
324 virtual void leaveTransformNode(QSGTransformNode *) {}
325 virtual void enterClipNode(QSGClipNode *) {}
326 virtual void leaveClipNode(QSGClipNode *) {}
327 virtual void enterGeometryNode(QSGGeometryNode *) {}
328 virtual void leaveGeometryNode(QSGGeometryNode *) {}
329 virtual void enterOpacityNode(QSGOpacityNode *) {}
330 virtual void leaveOpacityNode(QSGOpacityNode *) {}
331 virtual void visitNode(QSGNode *n);
332 virtual void visitChildren(QSGNode *n);
335 #ifndef QT_NO_DEBUG_STREAM
336 Q_DECLARATIVE_EXPORT QDebug operator<<(QDebug, const QSGNode *n);
337 Q_DECLARATIVE_EXPORT QDebug operator<<(QDebug, const QSGGeometryNode *n);
338 Q_DECLARATIVE_EXPORT QDebug operator<<(QDebug, const QSGTransformNode *n);
339 Q_DECLARATIVE_EXPORT QDebug operator<<(QDebug, const QSGOpacityNode *n);
340 Q_DECLARATIVE_EXPORT QDebug operator<<(QDebug, const QSGRootNode *n);