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