Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / scenegraph / coreapi / qsgnode.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef NODE_H
43 #define NODE_H
44
45 #include "qsggeometry.h"
46 #include <QtGui/QMatrix4x4>
47
48 #include <float.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 #define QML_RUNTIME_TESTING
55
56 class QSGRenderer;
57
58 class QSGNode;
59 class QSGRootNode;
60 class QSGGeometryNode;
61 class QSGTransformNode;
62 class QSGClipNode;
63
64 class Q_QUICK_EXPORT QSGNode
65 {
66 public:
67     enum NodeType {
68         BasicNodeType,
69         RootNodeType,
70         GeometryNodeType,
71         TransformNodeType,
72         ClipNodeType,
73         OpacityNodeType,
74         UserNodeType = 1024
75     };
76
77     enum Flag {
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.
83
84         // Upper 16 bits reserved for node subclasses
85
86         // QSGBasicGeometryNode
87         OwnsGeometry                = 0x00010000,
88         OwnsMaterial                = 0x00020000,
89         OwnsOpaqueMaterial          = 0x00040000
90     };
91     Q_DECLARE_FLAGS(Flags, Flag)
92
93     enum DirtyStateBit {
94         DirtyUsePreprocess          = UsePreprocess,
95         DirtyChildrenDoNotOverlap   = ChildrenDoNotOverlap,
96         DirtyStaticSubtreeGeometry  = StaticSubtreeGeometry,
97
98         DirtyMatrix                 = 0x0100,
99         DirtyClipList               = 0x0200,
100         DirtyNodeAdded              = 0x0400,
101         DirtyNodeRemoved            = 0x0800,
102         DirtyGeometry               = 0x1000,
103         DirtyMaterial               = 0x2000,
104         DirtyOpacity                = 0x4000,
105         DirtyForceUpdate            = 0x8000,
106
107         DirtyPropagationMask        = DirtyMatrix
108                                       | DirtyClipList
109                                       | DirtyNodeAdded
110                                       | DirtyOpacity
111                                       | DirtyForceUpdate
112
113     };
114     Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)
115
116     QSGNode();
117     virtual ~QSGNode();
118
119     QSGNode *parent() const { return m_parent; }
120
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);
127
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; }
134
135     inline NodeType type() const { return m_type; }
136
137     void clearDirty() { m_dirtyState = 0; }
138     void markDirty(DirtyState bits);
139     DirtyState dirtyState() const { return m_dirtyState; }
140
141     virtual bool isSubtreeBlocked() const;
142
143     Flags flags() const { return m_nodeFlags; }
144     void setFlag(Flag, bool = true);
145     void setFlags(Flags, bool = true);
146
147     virtual void preprocess() { }
148
149 #ifdef QML_RUNTIME_TESTING
150     QString description;
151 #endif
152
153 protected:
154     QSGNode(NodeType type);
155
156 private:
157     friend class QSGRootNode;
158
159     void init();
160     void destroy();
161
162     QSGNode *m_parent;
163     NodeType m_type;
164     QSGNode *m_firstChild;
165     QSGNode *m_lastChild;
166     QSGNode *m_nextSibling;
167     QSGNode *m_previousSibling;
168     int m_subtreeGeometryCount;
169
170     Flags m_nodeFlags;
171     DirtyState m_dirtyState;
172
173     void *m_reserved;
174 };
175
176 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::DirtyState)
177 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::Flags)
178
179 class Q_QUICK_EXPORT QSGBasicGeometryNode : public QSGNode
180 {
181 public:
182 //    enum  UsagePattern {
183 //        Static,
184 //        Dynamic,
185 //        Stream
186 //    };
187 //    void setUsagePattern(UsagePattern pattern);
188 //    UsagePattern usagePattern() const { return m_pattern; }
189
190     ~QSGBasicGeometryNode();
191
192     void setGeometry(QSGGeometry *geometry);
193     const QSGGeometry *geometry() const { return m_geometry; }
194     QSGGeometry *geometry() { return m_geometry; }
195
196     const QMatrix4x4 *matrix() const { return m_matrix; }
197     const QSGClipNode *clipList() const { return m_clip_list; }
198
199 protected:
200     QSGBasicGeometryNode(NodeType type);
201
202 private:
203     friend class QSGNodeUpdater;
204     QSGGeometry *m_geometry;
205
206     int m_reserved_start_index;
207     int m_reserved_end_index;
208
209     const QMatrix4x4 *m_matrix;
210     const QSGClipNode *m_clip_list;
211
212 //    UsagePattern m_pattern;
213 };
214
215 class QSGMaterial;
216
217 class Q_QUICK_EXPORT QSGGeometryNode : public QSGBasicGeometryNode
218 {
219 public:
220     QSGGeometryNode();
221     ~QSGGeometryNode();
222
223     void setMaterial(QSGMaterial *material);
224     QSGMaterial *material() const { return m_material; }
225
226     void setOpaqueMaterial(QSGMaterial *material);
227     QSGMaterial *opaqueMaterial() const { return m_opaque_material; }
228
229     QSGMaterial *activeMaterial() const;
230
231     void setRenderOrder(int order);
232     int renderOrder() const { return m_render_order; }
233
234     void setInheritedOpacity(qreal opacity);
235     qreal inheritedOpacity() const { return m_opacity; }
236
237 private:
238     friend class QSGNodeUpdater;
239
240     int m_render_order;
241     QSGMaterial *m_material;
242     QSGMaterial *m_opaque_material;
243
244     qreal m_opacity;
245 };
246
247 class Q_QUICK_EXPORT QSGClipNode : public QSGBasicGeometryNode
248 {
249 public:
250     QSGClipNode();
251     ~QSGClipNode();
252
253     void setIsRectangular(bool rectHint);
254     bool isRectangular() const { return m_is_rectangular; }
255
256     void setClipRect(const QRectF &);
257     QRectF clipRect() const { return m_clip_rect; }
258
259 private:
260     uint m_is_rectangular : 1;
261     uint m_reserved : 31;
262
263     QRectF m_clip_rect;
264 };
265
266
267 class Q_QUICK_EXPORT QSGTransformNode : public QSGNode
268 {
269 public:
270     QSGTransformNode();
271     ~QSGTransformNode();
272
273     void setMatrix(const QMatrix4x4 &matrix);
274     const QMatrix4x4 &matrix() const { return m_matrix; }
275
276     void setCombinedMatrix(const QMatrix4x4 &matrix);
277     const QMatrix4x4 &combinedMatrix() const { return m_combined_matrix; }
278
279 private:
280     QMatrix4x4 m_matrix;
281     QMatrix4x4 m_combined_matrix;
282 };
283
284
285 class Q_QUICK_EXPORT QSGRootNode : public QSGNode
286 {
287 public:
288     QSGRootNode();
289     ~QSGRootNode();
290
291 private:
292     void notifyNodeChange(QSGNode *node, DirtyState state);
293
294     friend class QSGRenderer;
295     friend class QSGNode;
296     friend class QSGGeometryNode;
297
298     QList<QSGRenderer *> m_renderers;
299 };
300
301
302 class Q_QUICK_EXPORT QSGOpacityNode : public QSGNode
303 {
304 public:
305     QSGOpacityNode();
306     ~QSGOpacityNode();
307
308     void setOpacity(qreal opacity);
309     qreal opacity() const { return m_opacity; }
310
311     void setCombinedOpacity(qreal opacity);
312     qreal combinedOpacity() const { return m_combined_opacity; }
313
314     bool isSubtreeBlocked() const;
315
316 private:
317     qreal m_opacity;
318     qreal m_combined_opacity;
319 };
320
321 class Q_QUICK_EXPORT QSGNodeVisitor {
322 public:
323     virtual ~QSGNodeVisitor();
324
325 protected:
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);
336 };
337
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);
344
345 #endif
346
347 QT_END_NAMESPACE
348
349 QT_END_HEADER
350
351 #endif // NODE_H