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