761153153c65c8faee9732ae224fa30d92863a8b
[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) 2023 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/node-helper.h>
34 #include <dali/internal/update/nodes/partial-rendering-data.h>
35 #include <dali/internal/update/rendering/scene-graph-renderer.h>
36 #include <dali/public-api/actors/actor-enumerations.h>
37 #include <dali/public-api/actors/draw-mode.h>
38 #include <dali/public-api/math/math-utils.h>
39 #include <dali/public-api/math/quaternion.h>
40 #include <dali/public-api/math/vector3.h>
41
42 namespace Dali
43 {
44 namespace Internal
45 {
46 // Value types used by messages.
47 template<>
48 struct ParameterType<ColorMode> : public BasicType<ColorMode>
49 {
50 };
51 template<>
52 struct ParameterType<ClippingMode::Type> : public BasicType<ClippingMode::Type>
53 {
54 };
55
56 namespace SceneGraph
57 {
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 to add to the node
230    */
231   void AddRenderer(const RendererKey& renderer);
232
233   /**
234    * Remove a renderer from the node
235    * @param[in] renderer The renderer to be removed
236    */
237   void RemoveRenderer(const RendererKey& renderer);
238
239   /*
240    * Get the renderer at the given index
241    * @param[in] index The index of the renderer in the node's renderer container
242    */
243   RendererKey GetRendererAt(uint32_t index) const
244   {
245     return mRenderers[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>(mRenderers.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    * Set the update area hint of the node.
669    * @param[in] updateAreaHint The update area hint.
670    */
671   void SetUpdateAreaHint(const Vector4& updateAreaHint)
672   {
673     if(mUpdateAreaChanged)
674     {
675       // Merge area if the update area is dirty
676       float x         = std::min(updateAreaHint.x - updateAreaHint.z / 2.0f, mUpdateAreaHint.x - mUpdateAreaHint.z / 2.0f);
677       float y         = std::min(updateAreaHint.y - updateAreaHint.w / 2.0f, mUpdateAreaHint.y - mUpdateAreaHint.w / 2.0f);
678       float width     = std::max(updateAreaHint.x + updateAreaHint.z / 2.0f, mUpdateAreaHint.x + mUpdateAreaHint.z / 2.0f) - x;
679       float height    = std::max(updateAreaHint.y + updateAreaHint.w / 2.0f, mUpdateAreaHint.y + mUpdateAreaHint.w / 2.0f) - y;
680       mUpdateAreaHint = Vector4(x + width / 2, y + height / 2, width, height);
681     }
682     else
683     {
684       mUpdateAreaHint    = updateAreaHint;
685       mUpdateAreaChanged = true;
686     }
687     mDirtyFlags |= NodePropertyFlags::TRANSFORM;
688   }
689
690   /**
691    * Retrieve the update area hint of the node.
692    * @return The update area hint.
693    */
694   const Vector4& GetUpdateAreaHint() const
695   {
696     return mUpdateAreaHint;
697   }
698
699   /**
700    * Retrieve the bounding sphere of the node
701    * @return A vector4 describing the bounding sphere. XYZ is the center and W is the radius
702    */
703   const Vector4& GetBoundingSphere() const
704   {
705     if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
706     {
707       return mTransformManagerData.Manager()->GetBoundingSphere(mTransformManagerData.Id());
708     }
709
710     return Vector4::ZERO;
711   }
712
713   /**
714    * Retrieve world matrix and size of the node
715    * @param[out] The local to world matrix of the node
716    * @param[out] size The current size of the node
717    */
718   void GetWorldMatrixAndSize(Matrix& worldMatrix, Vector3& size) const
719   {
720     if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
721     {
722       mTransformManagerData.Manager()->GetWorldMatrixAndSize(mTransformManagerData.Id(), worldMatrix, size);
723     }
724   }
725
726   /**
727    * Checks if local matrix has changed since last update
728    * @return true if local matrix has changed, false otherwise
729    */
730   bool IsLocalMatrixDirty() const
731   {
732     return (mTransformManagerData.Id() != INVALID_TRANSFORM_ID) &&
733            (mTransformManagerData.Manager()->IsLocalMatrixDirty(mTransformManagerData.Id()));
734   }
735
736   /**
737    * Retrieve the cached world-matrix of a node.
738    * @param[in] bufferIndex The buffer to read from.
739    * @return The world-matrix.
740    */
741   const Matrix& GetWorldMatrix(BufferIndex bufferIndex) const
742   {
743     if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
744     {
745       return mWorldMatrix.Get(bufferIndex);
746     }
747
748     return Matrix::IDENTITY;
749   }
750
751   /**
752    * Mark the node as exclusive to a single RenderTask.
753    * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
754    */
755   void SetExclusiveRenderTask(RenderTask* renderTask)
756   {
757     mExclusiveRenderTask = renderTask;
758   }
759
760   /**
761    * Query whether the node is exclusive to a single RenderTask.
762    * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
763    */
764   RenderTask* GetExclusiveRenderTask() const
765   {
766     return mExclusiveRenderTask;
767   }
768
769   /**
770    * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
771    * @param[in] drawMode The new draw-mode to use.
772    */
773   void SetDrawMode(const DrawMode::Type& drawMode)
774   {
775     mDrawMode = drawMode;
776   }
777
778   /**
779    * Returns whether node is an overlay or not.
780    * @return True if node is an overlay, false otherwise.
781    */
782   DrawMode::Type GetDrawMode() const
783   {
784     return mDrawMode;
785   }
786
787   void SetTransparent(bool transparent)
788   {
789     mTransparent = transparent;
790   }
791
792   bool IsTransparent() const
793   {
794     return mTransparent;
795   }
796
797   /*
798    * Returns the transform id of the node
799    * @return The transform component id of the node
800    */
801   TransformId GetTransformId() const
802   {
803     return mTransformManagerData.Id();
804   }
805
806   /**
807    * Equality operator, checks for identity, not values.
808    * @param[in]
809    */
810   bool operator==(const Node* rhs) const
811   {
812     return (this == rhs);
813   }
814
815   /**
816    * @brief Sets the sibling order of the node
817    * @param[in] order The new order
818    */
819   void SetDepthIndex(uint32_t depthIndex)
820   {
821     if(depthIndex != mDepthIndex)
822     {
823       if(mParent)
824       {
825         // Send CHILDREN_REORDER dirty flag only if my depth index changed.
826         mParent->SetDirtyFlag(NodePropertyFlags::CHILDREN_REORDER);
827       }
828       SetUpdated(true);
829       mDepthIndex = depthIndex;
830     }
831   }
832
833   /**
834    * @brief Get the depth index of the node
835    * @return Current depth index
836    */
837   uint32_t GetDepthIndex() const
838   {
839     return mDepthIndex;
840   }
841
842   /**
843    * @brief Get whether children sibiling order need to be changed. s.t. child's depth index changed.
844    * @note It will be reset when mDirtyFlag reseted.
845    * @return True if children sibiling order need to be changed.
846    */
847   uint32_t IsChildrenReorderRequired() const
848   {
849     return mDirtyFlags & NodePropertyFlags::CHILDREN_REORDER;
850   }
851
852   /**
853    * @brief Sets the boolean which states whether the position should use the anchor-point.
854    * @param[in] positionUsesAnchorPoint True if the position should use the anchor-point
855    */
856   void SetPositionUsesAnchorPoint(bool positionUsesAnchorPoint)
857   {
858     if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID && mPositionUsesAnchorPoint != positionUsesAnchorPoint)
859     {
860       mPositionUsesAnchorPoint = positionUsesAnchorPoint;
861       mTransformManagerData.Manager()->SetPositionUsesAnchorPoint(mTransformManagerData.Id(), mPositionUsesAnchorPoint);
862     }
863   }
864
865   /**
866    * @brief Sets whether the node is culled or not.
867    * @param[in] bufferIndex The buffer to read from.
868    * @param[in] culled True if the node is culled.
869    */
870   void SetCulled(BufferIndex bufferIndex, bool culled)
871   {
872     mCulled[bufferIndex] = culled;
873   }
874
875   /**
876    * @brief Retrieves whether the node is culled or not.
877    * @param[in] bufferIndex The buffer to read from.
878    * @return True if the node is culled.
879    */
880   bool IsCulled(BufferIndex bufferIndex) const
881   {
882     return mCulled[bufferIndex];
883   }
884
885   /**
886    * @brief Get the total capacity of the memory pools
887    * @return The capacity of the memory pools
888    *
889    * @note This is different to the node count.
890    */
891   static uint32_t GetMemoryPoolCapacity();
892
893   /**
894    * @brief Returns partial rendering data associated with the node.
895    * @return The partial rendering data
896    */
897   PartialRenderingData& GetPartialRenderingData()
898   {
899     return mPartialRenderingData;
900   }
901
902 public:
903   /**
904    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::IsAnimationPossible
905    */
906   bool IsAnimationPossible() const override;
907
908   /**
909    * Called by UpdateManager when the node is added.
910    * Creates a new transform component in the transform manager and initialize all the properties
911    * related to the transformation
912    * @param[in] transformManager A pointer to the trnasform manager (Owned by UpdateManager)
913    */
914   void CreateTransform(SceneGraph::TransformManager* transformManager);
915
916   /**
917    * Reset dirty flags
918    */
919   void ResetDirtyFlags(BufferIndex updateBufferIndex);
920
921   /**
922    * Update uniform hash
923    * @param[in] bufferIndex The buffer to read from.
924    */
925   void UpdateUniformHash(BufferIndex bufferIndex);
926
927 protected:
928   /**
929    * Set the parent of a Node.
930    * @param[in] parentNode the new parent.
931    */
932   void SetParent(Node& parentNode);
933
934 protected:
935   /**
936    * Protected constructor; See also Node::New()
937    */
938   Node();
939
940   /**
941    * Protected virtual destructor; See also Node::Delete( Node* )
942    * Kept protected to allow destructor chaining from layer
943    */
944   ~Node() override;
945
946 private: // from NodeDataProvider
947   /**
948    * @copydoc NodeDataProvider::GetRenderColor
949    */
950   const Vector4& GetRenderColor(BufferIndex bufferIndex) const override
951   {
952     return GetWorldColor(bufferIndex);
953   }
954
955   /**
956    * @copydoc NodeDataProvider::GetNodeUniformMap
957    */
958   const UniformMap& GetNodeUniformMap() const override
959   {
960     return GetUniformMap();
961   }
962
963 private:
964   // Delete copy and move
965   Node(const Node&) = delete;
966   Node(Node&&)      = delete;
967   Node& operator=(const Node& rhs) = delete;
968   Node& operator=(Node&& rhs) = delete;
969
970   /**
971    * Recursive helper to disconnect a Node and its children.
972    * Disconnected Nodes have no parent or children.
973    * @param[in] updateBufferIndex The current update buffer index.
974    */
975   void RecursiveDisconnectFromSceneGraph(BufferIndex updateBufferIndex);
976
977 public: // Default properties
978   // Define a base offset for the following wrappers. The wrapper macros calculate offsets from the previous
979   // element such that each wrapper type generates a compile time offset to the transform manager data.
980   BASE(TransformManagerData, mTransformManagerData);
981   PROPERTY_WRAPPER(mTransformManagerData, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_PARENT_ORIGIN,
982                    mParentOrigin); // Local transform; the position is relative to this. Sets the Transform flag dirty when changed
983
984   PROPERTY_WRAPPER(mParentOrigin, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_ANCHOR_POINT,
985                    mAnchorPoint); // Local transform; local center of rotation. Sets the Transform flag dirty when changed
986
987   PROPERTY_WRAPPER(mAnchorPoint, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_SIZE,
988                    mSize); // Size is provided for layouting
989
990   PROPERTY_WRAPPER(mSize, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_POSITION,
991                    mPosition); // Local transform; distance between parent-origin & anchor-point
992   PROPERTY_WRAPPER(mPosition, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_SCALE,
993                    mScale); // Local transform; scale relative to parent node
994
995   TEMPLATE_WRAPPER(mScale, TransformManagerPropertyQuaternion,
996                    mOrientation); // Local transform; rotation relative to parent node
997
998   // Inherited properties; read-only from public API
999   TEMPLATE_WRAPPER(mOrientation, TransformManagerVector3Input, mWorldPosition);      // Full inherited position
1000   TEMPLATE_WRAPPER(mWorldPosition, TransformManagerVector3Input, mWorldScale);       // Full inherited scale
1001   TEMPLATE_WRAPPER(mWorldScale, TransformManagerQuaternionInput, mWorldOrientation); // Full inherited orientation
1002   TEMPLATE_WRAPPER(mWorldOrientation, TransformManagerMatrixInput, mWorldMatrix);    // Full inherited world matrix
1003
1004   AnimatableProperty<bool>    mVisible;        ///< Visibility can be inherited from the Node hierachy
1005   AnimatableProperty<bool>    mCulled;         ///< True if the node is culled. This is not animatable. It is just double-buffered.
1006   AnimatableProperty<Vector4> mColor;          ///< Color can be inherited from the Node hierarchy
1007   InheritedColor              mWorldColor;     ///< Full inherited color
1008   Vector4                     mUpdateAreaHint; ///< Update area hint is provided for damaged area calculation. (x, y, width, height)
1009
1010   uint64_t       mUniformsHash{0u};     ///< Hash of uniform map property values
1011   uint32_t       mClippingSortModifier; ///< Contains bit-packed clipping information for quick access when sorting
1012   const uint32_t mId;                   ///< The Unique ID of the node.
1013
1014 protected:
1015   static uint32_t mNodeCounter; ///< count of total nodes, used for unique ids
1016
1017   PartialRenderingData mPartialRenderingData; ///< Cache to determine if this should be rendered again
1018
1019   Node*       mParent;              ///< Pointer to parent node (a child is owned by its parent)
1020   RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1021
1022   RendererContainer mRenderers; ///< Container of renderers; not owned
1023
1024   NodeContainer mChildren; ///< Container of children; not owned
1025
1026   uint32_t mClippingDepth; ///< The number of stencil clipping nodes deep this node is
1027   uint32_t mScissorDepth;  ///< The number of scissor clipping nodes deep this node is
1028   uint32_t mDepthIndex;    ///< Depth index of the node
1029
1030   // flags, compressed to bitfield
1031   NodePropertyFlags  mDirtyFlags;                  ///< Dirty flags for each of the Node properties
1032   DrawMode::Type     mDrawMode : 3;                ///< How the Node and its children should be drawn
1033   ColorMode          mColorMode : 3;               ///< Determines whether mWorldColor is inherited, 2 bits is enough
1034   ClippingMode::Type mClippingMode : 3;            ///< The clipping mode of this node
1035   bool               mIsRoot : 1;                  ///< True if the node cannot have a parent
1036   bool               mIsLayer : 1;                 ///< True if the node is a layer
1037   bool               mIsCamera : 1;                ///< True if the node is a camera
1038   bool               mPositionUsesAnchorPoint : 1; ///< True if the node should use the anchor-point when calculating the position
1039   bool               mTransparent : 1;             ///< True if this node is transparent. This value do not affect children.
1040   bool               mUpdateAreaChanged : 1;       ///< True if the update area of the node is changed.
1041
1042   // Changes scope, should be at end of class
1043   DALI_LOG_OBJECT_STRING_DECLARATION;
1044 };
1045
1046 // Messages for Node
1047
1048 inline void SetInheritOrientationMessage(EventThreadServices& eventThreadServices, const Node& node, bool inherit)
1049 {
1050   using LocalType = MessageValue1<Node, bool>;
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::SetInheritOrientation, inherit);
1057 }
1058
1059 inline void SetParentOriginMessage(EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin)
1060 {
1061   using LocalType = MessageValue1<Node, Vector3>;
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::SetParentOrigin, origin);
1068 }
1069
1070 inline void SetAnchorPointMessage(EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor)
1071 {
1072   using LocalType = MessageValue1<Node, Vector3>;
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::SetAnchorPoint, anchor);
1079 }
1080
1081 inline void SetInheritPositionMessage(EventThreadServices& eventThreadServices, const Node& node, bool inherit)
1082 {
1083   using LocalType = MessageValue1<Node, bool>;
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::SetInheritPosition, inherit);
1090 }
1091
1092 inline void SetInheritScaleMessage(EventThreadServices& eventThreadServices, const Node& node, bool inherit)
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::SetInheritScale, inherit);
1101 }
1102
1103 inline void SetColorModeMessage(EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode)
1104 {
1105   using LocalType = MessageValue1<Node, ColorMode>;
1106
1107   // Reserve some memory inside the message queue
1108   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1109
1110   // Construct message in the message queue memory; note that delete should not be called on the return value
1111   new(slot) LocalType(&node, &Node::SetColorMode, colorMode);
1112 }
1113
1114 inline void SetDrawModeMessage(EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode)
1115 {
1116   using LocalType = MessageValue1<Node, DrawMode::Type>;
1117
1118   // Reserve some memory inside the message queue
1119   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1120
1121   // Construct message in the message queue memory; note that delete should not be called on the return value
1122   new(slot) LocalType(&node, &Node::SetDrawMode, drawMode);
1123 }
1124
1125 inline void SetTransparentMessage(EventThreadServices& eventThreadServices, const Node& node, bool transparent)
1126 {
1127   using LocalType = MessageValue1<Node, bool>;
1128
1129   // Reserve some memory inside the message queue
1130   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1131
1132   // Construct message in the message queue memory; note that delete should not be called on the return value
1133   new(slot) LocalType(&node, &Node::SetTransparent, transparent);
1134 }
1135
1136 inline void DetachRendererMessage(EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer)
1137 {
1138   using LocalType = MessageValue1<Node, RendererKey>;
1139
1140   // Reserve some memory inside the message queue
1141   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1142
1143   // Construct message in the message queue memory; note that delete should not be called on the return value
1144   new(slot) LocalType(&node, &Node::RemoveRenderer, Renderer::GetKey(renderer));
1145 }
1146
1147 inline void SetDepthIndexMessage(EventThreadServices& eventThreadServices, const Node& node, uint32_t depthIndex)
1148 {
1149   using LocalType = MessageValue1<Node, uint32_t>;
1150
1151   // Reserve some memory inside the message queue
1152   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1153
1154   // Construct message in the message queue memory; note that delete should not be called on the return value
1155   new(slot) LocalType(&node, &Node::SetDepthIndex, depthIndex);
1156 }
1157
1158 inline void SetClippingModeMessage(EventThreadServices& eventThreadServices, const Node& node, ClippingMode::Type clippingMode)
1159 {
1160   using LocalType = MessageValue1<Node, ClippingMode::Type>;
1161
1162   // Reserve some memory inside the message queue
1163   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1164
1165   // Construct message in the message queue memory; note that delete should not be called on the return value
1166   new(slot) LocalType(&node, &Node::SetClippingMode, clippingMode);
1167 }
1168
1169 inline void SetPositionUsesAnchorPointMessage(EventThreadServices& eventThreadServices, const Node& node, bool positionUsesAnchorPoint)
1170 {
1171   using LocalType = MessageValue1<Node, bool>;
1172
1173   // Reserve some memory inside the message queue
1174   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1175
1176   // Construct message in the message queue memory; note that delete should not be called on the return value
1177   new(slot) LocalType(&node, &Node::SetPositionUsesAnchorPoint, positionUsesAnchorPoint);
1178 }
1179
1180 inline void SetUpdateAreaHintMessage(EventThreadServices& eventThreadServices, const Node& node, const Vector4& updateAreaHint)
1181 {
1182   using LocalType = MessageValue1<Node, Vector4>;
1183
1184   // Reserve some memory inside the message queue
1185   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1186
1187   // Construct message in the message queue memory; note that delete should not be called on the return value
1188   new(slot) LocalType(&node, &Node::SetUpdateAreaHint, updateAreaHint);
1189 }
1190
1191 } // namespace SceneGraph
1192
1193 // Template specialisation for OwnerPointer<Node>, because delete is protected
1194 template<>
1195 inline void OwnerPointer<Dali::Internal::SceneGraph::Node>::Reset()
1196 {
1197   if(mObject != nullptr)
1198   {
1199     Dali::Internal::SceneGraph::Node::Delete(mObject);
1200     mObject = nullptr;
1201   }
1202 }
1203 } // namespace Internal
1204
1205 // Template specialisations for OwnerContainer<Node*>, because delete is protected
1206 template<>
1207 inline void OwnerContainer<Dali::Internal::SceneGraph::Node*>::Delete(Dali::Internal::SceneGraph::Node* pointer)
1208 {
1209   Dali::Internal::SceneGraph::Node::Delete(pointer);
1210 }
1211 } // namespace Dali
1212
1213 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H