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