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