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