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