1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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
80 // Lower 16 bites reserved for general node
81 OwnedByParent = 0x0001,
82 UsePreprocess = 0x0002,
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)
95 DirtyNodeAdded = 0x0400,
96 DirtyNodeRemoved = 0x0800,
97 DirtyGeometry = 0x1000,
98 DirtyMaterial = 0x2000,
99 DirtyOpacity = 0x4000,
102 DirtyForceUpdate = 0x8000,
104 DirtyUsePreprocess = UsePreprocess,
106 DirtyPropagationMask = DirtyMatrix
113 Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)
118 QSGNode *parent() const { return m_parent; }
120 void removeChildNode(QSGNode *node);
121 void removeAllChildNodes();
122 void prependChildNode(QSGNode *node);
123 void appendChildNode(QSGNode *node);
124 void insertChildNodeBefore(QSGNode *node, QSGNode *before);
125 void insertChildNodeAfter(QSGNode *node, QSGNode *after);
127 int childCount() const;
128 QSGNode *childAtIndex(int i) const;
129 QSGNode *firstChild() const { return m_firstChild; }
130 QSGNode *lastChild() const { return m_lastChild; }
131 QSGNode *nextSibling() const { return m_nextSibling; }
132 QSGNode* previousSibling() const { return m_previousSibling; }
134 inline NodeType type() const { return m_type; }
136 void clearDirty() { m_dirtyState = 0; }
137 void markDirty(DirtyState bits);
138 DirtyState dirtyState() const { return m_dirtyState; }
140 virtual bool isSubtreeBlocked() const;
142 Flags flags() const { return m_nodeFlags; }
143 void setFlag(Flag, bool = true);
144 void setFlags(Flags, bool = true);
146 virtual void preprocess() { }
148 #ifdef QML_RUNTIME_TESTING
153 QSGNode(NodeType type);
156 friend class QSGRootNode;
163 QSGNode *m_firstChild;
164 QSGNode *m_lastChild;
165 QSGNode *m_nextSibling;
166 QSGNode *m_previousSibling;
167 int m_subtreeRenderableCount;
170 DirtyState m_dirtyState;
175 class Q_QUICK_EXPORT QSGBasicGeometryNode : public QSGNode
178 ~QSGBasicGeometryNode();
180 void setGeometry(QSGGeometry *geometry);
181 const QSGGeometry *geometry() const { return m_geometry; }
182 QSGGeometry *geometry() { return m_geometry; }
184 const QMatrix4x4 *matrix() const { return m_matrix; }
185 const QSGClipNode *clipList() const { return m_clip_list; }
188 QSGBasicGeometryNode(NodeType type);
191 friend class QSGNodeUpdater;
192 QSGGeometry *m_geometry;
194 int m_reserved_start_index;
195 int m_reserved_end_index;
197 const QMatrix4x4 *m_matrix;
198 const QSGClipNode *m_clip_list;
203 class Q_QUICK_EXPORT QSGGeometryNode : public QSGBasicGeometryNode
209 void setMaterial(QSGMaterial *material);
210 QSGMaterial *material() const { return m_material; }
212 void setOpaqueMaterial(QSGMaterial *material);
213 QSGMaterial *opaqueMaterial() const { return m_opaque_material; }
215 QSGMaterial *activeMaterial() const;
217 void setRenderOrder(int order);
218 int renderOrder() const { return m_render_order; }
220 void setInheritedOpacity(qreal opacity);
221 qreal inheritedOpacity() const { return m_opacity; }
224 friend class QSGNodeUpdater;
227 QSGMaterial *m_material;
228 QSGMaterial *m_opaque_material;
233 class Q_QUICK_EXPORT QSGClipNode : public QSGBasicGeometryNode
239 void setIsRectangular(bool rectHint);
240 bool isRectangular() const { return m_is_rectangular; }
242 void setClipRect(const QRectF &);
243 QRectF clipRect() const { return m_clip_rect; }
246 uint m_is_rectangular : 1;
247 uint m_reserved : 31;
253 class Q_QUICK_EXPORT QSGTransformNode : public QSGNode
259 void setMatrix(const QMatrix4x4 &matrix);
260 const QMatrix4x4 &matrix() const { return m_matrix; }
262 void setCombinedMatrix(const QMatrix4x4 &matrix);
263 const QMatrix4x4 &combinedMatrix() const { return m_combined_matrix; }
267 QMatrix4x4 m_combined_matrix;
271 class Q_QUICK_EXPORT QSGRootNode : public QSGNode
278 void notifyNodeChange(QSGNode *node, DirtyState state);
280 friend class QSGRenderer;
281 friend class QSGNode;
282 friend class QSGGeometryNode;
284 QList<QSGRenderer *> m_renderers;
288 class Q_QUICK_EXPORT QSGOpacityNode : public QSGNode
294 void setOpacity(qreal opacity);
295 qreal opacity() const { return m_opacity; }
297 void setCombinedOpacity(qreal opacity);
298 qreal combinedOpacity() const { return m_combined_opacity; }
300 bool isSubtreeBlocked() const;
304 qreal m_combined_opacity;
307 class Q_QUICK_EXPORT QSGNodeVisitor {
309 virtual ~QSGNodeVisitor();
312 virtual void enterTransformNode(QSGTransformNode *) {}
313 virtual void leaveTransformNode(QSGTransformNode *) {}
314 virtual void enterClipNode(QSGClipNode *) {}
315 virtual void leaveClipNode(QSGClipNode *) {}
316 virtual void enterGeometryNode(QSGGeometryNode *) {}
317 virtual void leaveGeometryNode(QSGGeometryNode *) {}
318 virtual void enterOpacityNode(QSGOpacityNode *) {}
319 virtual void leaveOpacityNode(QSGOpacityNode *) {}
320 virtual void visitNode(QSGNode *n);
321 virtual void visitChildren(QSGNode *n);
324 #ifndef QT_NO_DEBUG_STREAM
325 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGNode *n);
326 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGGeometryNode *n);
327 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGTransformNode *n);
328 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGOpacityNode *n);
329 Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGRootNode *n);
333 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::DirtyState)
334 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::Flags)