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