1 #ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_NODE_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
46 // Value types used by messages.
48 struct ParameterType<ColorMode> : public BasicType<ColorMode>
52 struct ParameterType<ClippingMode::Type> : public BasicType<ClippingMode::Type>
61 class ResetterManager;
64 // Flags which require the scene renderable lists to be updated
65 static NodePropertyFlags RenderableUpdateFlags = NodePropertyFlags::TRANSFORM | NodePropertyFlags::CHILD_DELETED;
68 * Node is the base class for all nodes in the Scene Graph.
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.
75 class Node : public PropertyOwner, public NodeDataProvider
78 using RenderTaskContainer = std::vector<RenderTask*>;
81 static const ColorMode DEFAULT_COLOR_MODE;
86 * Construct a new Node.
93 static void Delete(Node* node);
96 * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
101 * @return the unique ID of the node
103 uint32_t GetId() const;
108 * Query whether the node is a layer.
109 * @return True if the node is a layer.
117 * Convert a node to a layer.
118 * @return A pointer to the layer, or NULL.
120 virtual Layer* GetLayer()
128 * Query whether the node is a camera.
129 * @return True if the node is a camera.
131 bool IsCamera() const
137 * Mark an node and its sub tree according to the updated flag.
138 * @param[in] updated The updated flag
139 * (used for partial rendering to mark an animating sub tree for example).
141 void SetUpdatedTree(bool updated)
145 for(Node* child : mChildren)
147 child->SetUpdatedTree(updated);
152 * This method sets clipping information on the node based on its hierarchy in the scene-graph.
153 * A value is calculated that can be used during sorting to increase sort speed.
154 * @param[in] clippingId The Clipping ID of the node to set
155 * @param[in] clippingDepth The Clipping Depth of the node to set
156 * @param[in] scissorDepth The Scissor Clipping Depth of the node to set
158 void SetClippingInformation(const uint32_t clippingId, const uint32_t clippingDepth, const uint32_t scissorDepth)
160 // We only set up the sort value if we have a stencil clipping depth, IE. At least 1 clipping node has been hit.
161 // If not, if we traverse down a clipping tree and back up, and there is another
162 // node on the parent, this will have a non-zero clipping ID that must be ignored
163 if(clippingDepth > 0u)
165 mClippingDepth = clippingDepth;
167 // Calculate the sort value here on write, as when read (during sort) it may be accessed several times.
168 // The items must be sorted by Clipping ID first (so the ID is kept in the most-significant bits).
169 // For the same ID, the clipping nodes must be first, so we negate the
170 // clipping enabled flag and set it as the least significant bit.
171 mClippingSortModifier = (clippingId << 1u) | (mClippingMode == ClippingMode::DISABLED ? 1u : 0u);
175 // If we do not have a clipping depth, then set this to 0 so we do not have a Clipping ID either.
176 mClippingSortModifier = 0u;
179 // The scissor depth does not modify the clipping sort modifier (as scissor clips are 2D only).
180 // For this reason we can always update the member variable.
181 mScissorDepth = scissorDepth;
185 * Gets the Clipping ID for this node.
186 * @return The Clipping ID for this node.
188 uint32_t GetClippingId() const
190 return mClippingSortModifier >> 1u;
194 * Gets the Clipping Depth for this node.
195 * @return The Clipping Depth for this node.
197 uint32_t GetClippingDepth() const
199 return mClippingDepth;
203 * Gets the Scissor Clipping Depth for this node.
204 * @return The Scissor Clipping Depth for this node.
206 uint32_t GetScissorDepth() const
208 return mScissorDepth;
212 * Sets the clipping mode for this node.
213 * @param[in] clippingMode The ClippingMode to set
215 void SetClippingMode(const ClippingMode::Type clippingMode)
217 mClippingMode = clippingMode;
218 SetDirtyFlag(NodePropertyFlags::TRANSFORM);
222 * Gets the Clipping Mode for this node.
223 * @return The ClippingMode of this node
225 ClippingMode::Type GetClippingMode() const
227 return mClippingMode;
231 * Add a renderer to the node
232 * @param[in] renderer The renderer to add to the node
234 void AddRenderer(const RendererKey& renderer);
237 * Remove a renderer from the node
238 * @param[in] renderer The renderer to be removed
240 void RemoveRenderer(const RendererKey& renderer);
243 * Get the renderer at the given index
244 * @param[in] index The index of the renderer in the node's renderer container
246 RendererKey GetRendererAt(uint32_t index) const
248 return mRenderers[index];
252 * Retrieve the number of renderers for the node
254 uint32_t GetRendererCount() const
256 return static_cast<uint32_t>(mRenderers.Size());
259 // Containment methods
262 * Query whether a node is the root node. Root nodes cannot have a parent node.
263 * A node becomes a root node, when it is installed by UpdateManager.
264 * @return True if the node is a root node.
272 * Set whether a node is the root node. Root nodes cannot have a parent node.
273 * This method should only be called by UpdateManager.
274 * @pre When isRoot is true, the node must not have a parent.
275 * @param[in] isRoot Whether the node is now a root node.
277 void SetRoot(bool isRoot);
280 * Retrieve the parent of a Node.
281 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
289 * Retrieve the parent of a Node.
290 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
292 const Node* GetParent() const
298 * @return true if the node is connected to SceneGraph
300 bool ConnectedToScene()
302 return IsRoot() || GetParent();
306 * Connect a node to the scene-graph.
307 * @pre A node cannot be added to itself.
308 * @pre The parent node is connected to the scene-graph.
309 * @pre The childNode does not already have a parent.
310 * @pre The childNode is not a root node.
311 * @param[in] childNode The child to add.
313 void ConnectChild(Node* childNode);
316 * Disconnect a child (& its children) from the scene-graph.
317 * @pre childNode is a child of this Node.
318 * @param[in] updateBufferIndex The current update buffer index.
319 * @param[in] childNode The node to disconnect.
321 void DisconnectChild(BufferIndex updateBufferIndex, Node& childNode);
324 * Retrieve the children a Node.
325 * @return The container of children.
327 const NodeContainer& GetChildren() const
333 * Retrieve the children a Node.
334 * @return The container of children.
336 NodeContainer& GetChildren()
344 * Flag that one of the node values has changed in the current frame.
345 * @param[in] flag The flag to set.
347 void SetDirtyFlag(NodePropertyFlags flag)
353 * Flag that all of the node values are dirty.
355 void SetAllDirtyFlags()
357 mDirtyFlags = NodePropertyFlags::ALL;
361 * Query whether a node is dirty.
362 * @return The dirty flags
364 NodePropertyFlags GetDirtyFlags() const;
367 * Query inherited dirty flags.
369 * @param The parentFlags to or with
370 * @return The inherited dirty flags
372 NodePropertyFlags GetInheritedDirtyFlags(NodePropertyFlags parentFlags) const;
375 * Retrieve the parent-origin of the node.
376 * @return The parent-origin.
378 const Vector3& GetParentOrigin() const
380 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
382 return mParentOrigin.Get(0);
385 return Vector3::ZERO;
389 * Sets both the local & base parent-origins of the node.
390 * @param[in] origin The new local & base parent-origins.
392 void SetParentOrigin(const Vector3& origin)
394 mParentOrigin.Set(0, origin);
398 * Retrieve the anchor-point of the node.
399 * @return The anchor-point.
401 const Vector3& GetAnchorPoint() const
403 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
405 return mAnchorPoint.Get(0);
408 return Vector3::ZERO;
412 * Sets both the local & base anchor-points of the node.
413 * @param[in] anchor The new local & base anchor-points.
415 void SetAnchorPoint(const Vector3& anchor)
417 mAnchorPoint.Set(0, anchor);
421 * Retrieve the local position of the node, relative to its parent.
422 * @param[in] bufferIndex The buffer to read from.
423 * @return The local position.
425 const Vector3& GetPosition(BufferIndex bufferIndex) const
427 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
429 return mPosition.Get(bufferIndex);
432 return Vector3::ZERO;
436 * Retrieve the position of the node derived from the position of all its parents.
437 * @return The world position.
439 const Vector3& GetWorldPosition(BufferIndex bufferIndex) const
441 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
443 return mWorldPosition.Get(bufferIndex);
445 return Vector3::ZERO;
449 * Set whether the Node inherits position.
450 * @param[in] inherit True if the parent position is inherited.
452 void SetInheritPosition(bool inherit)
454 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
456 mTransformManagerData.Manager()->SetInheritPosition(mTransformManagerData.Id(), inherit);
461 * Retrieve the local orientation of the node, relative to its parent.
462 * @param[in] bufferIndex The buffer to read from.
463 * @return The local orientation.
465 const Quaternion& GetOrientation(BufferIndex bufferIndex) const
467 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
469 return mOrientation.Get(0);
472 return Quaternion::IDENTITY;
476 * Retrieve the orientation of the node derived from the rotation of all its parents.
477 * @param[in] bufferIndex The buffer to read from.
478 * @return The world rotation.
480 const Quaternion& GetWorldOrientation(BufferIndex bufferIndex) const
482 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
484 return mWorldOrientation.Get(0);
486 return Quaternion::IDENTITY;
490 * Set whether the Node inherits orientation.
491 * @param[in] inherit True if the parent orientation is inherited.
493 void SetInheritOrientation(bool inherit)
495 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
497 mTransformManagerData.Manager()->SetInheritOrientation(mTransformManagerData.Id(), inherit);
502 * Retrieve the local scale of the node, relative to its parent.
503 * @param[in] bufferIndex The buffer to read from.
504 * @return The local scale.
506 const Vector3& GetScale(BufferIndex bufferIndex) const
508 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
510 return mScale.Get(0);
517 * Retrieve the scale of the node derived from the scale of all its parents.
518 * @param[in] bufferIndex The buffer to read from.
519 * @return The world scale.
521 const Vector3& GetWorldScale(BufferIndex bufferIndex) const
523 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
525 return mWorldScale.Get(0);
531 * Set whether the Node inherits scale.
532 * @param inherit True if the Node inherits scale.
534 void SetInheritScale(bool inherit)
536 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
538 mTransformManagerData.Manager()->SetInheritScale(mTransformManagerData.Id(), inherit);
543 * Retrieve the visibility of the node.
544 * @param[in] bufferIndex The buffer to read from.
545 * @return True if the node is visible.
547 bool IsVisible(BufferIndex bufferIndex) const
549 return mVisible[bufferIndex];
553 * Retrieve the opacity of the node.
554 * @param[in] bufferIndex The buffer to read from.
555 * @return The opacity.
557 float GetOpacity(BufferIndex bufferIndex) const
559 return mColor[bufferIndex].a;
563 * Retrieve the color of the node.
564 * @param[in] bufferIndex The buffer to read from.
567 const Vector4& GetColor(BufferIndex bufferIndex) const
569 return mColor[bufferIndex];
573 * Sets the color of the node derived from the color of all its parents.
574 * @param[in] color The world color.
575 * @param[in] updateBufferIndex The current update buffer index.
577 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
579 mWorldColor.Set(updateBufferIndex, color);
583 * Sets the color of the node derived from the color of all its parents.
584 * This method should only be called when the parents world color is up-to-date.
585 * @pre The node has a parent.
586 * @param[in] updateBufferIndex The current update buffer index.
588 void InheritWorldColor(BufferIndex updateBufferIndex)
590 DALI_ASSERT_DEBUG(mParent != NULL);
593 if(mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA)
595 const Vector4& ownColor = mColor[updateBufferIndex];
596 mWorldColor.Set(updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a);
598 else if(mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR)
600 mWorldColor.Set(updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex]);
602 else if(mColorMode == USE_PARENT_COLOR)
604 mWorldColor.Set(updateBufferIndex, mParent->GetWorldColor(updateBufferIndex));
606 else // USE_OWN_COLOR
608 mWorldColor.Set(updateBufferIndex, mColor[updateBufferIndex]);
613 * Copies the previous inherited scale, if this changed in the previous frame.
614 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
615 * does not need to be recalculated in the current frame.
616 * @param[in] updateBufferIndex The current update buffer index.
618 void CopyPreviousWorldColor(BufferIndex updateBufferIndex)
620 mWorldColor.CopyPrevious(updateBufferIndex);
624 * Retrieve the color of the node, possibly derived from the color
625 * of all its parents, depending on the value of mColorMode.
626 * @param[in] bufferIndex The buffer to read from.
627 * @return The world color.
629 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
631 return mWorldColor[bufferIndex];
635 * Set the color mode. This specifies whether the Node uses its own color,
636 * or inherits its parent color.
637 * @param[in] colorMode The new color mode.
639 void SetColorMode(ColorMode colorMode)
641 mColorMode = colorMode;
643 SetDirtyFlag(NodePropertyFlags::COLOR);
647 * Retrieve the color mode.
648 * @return The color mode.
650 ColorMode GetColorMode() const
656 * Retrieve the size of the node.
657 * @param[in] bufferIndex The buffer to read from.
660 const Vector3& GetSize(BufferIndex bufferIndex) const
662 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
667 return Vector3::ZERO;
671 * Set the update area hint of the node.
672 * @param[in] updateAreaHint The update area hint.
674 void SetUpdateAreaHint(const Vector4& updateAreaHint)
676 if(mUpdateAreaChanged)
678 // Merge area if the update area is dirty
679 float x = std::min(updateAreaHint.x - updateAreaHint.z / 2.0f, mUpdateAreaHint.x - mUpdateAreaHint.z / 2.0f);
680 float y = std::min(updateAreaHint.y - updateAreaHint.w / 2.0f, mUpdateAreaHint.y - mUpdateAreaHint.w / 2.0f);
681 float width = std::max(updateAreaHint.x + updateAreaHint.z / 2.0f, mUpdateAreaHint.x + mUpdateAreaHint.z / 2.0f) - x;
682 float height = std::max(updateAreaHint.y + updateAreaHint.w / 2.0f, mUpdateAreaHint.y + mUpdateAreaHint.w / 2.0f) - y;
683 mUpdateAreaHint = Vector4(x + width / 2, y + height / 2, width, height);
687 mUpdateAreaHint = updateAreaHint;
688 mUpdateAreaChanged = true;
690 mDirtyFlags |= NodePropertyFlags::TRANSFORM;
694 * Retrieve the update area hint of the node.
695 * @return The update area hint.
697 const Vector4& GetUpdateAreaHint() const
699 return mUpdateAreaHint;
702 void UseTextureUpdateArea(bool useTextureUpdateArea)
704 mUseTextureUpdateArea = useTextureUpdateArea;
707 bool IsTextureUpdateAreaUsed() const
709 return mUseTextureUpdateArea;
713 * Retrieve the bounding sphere of the node
714 * @return A vector4 describing the bounding sphere. XYZ is the center and W is the radius
716 const Vector4& GetBoundingSphere() const
718 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
720 return mTransformManagerData.Manager()->GetBoundingSphere(mTransformManagerData.Id());
723 return Vector4::ZERO;
727 * Retrieve world matrix and size of the node
728 * @param[out] The local to world matrix of the node
729 * @param[out] size The current size of the node
731 void GetWorldMatrixAndSize(Matrix& worldMatrix, Vector3& size) const
733 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
735 mTransformManagerData.Manager()->GetWorldMatrixAndSize(mTransformManagerData.Id(), worldMatrix, size);
740 * Checks if local matrix has changed since last update
741 * @return true if local matrix has changed, false otherwise
743 bool IsLocalMatrixDirty() const
745 return (mTransformManagerData.Id() != INVALID_TRANSFORM_ID) &&
746 (mTransformManagerData.Manager()->IsLocalMatrixDirty(mTransformManagerData.Id()));
750 * Retrieve the cached world-matrix of a node.
751 * @param[in] bufferIndex The buffer to read from.
752 * @return The world-matrix.
754 const Matrix& GetWorldMatrix(BufferIndex bufferIndex) const
756 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
758 return mWorldMatrix.Get(bufferIndex);
761 return Matrix::IDENTITY;
765 * Add RenderTask that will exclusively render this node.
766 * @param[in] renderTask The render-task to render this node exclusively.
768 void AddExclusiveRenderTask(RenderTask* renderTask)
770 auto found = std::find(mExclusiveRenderTasks.begin(), mExclusiveRenderTasks.end(), renderTask);
771 if(found == mExclusiveRenderTasks.end())
773 mExclusiveRenderTasks.push_back(renderTask);
778 * Remove a RenderTask from exclusive render task queue.
779 * The RenderTask cannot render this node if this node is exclusive to other RenderTasks.
780 * @param[in] renderTask The render-task to be removed from exclusive render task queue.
782 void RemoveExclusiveRenderTask(RenderTask* renderTask)
784 auto found = std::find(mExclusiveRenderTasks.begin(), mExclusiveRenderTasks.end(), renderTask);
785 if(found != mExclusiveRenderTasks.end())
787 mExclusiveRenderTasks.erase(found);
792 * Retrieves the number of exclusive RenderTask for this node.
793 * @return The number of exclusive RenderTask.
795 uint32_t GetExclusiveRenderTaskCount()
797 return mExclusiveRenderTasks.size();
801 * Query whether the node is exclusive to the renderTask.
802 * @return true if this node is exclusive to the renderTask.
804 bool IsExclusiveRenderTask(const RenderTask* renderTask) const
806 auto found = std::find(mExclusiveRenderTasks.begin(), mExclusiveRenderTasks.end(), renderTask);
807 if(found != mExclusiveRenderTasks.end())
815 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
816 * @param[in] drawMode The new draw-mode to use.
818 void SetDrawMode(const DrawMode::Type& drawMode)
820 mDrawMode = drawMode;
824 * Returns whether node is an overlay or not.
825 * @return True if node is an overlay, false otherwise.
827 DrawMode::Type GetDrawMode() const
832 void SetTransparent(bool transparent)
834 mTransparent = transparent;
837 bool IsTransparent() const
843 * Returns the transform id of the node
844 * @return The transform component id of the node
846 TransformId GetTransformId() const
848 return mTransformManagerData.Id();
852 * Equality operator, checks for identity, not values.
855 bool operator==(const Node* rhs) const
857 return (this == rhs);
861 * @brief Sets the sibling order of the node
862 * @param[in] order The new order
864 void SetDepthIndex(uint32_t depthIndex)
866 if(depthIndex != mDepthIndex)
870 // Send CHILDREN_REORDER dirty flag only if my depth index changed.
871 mParent->SetDirtyFlag(NodePropertyFlags::CHILDREN_REORDER);
874 mDepthIndex = depthIndex;
879 * @brief Get the depth index of the node
880 * @return Current depth index
882 uint32_t GetDepthIndex() const
888 * @brief Get whether children sibiling order need to be changed. s.t. child's depth index changed.
889 * @note It will be reset when mDirtyFlag reseted.
890 * @return True if children sibiling order need to be changed.
892 bool IsChildrenReorderRequired() const
894 return mDirtyFlags & NodePropertyFlags::CHILDREN_REORDER;
898 * @brief Get whether descendent hierarchy was changed.
899 * @pre The flag will be propagate at UpdateManager::SetDepthIndices().
900 * @note It will be reset when mDirtyFlag reseted.
901 * @return True if children sibiling order need to be changed.
903 bool IsDescendentHierarchyChanged() const
905 return mDirtyFlags & NodePropertyFlags::DESCENDENT_HIERARCHY_CHANGED;
909 * @brief Propagate the heirarchy changeness flag to it's parent node.
911 void PropagateDescendentFlags()
913 if(IsDescendentHierarchyChanged() && mParent)
915 mParent->SetDirtyFlag(NodePropertyFlags::DESCENDENT_HIERARCHY_CHANGED);
920 * @brief Sets the boolean which states whether the position should use the anchor-point.
921 * @param[in] positionUsesAnchorPoint True if the position should use the anchor-point
923 void SetPositionUsesAnchorPoint(bool positionUsesAnchorPoint)
925 if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID && mPositionUsesAnchorPoint != positionUsesAnchorPoint)
927 mPositionUsesAnchorPoint = positionUsesAnchorPoint;
928 mTransformManagerData.Manager()->SetPositionUsesAnchorPoint(mTransformManagerData.Id(), mPositionUsesAnchorPoint);
933 * @brief Sets whether the node is culled or not.
934 * @param[in] bufferIndex The buffer to read from.
935 * @param[in] culled True if the node is culled.
937 void SetCulled(BufferIndex bufferIndex, bool culled)
939 mCulled[bufferIndex] = culled;
943 * @brief Retrieves whether the node is culled or not.
944 * @param[in] bufferIndex The buffer to read from.
945 * @return True if the node is culled.
947 bool IsCulled(BufferIndex bufferIndex) const
949 return mCulled[bufferIndex];
953 * @brief Get the total capacity of the memory pools
954 * @return The capacity of the memory pools
956 * @note This is different to the node count.
958 static uint32_t GetMemoryPoolCapacity();
961 * @brief Returns partial rendering data associated with the node.
962 * @return The partial rendering data
964 PartialRenderingData& GetPartialRenderingData()
966 return mPartialRenderingData;
971 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::IsAnimationPossible
973 bool IsAnimationPossible() const override;
976 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::AddInitializeResetter
978 void AddInitializeResetter(ResetterManager& manager) const override;
981 * Called by UpdateManager when the node is added.
982 * Creates a new transform component in the transform manager and initialize all the properties
983 * related to the transformation
984 * @param[in] transformManager A pointer to the trnasform manager (Owned by UpdateManager)
986 void CreateTransform(SceneGraph::TransformManager* transformManager);
991 void ResetDirtyFlags(BufferIndex updateBufferIndex);
995 * Set the parent of a Node.
996 * @param[in] parentNode the new parent.
998 void SetParent(Node& parentNode);
1002 * Protected constructor; See also Node::New()
1007 * Protected virtual destructor; See also Node::Delete( Node* )
1008 * Kept protected to allow destructor chaining from layer
1012 private: // from NodeDataProvider
1014 * @copydoc NodeDataProvider::GetRenderColor
1016 const Vector4& GetRenderColor(BufferIndex bufferIndex) const override
1018 return GetWorldColor(bufferIndex);
1022 * @copydoc NodeDataProvider::GetNodeUniformMap
1024 const UniformMap& GetNodeUniformMap() const override
1026 return GetUniformMap();
1030 // Delete copy and move
1031 Node(const Node&) = delete;
1032 Node(Node&&) = delete;
1033 Node& operator=(const Node& rhs) = delete;
1034 Node& operator=(Node&& rhs) = delete;
1037 * Recursive helper to disconnect a Node and its children.
1038 * Disconnected Nodes have no parent or children.
1039 * @param[in] updateBufferIndex The current update buffer index.
1041 void RecursiveDisconnectFromSceneGraph(BufferIndex updateBufferIndex);
1043 public: // Default properties
1044 // Define a base offset for the following wrappers. The wrapper macros calculate offsets from the previous
1045 // element such that each wrapper type generates a compile time offset to the transform manager data.
1046 BASE(TransformManagerData, mTransformManagerData);
1047 PROPERTY_WRAPPER(mTransformManagerData, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_PARENT_ORIGIN,
1048 mParentOrigin); // Local transform; the position is relative to this. Sets the Transform flag dirty when changed
1050 PROPERTY_WRAPPER(mParentOrigin, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_ANCHOR_POINT,
1051 mAnchorPoint); // Local transform; local center of rotation. Sets the Transform flag dirty when changed
1053 PROPERTY_WRAPPER(mAnchorPoint, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_SIZE,
1054 mSize); // Size is provided for layouting
1056 PROPERTY_WRAPPER(mSize, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_POSITION,
1057 mPosition); // Local transform; distance between parent-origin & anchor-point
1058 PROPERTY_WRAPPER(mPosition, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_SCALE,
1059 mScale); // Local transform; scale relative to parent node
1061 TEMPLATE_WRAPPER(mScale, TransformManagerPropertyQuaternion,
1062 mOrientation); // Local transform; rotation relative to parent node
1064 // Inherited properties; read-only from public API
1065 TEMPLATE_WRAPPER(mOrientation, TransformManagerVector3Input, mWorldPosition); // Full inherited position
1066 TEMPLATE_WRAPPER(mWorldPosition, TransformManagerVector3Input, mWorldScale); // Full inherited scale
1067 TEMPLATE_WRAPPER(mWorldScale, TransformManagerQuaternionInput, mWorldOrientation); // Full inherited orientation
1068 TEMPLATE_WRAPPER(mWorldOrientation, TransformManagerMatrixInput, mWorldMatrix); // Full inherited world matrix
1070 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1071 AnimatableProperty<bool> mCulled; ///< True if the node is culled. This is not animatable. It is just double-buffered.
1072 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1073 InheritedColor mWorldColor; ///< Full inherited color
1074 Vector4 mUpdateAreaHint; ///< Update area hint is provided for damaged area calculation. (x, y, width, height)
1076 uint32_t mClippingSortModifier; ///< Contains bit-packed clipping information for quick access when sorting
1077 const uint32_t mId; ///< The Unique ID of the node.
1080 static uint32_t mNodeCounter; ///< count of total nodes, used for unique ids
1082 PartialRenderingData mPartialRenderingData; ///< Cache to determine if this should be rendered again
1084 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1085 RenderTaskContainer mExclusiveRenderTasks; ///< Nodes can be marked as exclusive to multiple RenderTasks
1087 RendererContainer mRenderers; ///< Container of renderers; not owned
1089 NodeContainer mChildren; ///< Container of children; not owned
1091 uint32_t mClippingDepth; ///< The number of stencil clipping nodes deep this node is
1092 uint32_t mScissorDepth; ///< The number of scissor clipping nodes deep this node is
1093 uint32_t mDepthIndex; ///< Depth index of the node
1095 // flags, compressed to bitfield
1096 NodePropertyFlags mDirtyFlags; ///< Dirty flags for each of the Node properties
1097 DrawMode::Type mDrawMode : 3; ///< How the Node and its children should be drawn
1098 ColorMode mColorMode : 3; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1099 ClippingMode::Type mClippingMode : 3; ///< The clipping mode of this node
1100 bool mIsRoot : 1; ///< True if the node cannot have a parent
1101 bool mIsLayer : 1; ///< True if the node is a layer
1102 bool mIsCamera : 1; ///< True if the node is a camera
1103 bool mPositionUsesAnchorPoint : 1; ///< True if the node should use the anchor-point when calculating the position
1104 bool mTransparent : 1; ///< True if this node is transparent. This value do not affect children.
1105 bool mUpdateAreaChanged : 1; ///< True if the update area of the node is changed.
1106 bool mUseTextureUpdateArea : 1; ///< Whether the actor uses the update area of the texture instead of its own.
1108 // Changes scope, should be at end of class
1109 DALI_LOG_OBJECT_STRING_DECLARATION;
1112 // Messages for Node
1114 inline void SetInheritOrientationMessage(EventThreadServices& eventThreadServices, const Node& node, bool inherit)
1116 using LocalType = MessageValue1<Node, bool>;
1118 // Reserve some memory inside the message queue
1119 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1121 // Construct message in the message queue memory; note that delete should not be called on the return value
1122 new(slot) LocalType(&node, &Node::SetInheritOrientation, inherit);
1125 inline void SetParentOriginMessage(EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin)
1127 using LocalType = MessageValue1<Node, Vector3>;
1129 // Reserve some memory inside the message queue
1130 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1132 // Construct message in the message queue memory; note that delete should not be called on the return value
1133 new(slot) LocalType(&node, &Node::SetParentOrigin, origin);
1136 inline void SetAnchorPointMessage(EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor)
1138 using LocalType = MessageValue1<Node, Vector3>;
1140 // Reserve some memory inside the message queue
1141 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1143 // Construct message in the message queue memory; note that delete should not be called on the return value
1144 new(slot) LocalType(&node, &Node::SetAnchorPoint, anchor);
1147 inline void SetInheritPositionMessage(EventThreadServices& eventThreadServices, const Node& node, bool inherit)
1149 using LocalType = MessageValue1<Node, bool>;
1151 // Reserve some memory inside the message queue
1152 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1154 // Construct message in the message queue memory; note that delete should not be called on the return value
1155 new(slot) LocalType(&node, &Node::SetInheritPosition, inherit);
1158 inline void SetInheritScaleMessage(EventThreadServices& eventThreadServices, const Node& node, bool inherit)
1160 using LocalType = MessageValue1<Node, bool>;
1162 // Reserve some memory inside the message queue
1163 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1165 // Construct message in the message queue memory; note that delete should not be called on the return value
1166 new(slot) LocalType(&node, &Node::SetInheritScale, inherit);
1169 inline void SetColorModeMessage(EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode)
1171 using LocalType = MessageValue1<Node, ColorMode>;
1173 // Reserve some memory inside the message queue
1174 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1176 // Construct message in the message queue memory; note that delete should not be called on the return value
1177 new(slot) LocalType(&node, &Node::SetColorMode, colorMode);
1180 inline void SetDrawModeMessage(EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode)
1182 using LocalType = MessageValue1<Node, DrawMode::Type>;
1184 // Reserve some memory inside the message queue
1185 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1187 // Construct message in the message queue memory; note that delete should not be called on the return value
1188 new(slot) LocalType(&node, &Node::SetDrawMode, drawMode);
1191 inline void SetTransparentMessage(EventThreadServices& eventThreadServices, const Node& node, bool transparent)
1193 using LocalType = MessageValue1<Node, bool>;
1195 // Reserve some memory inside the message queue
1196 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1198 // Construct message in the message queue memory; note that delete should not be called on the return value
1199 new(slot) LocalType(&node, &Node::SetTransparent, transparent);
1202 inline void DetachRendererMessage(EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer)
1204 using LocalType = MessageValue1<Node, RendererKey>;
1206 // Reserve some memory inside the message queue
1207 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1209 // Construct message in the message queue memory; note that delete should not be called on the return value
1210 new(slot) LocalType(&node, &Node::RemoveRenderer, Renderer::GetKey(renderer));
1213 inline void SetDepthIndexMessage(EventThreadServices& eventThreadServices, const Node& node, uint32_t depthIndex)
1215 using LocalType = MessageValue1<Node, uint32_t>;
1217 // Reserve some memory inside the message queue
1218 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1220 // Construct message in the message queue memory; note that delete should not be called on the return value
1221 new(slot) LocalType(&node, &Node::SetDepthIndex, depthIndex);
1224 inline void SetClippingModeMessage(EventThreadServices& eventThreadServices, const Node& node, ClippingMode::Type clippingMode)
1226 using LocalType = MessageValue1<Node, ClippingMode::Type>;
1228 // Reserve some memory inside the message queue
1229 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1231 // Construct message in the message queue memory; note that delete should not be called on the return value
1232 new(slot) LocalType(&node, &Node::SetClippingMode, clippingMode);
1235 inline void SetPositionUsesAnchorPointMessage(EventThreadServices& eventThreadServices, const Node& node, bool positionUsesAnchorPoint)
1237 using LocalType = MessageValue1<Node, bool>;
1239 // Reserve some memory inside the message queue
1240 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1242 // Construct message in the message queue memory; note that delete should not be called on the return value
1243 new(slot) LocalType(&node, &Node::SetPositionUsesAnchorPoint, positionUsesAnchorPoint);
1246 inline void SetUpdateAreaHintMessage(EventThreadServices& eventThreadServices, const Node& node, const Vector4& updateAreaHint)
1248 using LocalType = MessageValue1<Node, Vector4>;
1250 // Reserve some memory inside the message queue
1251 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1253 // Construct message in the message queue memory; note that delete should not be called on the return value
1254 new(slot) LocalType(&node, &Node::SetUpdateAreaHint, updateAreaHint);
1257 inline void UseTextureUpdateAreaMessage(EventThreadServices& eventThreadServices, const Node& node, bool useTextureUpdateArea)
1259 using LocalType = MessageValue1<Node, bool>;
1261 // Reserve some memory inside the message queue
1262 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
1264 // Construct message in the message queue memory; note that delete should not be called on the return value
1265 new(slot) LocalType(&node, &Node::UseTextureUpdateArea, useTextureUpdateArea);
1268 } // namespace SceneGraph
1270 // Template specialisation for OwnerPointer<Node>, because delete is protected
1272 inline void OwnerPointer<Dali::Internal::SceneGraph::Node>::Reset()
1274 if(mObject != nullptr)
1276 Dali::Internal::SceneGraph::Node::Delete(mObject);
1280 } // namespace Internal
1282 // Template specialisations for OwnerContainer<Node*>, because delete is protected
1284 inline void OwnerContainer<Dali::Internal::SceneGraph::Node*>::Delete(Dali::Internal::SceneGraph::Node* pointer)
1286 Dali::Internal::SceneGraph::Node::Delete(pointer);
1290 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H