[dali_1.9.18] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_NODE_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/actors/draw-mode.h>
24 #include <dali/public-api/math/quaternion.h>
25 #include <dali/public-api/math/math-utils.h>
26 #include <dali/public-api/math/vector3.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/event/common/event-thread-services.h>
30 #include <dali/internal/render/data-providers/node-data-provider.h>
31 #include <dali/internal/update/common/animatable-property.h>
32 #include <dali/internal/update/common/property-owner.h>
33 #include <dali/internal/update/common/scene-graph-buffers.h>
34 #include <dali/internal/update/common/inherited-property.h>
35 #include <dali/internal/update/manager/transform-manager.h>
36 #include <dali/internal/update/manager/transform-manager-property.h>
37 #include <dali/internal/update/nodes/node-declarations.h>
38 #include <dali/internal/update/rendering/scene-graph-renderer.h>
39
40 namespace Dali
41 {
42
43 namespace Internal
44 {
45
46 // Value types used by messages.
47 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
48 template <> struct ParameterType< ClippingMode::Type > : public BasicType< ClippingMode::Type > {};
49
50 namespace SceneGraph
51 {
52
53 class DiscardQueue;
54 class Layer;
55 class RenderTask;
56 class UpdateManager;
57
58
59 // Flags which require the scene renderable lists to be updated
60 static NodePropertyFlags RenderableUpdateFlags = NodePropertyFlags::TRANSFORM | NodePropertyFlags::CHILD_DELETED;
61
62 /**
63  * Node is the base class for all nodes in the Scene Graph.
64  *
65  * Each node provides a transformation which applies to the node and
66  * its children.  Node data is double-buffered. This allows an update
67  * thread to modify node data, without interferring with another
68  * thread reading the values from the previous update traversal.
69  */
70 class Node : public PropertyOwner, public NodeDataProvider
71 {
72 public:
73
74   // Defaults
75   static const ColorMode DEFAULT_COLOR_MODE;
76
77   // Creation methods
78
79   /**
80    * Construct a new Node.
81    */
82   static Node* New();
83
84   /**
85    * Deletes a Node.
86    */
87   static void Delete( Node* node );
88
89   /**
90    * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
91    */
92   void OnDestroy();
93
94   /**
95    * @return the unique ID of the node
96    */
97   uint32_t GetId() const;
98
99   // Layer interface
100
101   /**
102    * Query whether the node is a layer.
103    * @return True if the node is a layer.
104    */
105   bool IsLayer()
106   {
107     return mIsLayer;
108   }
109
110   /**
111    * Convert a node to a layer.
112    * @return A pointer to the layer, or NULL.
113    */
114   virtual Layer* GetLayer()
115   {
116     return NULL;
117   }
118
119   /**
120    * Mark an node and its sub tree according to the updated flag.
121    * @param[in] updated The updated flag
122    * (used for partial rendering to mark an animating sub tree for example).
123    */
124   virtual void SetUpdated(bool updated)
125   {
126     mUpdated = updated;
127
128     for (Node* child : mChildren)
129     {
130        child->SetUpdated(updated);
131     }
132   }
133
134   /**
135    * This method sets clipping information on the node based on its hierarchy in the scene-graph.
136    * A value is calculated that can be used during sorting to increase sort speed.
137    * @param[in] clippingId The Clipping ID of the node to set
138    * @param[in] clippingDepth The Clipping Depth of the node to set
139    * @param[in] scissorDepth The Scissor Clipping Depth of the node to set
140    */
141   void SetClippingInformation( const uint32_t clippingId, const uint32_t clippingDepth, const uint32_t scissorDepth )
142   {
143     // We only set up the sort value if we have a stencil clipping depth, IE. At least 1 clipping node has been hit.
144     // If not, if we traverse down a clipping tree and back up, and there is another
145     // node on the parent, this will have a non-zero clipping ID that must be ignored
146     if( clippingDepth > 0u )
147     {
148       mClippingDepth = clippingDepth;
149
150       // Calculate the sort value here on write, as when read (during sort) it may be accessed several times.
151       // The items must be sorted by Clipping ID first (so the ID is kept in the most-significant bits).
152       // For the same ID, the clipping nodes must be first, so we negate the
153       // clipping enabled flag and set it as the least significant bit.
154       mClippingSortModifier = ( clippingId << 1u ) | ( mClippingMode == ClippingMode::DISABLED ? 1u : 0u );
155     }
156     else
157     {
158       // If we do not have a clipping depth, then set this to 0 so we do not have a Clipping ID either.
159       mClippingSortModifier = 0u;
160     }
161
162     // The scissor depth does not modify the clipping sort modifier (as scissor clips are 2D only).
163     // For this reason we can always update the member variable.
164     mScissorDepth = scissorDepth;
165   }
166
167   /**
168    * Gets the Clipping ID for this node.
169    * @return The Clipping ID for this node.
170    */
171   uint32_t GetClippingId() const
172   {
173     return mClippingSortModifier >> 1u;
174   }
175
176   /**
177    * Gets the Clipping Depth for this node.
178    * @return The Clipping Depth for this node.
179    */
180   uint32_t GetClippingDepth() const
181   {
182     return mClippingDepth;
183   }
184
185   /**
186    * Gets the Scissor Clipping Depth for this node.
187    * @return The Scissor Clipping Depth for this node.
188    */
189   uint32_t GetScissorDepth() const
190   {
191     return mScissorDepth;
192   }
193
194   /**
195    * Sets the clipping mode for this node.
196    * @param[in] clippingMode The ClippingMode to set
197    */
198   void SetClippingMode( const ClippingMode::Type clippingMode )
199   {
200     mClippingMode = clippingMode;
201   }
202
203   /**
204    * Gets the Clipping Mode for this node.
205    * @return The ClippingMode of this node
206    */
207   ClippingMode::Type GetClippingMode() const
208   {
209     return mClippingMode;
210   }
211
212   /**
213    * Add a renderer to the node
214    * @param[in] renderer The renderer added to the node
215    */
216   void AddRenderer( Renderer* renderer );
217
218   /**
219    * Remove a renderer from the node
220    * @param[in] renderer The renderer to be removed
221    */
222   void RemoveRenderer( const Renderer* renderer );
223
224   /*
225    * Get the renderer at the given index
226    * @param[in] index
227    */
228   Renderer* GetRendererAt( uint32_t index ) const
229   {
230     return mRenderer[index];
231   }
232
233   /**
234    * Retrieve the number of renderers for the node
235    */
236   uint32_t GetRendererCount() const
237   {
238     return static_cast<uint32_t>( mRenderer.Size() );
239   }
240
241   // Containment methods
242
243   /**
244    * Query whether a node is the root node. Root nodes cannot have a parent node.
245    * A node becomes a root node, when it is installed by UpdateManager.
246    * @return True if the node is a root node.
247    */
248   bool IsRoot() const
249   {
250     return mIsRoot;
251   }
252
253   /**
254    * Set whether a node is the root node. Root nodes cannot have a parent node.
255    * This method should only be called by UpdateManager.
256    * @pre When isRoot is true, the node must not have a parent.
257    * @param[in] isRoot Whether the node is now a root node.
258    */
259   void SetRoot(bool isRoot);
260
261   /**
262    * Retrieve the parent of a Node.
263    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
264    */
265   Node* GetParent()
266   {
267     return mParent;
268   }
269
270   /**
271    * Retrieve the parent of a Node.
272    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
273    */
274   const Node* GetParent() const
275   {
276     return mParent;
277   }
278
279   /**
280    * @return true if the node is connected to SceneGraph
281    */
282   bool ConnectedToScene()
283   {
284     return IsRoot() || GetParent();
285   }
286
287   /**
288    * Connect a node to the scene-graph.
289    * @pre A node cannot be added to itself.
290    * @pre The parent node is connected to the scene-graph.
291    * @pre The childNode does not already have a parent.
292    * @pre The childNode is not a root node.
293    * @param[in] childNode The child to add.
294    */
295   void ConnectChild( Node* childNode );
296
297   /**
298    * Disconnect a child (& its children) from the scene-graph.
299    * @pre childNode is a child of this Node.
300    * @param[in] updateBufferIndex The current update buffer index.
301    * @param[in] childNode The node to disconnect.
302    */
303   void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode );
304
305   /**
306    * Retrieve the children a Node.
307    * @return The container of children.
308    */
309   const NodeContainer& GetChildren() const
310   {
311     return mChildren;
312   }
313
314   /**
315    * Retrieve the children a Node.
316    * @return The container of children.
317    */
318   NodeContainer& GetChildren()
319   {
320     return mChildren;
321   }
322
323   // Update methods
324
325   /**
326    * Flag that one of the node values has changed in the current frame.
327    * @param[in] flag The flag to set.
328    */
329   void SetDirtyFlag( NodePropertyFlags flag )
330   {
331     mDirtyFlags |= flag;
332   }
333
334   /**
335    * Flag that all of the node values are dirty.
336    */
337   void SetAllDirtyFlags()
338   {
339     mDirtyFlags = NodePropertyFlags::ALL;
340   }
341
342   /**
343    * Query whether a node is dirty.
344    * @return The dirty flags
345    */
346   NodePropertyFlags GetDirtyFlags() const;
347
348   /**
349    * Query inherited dirty flags.
350    *
351    * @param The parentFlags to or with
352    * @return The inherited dirty flags
353    */
354   NodePropertyFlags GetInheritedDirtyFlags( NodePropertyFlags parentFlags ) const;
355
356   /**
357    * Retrieve the parent-origin of the node.
358    * @return The parent-origin.
359    */
360   const Vector3& GetParentOrigin() const
361   {
362     return mParentOrigin.Get(0);
363   }
364
365   /**
366    * Sets both the local & base parent-origins of the node.
367    * @param[in] origin The new local & base parent-origins.
368    */
369   void SetParentOrigin(const Vector3& origin)
370   {
371     mParentOrigin.Set(0,origin );
372   }
373
374   /**
375    * Retrieve the anchor-point of the node.
376    * @return The anchor-point.
377    */
378   const Vector3& GetAnchorPoint() const
379   {
380     return mAnchorPoint.Get(0);
381   }
382
383   /**
384    * Sets both the local & base anchor-points of the node.
385    * @param[in] anchor The new local & base anchor-points.
386    */
387   void SetAnchorPoint(const Vector3& anchor)
388   {
389     mAnchorPoint.Set(0, anchor );
390   }
391
392   /**
393    * Retrieve the local position of the node, relative to its parent.
394    * @param[in] bufferIndex The buffer to read from.
395    * @return The local position.
396    */
397   const Vector3& GetPosition(BufferIndex bufferIndex) const
398   {
399     if( mTransformId != INVALID_TRANSFORM_ID )
400     {
401       return mPosition.Get(bufferIndex);
402     }
403
404     return Vector3::ZERO;
405   }
406
407   /**
408    * Retrieve the position of the node derived from the position of all its parents.
409    * @return The world position.
410    */
411   const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
412   {
413     return mWorldPosition.Get(bufferIndex);
414   }
415
416   /**
417    * Set whether the Node inherits position.
418    * @param[in] inherit True if the parent position is inherited.
419    */
420   void SetInheritPosition(bool inherit)
421   {
422     if( mTransformId != INVALID_TRANSFORM_ID )
423     {
424       mTransformManager->SetInheritPosition( mTransformId, inherit );
425     }
426   }
427
428   /**
429    * Retrieve the local orientation of the node, relative to its parent.
430    * @param[in] bufferIndex The buffer to read from.
431    * @return The local orientation.
432    */
433   const Quaternion& GetOrientation(BufferIndex bufferIndex) const
434   {
435     if( mTransformId != INVALID_TRANSFORM_ID )
436     {
437       return mOrientation.Get(0);
438     }
439
440     return Quaternion::IDENTITY;
441   }
442
443   /**
444    * Retrieve the orientation of the node derived from the rotation of all its parents.
445    * @param[in] bufferIndex The buffer to read from.
446    * @return The world rotation.
447    */
448   const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
449   {
450     return mWorldOrientation.Get(0);
451   }
452
453   /**
454    * Set whether the Node inherits orientation.
455    * @param[in] inherit True if the parent orientation is inherited.
456    */
457   void SetInheritOrientation(bool inherit)
458   {
459     if( mTransformId != INVALID_TRANSFORM_ID )
460     {
461       mTransformManager->SetInheritOrientation(mTransformId, inherit );
462     }
463   }
464
465   /**
466    * Retrieve the local scale of the node, relative to its parent.
467    * @param[in] bufferIndex The buffer to read from.
468    * @return The local scale.
469    */
470   const Vector3& GetScale(BufferIndex bufferIndex) const
471   {
472     if( mTransformId != INVALID_TRANSFORM_ID )
473     {
474       return mScale.Get(0);
475     }
476
477     return Vector3::ONE;
478   }
479
480
481   /**
482    * Retrieve the scale of the node derived from the scale of all its parents.
483    * @param[in] bufferIndex The buffer to read from.
484    * @return The world scale.
485    */
486   const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
487   {
488     return mWorldScale.Get(0);
489   }
490
491   /**
492    * Set whether the Node inherits scale.
493    * @param inherit True if the Node inherits scale.
494    */
495   void SetInheritScale( bool inherit )
496   {
497     if( mTransformId != INVALID_TRANSFORM_ID )
498     {
499       mTransformManager->SetInheritScale(mTransformId, inherit );
500     }
501   }
502
503   /**
504    * Retrieve the visibility of the node.
505    * @param[in] bufferIndex The buffer to read from.
506    * @return True if the node is visible.
507    */
508   bool IsVisible(BufferIndex bufferIndex) const
509   {
510     return mVisible[bufferIndex];
511   }
512
513   /**
514    * Retrieve the opacity of the node.
515    * @param[in] bufferIndex The buffer to read from.
516    * @return The opacity.
517    */
518   float GetOpacity(BufferIndex bufferIndex) const
519   {
520     return mColor[bufferIndex].a;
521   }
522
523   /**
524    * Retrieve the color of the node.
525    * @param[in] bufferIndex The buffer to read from.
526    * @return The color.
527    */
528   const Vector4& GetColor(BufferIndex bufferIndex) const
529   {
530     return mColor[bufferIndex];
531   }
532
533   /**
534    * Sets the color of the node derived from the color of all its parents.
535    * @param[in] color The world color.
536    * @param[in] updateBufferIndex The current update buffer index.
537    */
538   void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
539   {
540     mWorldColor.Set( updateBufferIndex, color );
541   }
542
543   /**
544    * Sets the color of the node derived from the color of all its parents.
545    * This method should only be called when the parents world color is up-to-date.
546    * @pre The node has a parent.
547    * @param[in] updateBufferIndex The current update buffer index.
548    */
549   void InheritWorldColor( BufferIndex updateBufferIndex )
550   {
551     DALI_ASSERT_DEBUG(mParent != NULL);
552
553     // default first
554     if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
555     {
556       const Vector4& ownColor = mColor[updateBufferIndex];
557       mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
558     }
559     else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
560     {
561       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
562     }
563     else if( mColorMode == USE_PARENT_COLOR )
564     {
565       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
566     }
567     else // USE_OWN_COLOR
568     {
569       mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
570     }
571   }
572
573   /**
574    * Copies the previous inherited scale, if this changed in the previous frame.
575    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
576    * does not need to be recalculated in the current frame.
577    * @param[in] updateBufferIndex The current update buffer index.
578    */
579   void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
580   {
581     mWorldColor.CopyPrevious( updateBufferIndex );
582   }
583
584   /**
585    * Retrieve the color of the node, possibly derived from the color
586    * of all its parents, depending on the value of mColorMode.
587    * @param[in] bufferIndex The buffer to read from.
588    * @return The world color.
589    */
590   const Vector4& GetWorldColor(BufferIndex bufferIndex) const
591   {
592     return mWorldColor[bufferIndex];
593   }
594
595   /**
596    * Set the color mode. This specifies whether the Node uses its own color,
597    * or inherits its parent color.
598    * @param[in] colorMode The new color mode.
599    */
600   void SetColorMode( ColorMode colorMode )
601   {
602     mColorMode = colorMode;
603
604     SetDirtyFlag( NodePropertyFlags::COLOR );
605   }
606
607   /**
608    * Retrieve the color mode.
609    * @return The color mode.
610    */
611   ColorMode GetColorMode() const
612   {
613     return mColorMode;
614   }
615
616   /**
617    * Retrieve the size of the node.
618    * @param[in] bufferIndex The buffer to read from.
619    * @return The size.
620    */
621   const Vector3& GetSize(BufferIndex bufferIndex) const
622   {
623     if( mTransformId != INVALID_TRANSFORM_ID )
624     {
625       return mSize.Get(0);
626     }
627
628     return Vector3::ZERO;
629   }
630
631   /**
632    * Retrieve the update size hint of the node.
633    * @return The update size hint.
634    */
635   const Vector3& GetUpdateSizeHint() const
636   {
637     if( mTransformId != INVALID_TRANSFORM_ID )
638     {
639       return mUpdateSizeHint.Get(0);
640     }
641
642     return Vector3::ZERO;
643   }
644
645   /**
646    * Retrieve the bounding sphere of the node
647    * @return A vector4 describing the bounding sphere. XYZ is the center and W is the radius
648    */
649   const Vector4& GetBoundingSphere() const
650   {
651     if( mTransformId != INVALID_TRANSFORM_ID )
652     {
653       return mTransformManager->GetBoundingSphere( mTransformId );
654     }
655
656     return Vector4::ZERO;
657   }
658
659   /**
660    * Retrieve world matrix and size of the node
661    * @param[out] The local to world matrix of the node
662    * @param[out] size The current size of the node
663    */
664   void GetWorldMatrixAndSize( Matrix& worldMatrix, Vector3& size ) const
665   {
666     if( mTransformId != INVALID_TRANSFORM_ID )
667     {
668       mTransformManager->GetWorldMatrixAndSize( mTransformId, worldMatrix, size );
669     }
670   }
671
672   /**
673    * Checks if local matrix has changed since last update
674    * @return true if local matrix has changed, false otherwise
675    */
676   bool IsLocalMatrixDirty() const
677   {
678     return (mTransformId != INVALID_TRANSFORM_ID) &&
679            (mTransformManager->IsLocalMatrixDirty( mTransformId ));
680   }
681
682   /**
683    * Retrieve the cached world-matrix of a node.
684    * @param[in] bufferIndex The buffer to read from.
685    * @return The world-matrix.
686    */
687   const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
688   {
689     return mWorldMatrix.Get(bufferIndex);
690   }
691
692   /**
693    * Mark the node as exclusive to a single RenderTask.
694    * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
695    */
696   void SetExclusiveRenderTask( RenderTask* renderTask )
697   {
698     mExclusiveRenderTask = renderTask;
699   }
700
701   /**
702    * Query whether the node is exclusive to a single RenderTask.
703    * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
704    */
705   RenderTask* GetExclusiveRenderTask() const
706   {
707     return mExclusiveRenderTask;
708   }
709
710   /**
711    * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
712    * @param[in] drawMode The new draw-mode to use.
713    */
714   void SetDrawMode( const DrawMode::Type& drawMode )
715   {
716     mDrawMode = drawMode;
717   }
718
719   /**
720    * Returns whether node is an overlay or not.
721    * @return True if node is an overlay, false otherwise.
722    */
723   DrawMode::Type GetDrawMode() const
724   {
725     return mDrawMode;
726   }
727
728   /*
729    * Returns the transform id of the node
730    * @return The transform component id of the node
731    */
732   TransformId GetTransformId() const
733   {
734     return mTransformId;
735   }
736
737   /**
738    * Equality operator, checks for identity, not values.
739    * @param[in]
740    */
741   bool operator==( const Node* rhs ) const
742   {
743     return ( this == rhs );
744   }
745
746   /**
747    * @brief Sets the sibling order of the node
748    * @param[in] order The new order
749    */
750   void SetDepthIndex( uint32_t depthIndex )
751   {
752     mDepthIndex = depthIndex;
753   }
754
755   /**
756    * @brief Get the depth index of the node
757    * @return Current depth index
758    */
759   uint32_t GetDepthIndex() const
760   {
761     return mDepthIndex;
762   }
763
764   /**
765    * @brief Sets the boolean which states whether the position should use the anchor-point.
766    * @param[in] positionUsesAnchorPoint True if the position should use the anchor-point
767    */
768   void SetPositionUsesAnchorPoint( bool positionUsesAnchorPoint )
769   {
770     if( mTransformId != INVALID_TRANSFORM_ID && mPositionUsesAnchorPoint != positionUsesAnchorPoint )
771     {
772       mPositionUsesAnchorPoint = positionUsesAnchorPoint;
773       mTransformManager->SetPositionUsesAnchorPoint( mTransformId, mPositionUsesAnchorPoint );
774     }
775   }
776
777   /**
778    * @brief Sets whether the node is culled or not.
779    * @param[in] bufferIndex The buffer to read from.
780    * @param[in] culled True if the node is culled.
781    */
782   void SetCulled( BufferIndex bufferIndex, bool culled )
783   {
784     mCulled[bufferIndex] = culled;
785   }
786
787   /**
788    * @brief Retrieves whether the node is culled or not.
789    * @param[in] bufferIndex The buffer to read from.
790    * @return True if the node is culled.
791    */
792   bool IsCulled( BufferIndex bufferIndex ) const
793   {
794     return mCulled[bufferIndex];
795   }
796
797 public:
798   /**
799    * @copydoc UniformMap::Add
800    */
801   void AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map );
802
803   /**
804    * @copydoc UniformMap::Remove
805    */
806   void RemoveUniformMapping( const std::string& uniformName );
807
808   /**
809    * Prepare the node for rendering.
810    * This is called by the UpdateManager when an object is due to be rendered in the current frame.
811    * @param[in] updateBufferIndex The current update buffer index.
812    */
813   void PrepareRender( BufferIndex bufferIndex );
814
815   /**
816    * Called by UpdateManager when the node is added.
817    * Creates a new transform component in the transform manager and initialize all the properties
818    * related to the transformation
819    * @param[in] transformManager A pointer to the trnasform manager (Owned by UpdateManager)
820    */
821   void CreateTransform( SceneGraph::TransformManager* transformManager );
822
823   /**
824    * Reset dirty flags
825    */
826   void ResetDirtyFlags( BufferIndex updateBufferIndex );
827
828 protected:
829
830   /**
831    * Set the parent of a Node.
832    * @param[in] parentNode the new parent.
833    */
834   void SetParent( Node& parentNode );
835
836 protected:
837
838   /**
839    * Protected constructor; See also Node::New()
840    */
841   Node();
842
843   /**
844    * Protected virtual destructor; See also Node::Delete( Node* )
845    * Kept protected to allow destructor chaining from layer
846    */
847   virtual ~Node();
848
849 private: // from NodeDataProvider
850
851   /**
852    * @copydoc NodeDataProvider::GetModelMatrix
853    */
854   virtual const Matrix& GetModelMatrix( BufferIndex bufferIndex ) const
855   {
856     return GetWorldMatrix( bufferIndex );
857   }
858
859   /**
860    * @copydoc NodeDataProvider::GetRenderColor
861    */
862   virtual const Vector4& GetRenderColor( BufferIndex bufferIndex ) const
863   {
864     return GetWorldColor( bufferIndex );
865   }
866
867 public: // From UniformMapDataProvider
868   /**
869    * @copydoc UniformMapDataProvider::GetUniformMapChanged
870    */
871   virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const
872   {
873     return mUniformMapChanged[bufferIndex];
874   }
875
876   /**
877    * @copydoc UniformMapDataProvider::GetUniformMap
878    */
879   virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const
880   {
881     return mCollectedUniformMap[bufferIndex];
882   }
883
884 private:
885
886   // Undefined
887   Node(const Node&);
888
889   // Undefined
890   Node& operator=(const Node& rhs);
891
892   /**
893    * Recursive helper to disconnect a Node and its children.
894    * Disconnected Nodes have no parent or children.
895    * @param[in] updateBufferIndex The current update buffer index.
896    */
897   void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex );
898
899 public: // Default properties
900
901   TransformManager*                  mTransformManager;
902   TransformId                        mTransformId;
903   TransformManagerPropertyVector3    mParentOrigin;           ///< Local transform; the position is relative to this. Sets the Transform flag dirty when changed
904   TransformManagerPropertyVector3    mAnchorPoint;            ///< Local transform; local center of rotation. Sets the Transform flag dirty when changed
905   TransformManagerPropertyVector3    mSize;                   ///< Size is provided for layouting
906   TransformManagerPropertyVector3    mPosition;               ///< Local transform; distance between parent-origin & anchor-point
907   TransformManagerPropertyQuaternion mOrientation;            ///< Local transform; rotation relative to parent node
908   TransformManagerPropertyVector3    mScale;                  ///< Local transform; scale relative to parent node
909
910   AnimatableProperty<bool>           mVisible;                ///< Visibility can be inherited from the Node hierachy
911   AnimatableProperty<bool>           mCulled;                 ///< True if the node is culled. This is not animatable. It is just double-buffered.
912   AnimatableProperty<Vector4>        mColor;                  ///< Color can be inherited from the Node hierarchy
913   AnimatableProperty<Vector3>        mUpdateSizeHint;         ///< Update size hint is provided for damaged area calculation. This is not animatable. It is just double-buffered. (Because all these bloody properties are).
914
915
916   // Inherited properties; read-only from public API
917
918   TransformManagerVector3Input       mWorldPosition;          ///< Full inherited position
919   TransformManagerVector3Input       mWorldScale;
920   TransformManagerQuaternionInput    mWorldOrientation;       ///< Full inherited orientation
921   TransformManagerMatrixInput        mWorldMatrix;            ///< Full inherited world matrix
922   InheritedColor                     mWorldColor;             ///< Full inherited color
923
924   uint32_t                           mClippingSortModifier;   ///< Contains bit-packed clipping information for quick access when sorting
925   const uint32_t                     mId;                     ///< The Unique ID of the node.
926
927 protected:
928
929   static uint32_t                    mNodeCounter;            ///< count of total nodes, used for unique ids
930
931   Node*                              mParent;                 ///< Pointer to parent node (a child is owned by its parent)
932   RenderTask*                        mExclusiveRenderTask;    ///< Nodes can be marked as exclusive to a single RenderTask
933
934   RendererContainer                  mRenderer;               ///< Container of renderers; not owned
935
936   NodeContainer                      mChildren;               ///< Container of children; not owned
937
938   CollectedUniformMap                mCollectedUniformMap[2]; ///< Uniform maps of the node
939   uint32_t                           mUniformMapChanged[2];   ///< Records if the uniform map has been altered this frame
940   uint32_t                           mClippingDepth;          ///< The number of stencil clipping nodes deep this node is
941   uint32_t                           mScissorDepth;           ///< The number of scissor clipping nodes deep this node is
942
943   uint32_t                           mDepthIndex;             ///< Depth index of the node
944
945   // flags, compressed to bitfield
946   NodePropertyFlags                  mDirtyFlags;             ///< Dirty flags for each of the Node properties
947   uint32_t                           mRegenerateUniformMap:2; ///< Indicate if the uniform map has to be regenerated this frame
948   DrawMode::Type                     mDrawMode:3;             ///< How the Node and its children should be drawn
949   ColorMode                          mColorMode:3;            ///< Determines whether mWorldColor is inherited, 2 bits is enough
950   ClippingMode::Type                 mClippingMode:3;         ///< The clipping mode of this node
951   bool                               mIsRoot:1;               ///< True if the node cannot have a parent
952   bool                               mIsLayer:1;              ///< True if the node is a layer
953   bool                               mPositionUsesAnchorPoint:1; ///< True if the node should use the anchor-point when calculating the position
954
955   // Changes scope, should be at end of class
956   DALI_LOG_OBJECT_STRING_DECLARATION;
957 };
958
959 // Messages for Node
960
961 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
962 {
963   typedef MessageValue1< Node, bool > LocalType;
964
965   // Reserve some memory inside the message queue
966   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
967
968   // Construct message in the message queue memory; note that delete should not be called on the return value
969   new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
970 }
971
972 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
973 {
974   typedef MessageValue1< Node, Vector3 > LocalType;
975
976   // Reserve some memory inside the message queue
977   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
978
979   // Construct message in the message queue memory; note that delete should not be called on the return value
980   new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
981 }
982
983 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
984 {
985   typedef MessageValue1< Node, Vector3 > LocalType;
986
987   // Reserve some memory inside the message queue
988   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
989
990   // Construct message in the message queue memory; note that delete should not be called on the return value
991   new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
992 }
993
994 inline void SetInheritPositionMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
995 {
996   typedef MessageValue1< Node, bool > LocalType;
997
998   // Reserve some memory inside the message queue
999   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1000
1001   // Construct message in the message queue memory; note that delete should not be called on the return value
1002   new (slot) LocalType( &node, &Node::SetInheritPosition, inherit );
1003 }
1004
1005 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1006 {
1007   typedef MessageValue1< Node, bool > LocalType;
1008
1009   // Reserve some memory inside the message queue
1010   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1011
1012   // Construct message in the message queue memory; note that delete should not be called on the return value
1013   new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1014 }
1015
1016 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
1017 {
1018   typedef MessageValue1< Node, ColorMode > LocalType;
1019
1020   // Reserve some memory inside the message queue
1021   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1022
1023   // Construct message in the message queue memory; note that delete should not be called on the return value
1024   new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1025 }
1026
1027 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
1028 {
1029   typedef MessageValue1< Node, DrawMode::Type > LocalType;
1030
1031   // Reserve some memory inside the message queue
1032   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1033
1034   // Construct message in the message queue memory; note that delete should not be called on the return value
1035   new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1036 }
1037
1038 inline void AttachRendererMessage( EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer )
1039 {
1040   typedef MessageValue1< Node, Renderer* > LocalType;
1041
1042   // Reserve some memory inside the message queue
1043   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1044
1045   // Construct message in the message queue memory; note that delete should not be called on the return value
1046   new (slot) LocalType( &node, &Node::AddRenderer, const_cast<Renderer*>( &renderer ) );
1047 }
1048
1049 inline void DetachRendererMessage( EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer )
1050 {
1051   typedef MessageValue1< Node, const Renderer* > LocalType;
1052
1053   // Reserve some memory inside the message queue
1054   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1055
1056   // Construct message in the message queue memory; note that delete should not be called on the return value
1057   new (slot) LocalType( &node, &Node::RemoveRenderer, &renderer );
1058 }
1059
1060 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Node& node, uint32_t depthIndex )
1061 {
1062   typedef MessageValue1< Node, uint32_t > LocalType;
1063
1064   // Reserve some memory inside the message queue
1065   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1066
1067   // Construct message in the message queue memory; note that delete should not be called on the return value
1068   new (slot) LocalType( &node, &Node::SetDepthIndex, depthIndex );
1069 }
1070
1071 inline void SetClippingModeMessage( EventThreadServices& eventThreadServices, const Node& node, ClippingMode::Type clippingMode )
1072 {
1073   typedef MessageValue1< Node, ClippingMode::Type > LocalType;
1074
1075   // Reserve some memory inside the message queue
1076   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1077
1078   // Construct message in the message queue memory; note that delete should not be called on the return value
1079   new (slot) LocalType( &node, &Node::SetClippingMode, clippingMode );
1080 }
1081
1082 inline void SetPositionUsesAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, bool positionUsesAnchorPoint )
1083 {
1084   typedef MessageValue1< Node, bool > LocalType;
1085
1086   // Reserve some memory inside the message queue
1087   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1088
1089   // Construct message in the message queue memory; note that delete should not be called on the return value
1090   new (slot) LocalType( &node, &Node::SetPositionUsesAnchorPoint, positionUsesAnchorPoint );
1091 }
1092
1093 } // namespace SceneGraph
1094
1095 // Template specialisation for OwnerPointer<Node>, because delete is protected
1096 template <>
1097 inline void OwnerPointer<Dali::Internal::SceneGraph::Node>::Reset()
1098 {
1099   if (mObject != NULL)
1100   {
1101     Dali::Internal::SceneGraph::Node::Delete(mObject);
1102     mObject = NULL;
1103   }
1104 }
1105 } // namespace Internal
1106
1107 // Template specialisations for OwnerContainer<Node*>, because delete is protected
1108 template <>
1109 inline void OwnerContainer<Dali::Internal::SceneGraph::Node*>::Delete( Dali::Internal::SceneGraph::Node* pointer )
1110 {
1111   Dali::Internal::SceneGraph::Node::Delete(pointer);
1112 }
1113 } // namespace Dali
1114
1115 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H