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