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