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