From: David Steele Date: Wed, 20 Oct 2021 16:32:42 +0000 (+0100) Subject: Moved actor recursion methods to actor-parent-impl X-Git-Tag: dali_2.0.49~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-core.git;a=commitdiff_plain;h=743603c4a76d89874f58e7c014b05236b445037a Moved actor recursion methods to actor-parent-impl Change-Id: I01a3153dc8849425f6b8e69f60c224dc36ee7d45 --- diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 99d47f1..1057dea 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -1344,8 +1343,8 @@ void Actor::ConnectToScene(uint32_t parentDepth, bool notify) mScene->RequestRebuildDepthTree(); } - // This stage is atomic i.e. not interrupted by user callbacks. - RecursiveConnectToScene(connectionList, parentDepth + 1); + // This stage is not interrupted by user callbacks. + mParentImpl.RecursiveConnectToScene(connectionList, parentDepth + 1); // Notify applications about the newly connected actors. for(const auto& actor : connectionList) @@ -1356,32 +1355,6 @@ void Actor::ConnectToScene(uint32_t parentDepth, bool notify) RelayoutRequest(); } -void Actor::RecursiveConnectToScene(ActorContainer& connectionList, uint32_t depth) -{ - DALI_ASSERT_ALWAYS(!OnScene()); - - mIsOnScene = true; - mDepth = static_cast(depth); // overflow ignored, not expected in practice - - ConnectToSceneGraph(); - - // Notification for internal derived classes - OnSceneConnectionInternal(); - - // This stage is atomic; avoid emitting callbacks until all Actors are connected - connectionList.push_back(ActorPtr(this)); - - // Recursively connect children - if(GetChildCount() > 0) - { - for(const auto& child : mParentImpl.GetChildrenInternal()) - { - child->SetScene(*mScene); - child->RecursiveConnectToScene(connectionList, depth + 1); - } - } -} - /** * This method is called when the Actor is connected to the Stage. * The parent must have added its Node to the scene-graph. @@ -1439,8 +1412,8 @@ void Actor::DisconnectFromStage(bool notify) mScene->RequestRebuildDepthTree(); } - // This stage is atomic i.e. not interrupted by user callbacks - RecursiveDisconnectFromStage(disconnectionList); + // This stage is not interrupted by user callbacks + mParentImpl.RecursiveDisconnectFromScene(disconnectionList); // Notify applications about the newly disconnected actors. for(const auto& actor : disconnectionList) @@ -1449,29 +1422,6 @@ void Actor::DisconnectFromStage(bool notify) } } -void Actor::RecursiveDisconnectFromStage(ActorContainer& disconnectionList) -{ - // need to change state first so that internals relying on IsOnScene() inside OnSceneDisconnectionInternal() get the correct value - mIsOnScene = false; - - // Recursively disconnect children - if(GetChildCount() > 0) - { - for(const auto& child : mParentImpl.GetChildrenInternal()) - { - child->RecursiveDisconnectFromStage(disconnectionList); - } - } - - // This stage is atomic; avoid emitting callbacks until all Actors are disconnected - disconnectionList.push_back(ActorPtr(this)); - - // Notification for internal derived classes - OnSceneDisconnectionInternal(); - - DisconnectFromSceneGraph(); -} - /** * This method is called by an actor or its parent, before a node removal message is sent. * This is recursive; the child calls DisconnectFromStage() for its children. @@ -1511,17 +1461,7 @@ void Actor::NotifyStageDisconnection(bool notify) bool Actor::IsNodeConnected() const { - bool connected(false); - - if(OnScene()) - { - if(IsRoot() || GetNode().GetParent()) - { - connected = true; - } - } - - return connected; + return OnScene() && (IsRoot() || GetNode().GetParent()); } // This method initiates traversal of the actor tree using depth-first @@ -1539,29 +1479,12 @@ void Actor::RebuildDepthTree() OwnerPointer sceneGraphNodeDepths(new SceneGraph::NodeDepths()); int32_t depthIndex = 1; - DepthTraverseActorTree(sceneGraphNodeDepths, depthIndex); + mParentImpl.DepthTraverseActorTree(sceneGraphNodeDepths, depthIndex); SetDepthIndicesMessage(GetEventThreadServices().GetUpdateManager(), sceneGraphNodeDepths); DALI_LOG_TIMER_END(depthTimer, gLogFilter, Debug::Concise, "Depth tree traversal time: "); } -void Actor::DepthTraverseActorTree(OwnerPointer& sceneGraphNodeDepths, int32_t& depthIndex) -{ - mSortedDepth = depthIndex * DevelLayer::SIBLING_ORDER_MULTIPLIER; - sceneGraphNodeDepths->Add(const_cast(&GetNode()), mSortedDepth); - - // Create/add to children of this node - if(GetChildCount() > 0) - { - for(const auto& child : mParentImpl.GetChildrenInternal()) - { - Actor* childActor = child.Get(); - ++depthIndex; - childActor->DepthTraverseActorTree(sceneGraphNodeDepths, depthIndex); - } - } -} - void Actor::SetDefaultProperty(Property::Index index, const Property::Value& property) { PropertyHandler::SetDefaultProperty(*this, index, property); @@ -1944,36 +1867,14 @@ bool Actor::IsLayoutNegotiated(Dimension::Type dimension) const float Actor::GetHeightForWidthBase(float width) { - float height = 0.0f; - const Vector3 naturalSize = GetNaturalSize(); - if(naturalSize.width > 0.0f) - { - height = naturalSize.height * width / naturalSize.width; - } - else // we treat 0 as 1:1 aspect ratio - { - height = width; - } - - return height; + return naturalSize.width > 0.0f ? naturalSize.height * width / naturalSize.width : width; } float Actor::GetWidthForHeightBase(float height) { - float width = 0.0f; - const Vector3 naturalSize = GetNaturalSize(); - if(naturalSize.height > 0.0f) - { - width = naturalSize.width * height / naturalSize.height; - } - else // we treat 0 as 1:1 aspect ratio - { - width = height; - } - - return width; + return naturalSize.height > 0.0f ? naturalSize.width * height / naturalSize.height : height; } float Actor::CalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension) @@ -2200,12 +2101,7 @@ void Actor::SetPreferredSize(const Vector2& size) Vector2 Actor::GetPreferredSize() const { - if(mRelayoutData) - { - return Vector2(mRelayoutData->preferredSize); - } - - return Relayouter::DEFAULT_PREFERRED_SIZE; + return mRelayoutData ? Vector2(mRelayoutData->preferredSize) : Relayouter::DEFAULT_PREFERRED_SIZE; } void Actor::SetMinimumSize(float size, Dimension::Type dimension) @@ -2216,12 +2112,7 @@ void Actor::SetMinimumSize(float size, Dimension::Type dimension) float Actor::GetMinimumSize(Dimension::Type dimension) const { - if(mRelayoutData) - { - return mRelayoutData->GetMinimumSize(dimension); - } - - return 0.0f; // Default + return mRelayoutData ? mRelayoutData->GetMinimumSize(dimension) : 0.0f; } void Actor::SetMaximumSize(float size, Dimension::Type dimension) @@ -2232,12 +2123,7 @@ void Actor::SetMaximumSize(float size, Dimension::Type dimension) float Actor::GetMaximumSize(Dimension::Type dimension) const { - if(mRelayoutData) - { - return mRelayoutData->GetMaximumSize(dimension); - } - - return FLT_MAX; // Default + return mRelayoutData ? mRelayoutData->GetMaximumSize(dimension) : FLT_MAX; } void Actor::SetVisibleInternal(bool visible, SendMessage::Type sendMessage) @@ -2255,7 +2141,7 @@ void Actor::SetVisibleInternal(bool visible, SendMessage::Type sendMessage) mVisible = visible; // Emit the signal on this actor and all its children - EmitVisibilityChangedSignalRecursively(visible, DevelActor::VisibilityChange::SELF); + mParentImpl.EmitVisibilityChangedSignalRecursively(visible, DevelActor::VisibilityChange::SELF); } } @@ -2307,28 +2193,7 @@ void Actor::SetInheritLayoutDirection(bool inherit) if(inherit && mParent) { - InheritLayoutDirectionRecursively(GetParent()->mLayoutDirection); - } - } -} - -void Actor::InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set) -{ - if(mInheritLayoutDirection || set) - { - if(mLayoutDirection != direction) - { - mLayoutDirection = direction; - EmitLayoutDirectionChangedSignal(direction); - RelayoutRequest(); - } - - if(GetChildCount() > 0) - { - for(const auto& child : mParentImpl.GetChildrenInternal()) - { - child->InheritLayoutDirectionRecursively(direction); - } + mParentImpl.InheritLayoutDirectionRecursively(GetParent()->mLayoutDirection); } } } @@ -2339,20 +2204,6 @@ void Actor::SetUpdateSizeHint(const Vector2& updateSizeHint) SceneGraph::NodePropertyMessage::Send(GetEventThreadServices(), &GetNode(), &GetNode().mUpdateSizeHint, &AnimatableProperty::Bake, Vector3(updateSizeHint.width, updateSizeHint.height, 0.f)); } -void Actor::EmitVisibilityChangedSignalRecursively(bool visible, - DevelActor::VisibilityChange::Type type) -{ - EmitVisibilityChangedSignal(visible, type); - - if(GetChildCount() > 0) - { - for(auto& child : mParentImpl.GetChildrenInternal()) - { - child->EmitVisibilityChangedSignalRecursively(visible, DevelActor::VisibilityChange::PARENT); - } - } -} - } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/actors/actor-impl.h b/dali/internal/event/actors/actor-impl.h index a5ebcc3..c4c300c 100644 --- a/dali/internal/event/actors/actor-impl.h +++ b/dali/internal/event/actors/actor-impl.h @@ -767,11 +767,20 @@ public: * * @return The depth used for hit-testing and renderer sorting */ - uint32_t GetSortingDepth() + inline uint32_t GetSortingDepth() { return mSortedDepth; } + /** + * Set the actor's sorted depth. Used during recreation of depth tree + * @param[in] sortedDepth the new sorted depth + */ + inline void SetSortingDepth(uint32_t sortedDepth) + { + mSortedDepth = sortedDepth; + } + public: // Size negotiation virtual functions @@ -1656,14 +1665,6 @@ protected: void ConnectToScene(uint32_t parentDepth, bool notify); /** - * Helper for ConnectToScene, to recursively connect a tree of actors. - * This is atomic i.e. not interrupted by user callbacks. - * @param[in] depth The depth in the hierarchy of the actor - * @param[out] connectionList On return, the list of connected actors which require notification. - */ - void RecursiveConnectToScene(ActorContainer& connectionList, uint32_t depth); - - /** * Connect the Node associated with this Actor to the scene-graph. */ void ConnectToSceneGraph(); @@ -1681,13 +1682,6 @@ protected: void DisconnectFromStage(bool notify); /** - * Helper for DisconnectFromStage, to recursively disconnect a tree of actors. - * This is atomic i.e. not interrupted by user callbacks. - * @param[out] disconnectionList On return, the list of disconnected actors which require notification. - */ - void RecursiveDisconnectFromStage(ActorContainer& disconnectionList); - - /** * Disconnect the Node associated with this Actor from the scene-graph. */ void DisconnectFromSceneGraph(); @@ -1712,14 +1706,6 @@ public: */ void RebuildDepthTree(); -protected: - /** - * Traverse the actor tree, inserting actors into the depth tree in sibling order. - * @param[in] sceneGraphNodeDepths A vector capturing the nodes and their depth index - * @param[in,out] depthIndex The current depth index (traversal index) - */ - void DepthTraverseActorTree(OwnerPointer& sceneGraphNodeDepths, int32_t& depthIndex); - public: // Default property extensions from Object @@ -2039,26 +2025,11 @@ private: } /** - * @brief Propagates layout direction recursively. - * @param[in] direction New layout direction. - */ - void InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set = false); - - /** * @brief Sets the update size hint of an actor. * @param [in] updateSizeHint The update size hint. */ void SetUpdateSizeHint(const Vector2& updateSizeHint); - /** - * @brief Recursively emits the visibility-changed-signal on the actor tree. - * - * @param[in] visible The new visibility of the actor - * @param[in] type Whether the actor's visible property has changed or a parent's - */ - void EmitVisibilityChangedSignalRecursively(bool visible, - DevelActor::VisibilityChange::Type type); - protected: ActorParentImpl mParentImpl; ///< Implementation of ActorParent; ActorParent* mParent; ///< Each actor (except the root) can have one parent diff --git a/dali/internal/event/actors/actor-parent-impl.cpp b/dali/internal/event/actors/actor-parent-impl.cpp index 41a6e2c..e26f129 100644 --- a/dali/internal/event/actors/actor-parent-impl.cpp +++ b/dali/internal/event/actors/actor-parent-impl.cpp @@ -18,6 +18,7 @@ #include // INTERNAL INCLUDES +#include #include #include #include @@ -100,7 +101,7 @@ void ActorParentImpl::Add(Actor& child, bool notify) EmitChildAddedSignal(child); } - child.InheritLayoutDirectionRecursively(mOwner.GetLayoutDirection()); + child.mParentImpl.InheritLayoutDirectionRecursively(mOwner.GetLayoutDirection()); // Only put in a relayout request if there is a suitable dependency if(mOwner.RelayoutDependentOnChildren()) @@ -414,6 +415,107 @@ void ActorParentImpl::LowerChildBelow(Actor& child, Actor& target) } } +void ActorParentImpl::DepthTraverseActorTree(OwnerPointer& sceneGraphNodeDepths, + int32_t& depthIndex) +{ + uint32_t sortedDepth = depthIndex * DevelLayer::SIBLING_ORDER_MULTIPLIER; + mOwner.SetSortingDepth(sortedDepth); + sceneGraphNodeDepths->Add(const_cast(&mOwner.GetNode()), sortedDepth); + + // Create/add to children of this node + if(mChildren) + { + for(const auto& actor : *mChildren) + { + ++depthIndex; + actor->mParentImpl.DepthTraverseActorTree(sceneGraphNodeDepths, depthIndex); + } + } +} + +void ActorParentImpl::RecursiveConnectToScene(ActorContainer& connectionList, uint32_t depth) +{ + DALI_ASSERT_ALWAYS(!mOwner.OnScene()); + + mOwner.mIsOnScene = true; + mOwner.mDepth = static_cast(depth); // overflow ignored, not expected in practice + mOwner.ConnectToSceneGraph(); + + // Notification for internal derived classes + mOwner.OnSceneConnectionInternal(); + + // This stage is atomic; avoid emitting callbacks until all Actors are connected + connectionList.push_back(ActorPtr(&mOwner)); + + // Recursively connect children + if(mChildren) + { + for(const auto& actor : *mChildren) + { + actor->SetScene(*mOwner.mScene); + actor->mParentImpl.RecursiveConnectToScene(connectionList, depth + 1); + } + } +} + +void ActorParentImpl::RecursiveDisconnectFromScene(ActorContainer& disconnectionList) +{ + // need to change state first so that internals relying on IsOnScene() inside OnSceneDisconnectionInternal() get the correct value + mOwner.mIsOnScene = false; + + // Recursively disconnect children + if(mChildren) + { + for(const auto& actor : *mChildren) + { + actor->mParentImpl.RecursiveDisconnectFromScene(disconnectionList); + } + } + + // This stage is atomic; avoid emitting callbacks until all Actors are disconnected + disconnectionList.push_back(ActorPtr(&mOwner)); + + // Notification for internal derived classes + mOwner.OnSceneDisconnectionInternal(); + mOwner.DisconnectFromSceneGraph(); +} + +void ActorParentImpl::InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set) +{ + if(mOwner.mInheritLayoutDirection || set) + { + if(mOwner.mLayoutDirection != direction) + { + mOwner.mLayoutDirection = direction; + mOwner.EmitLayoutDirectionChangedSignal(direction); + mOwner.RelayoutRequest(); + } + + if(mChildren) + { + for(const auto& child : *mChildren) + { + child->mParentImpl.InheritLayoutDirectionRecursively(direction); + } + } + } +} + +void ActorParentImpl::EmitVisibilityChangedSignalRecursively( + bool visible, + DevelActor::VisibilityChange::Type type) +{ + mOwner.EmitVisibilityChangedSignal(visible, type); + + if(mChildren) + { + for(const auto& child : *mChildren) + { + child->mParentImpl.EmitVisibilityChangedSignalRecursively(visible, DevelActor::VisibilityChange::PARENT); + } + } +} + void ActorParentImpl::EmitChildAddedSignal(Actor& child) { EmitSignal(child, mChildAddedSignal); diff --git a/dali/internal/event/actors/actor-parent-impl.h b/dali/internal/event/actors/actor-parent-impl.h index 98bedb9..5dff226 100644 --- a/dali/internal/event/actors/actor-parent-impl.h +++ b/dali/internal/event/actors/actor-parent-impl.h @@ -19,8 +19,10 @@ // INTERNAL INCLUDES #include #include +#include #include #include +#include // EXTERNAL INCLUDES #include @@ -192,6 +194,43 @@ public: return mChildOrderChangedSignal; } + /** + * Traverse the actor tree, inserting actors into the depth tree in sibling order. + * @param[in] sceneGraphNodeDepths A vector capturing the nodes and their depth index + * @param[in,out] depthIndex The current depth index (traversal index) + */ + void DepthTraverseActorTree(OwnerPointer& sceneGraphNodeDepths, int32_t& depthIndex); + + /** + * Helper to recursively connect a tree of actors. + * This is not interrupted by user callbacks + * @param[in] depth The depth in the hierarchy of the actor + * @param[out] connectionList On return, the list of connected actors which require notification. + */ + void RecursiveConnectToScene(ActorContainer& connectionList, uint32_t depth); + + /** + * Helper to recursively disconnect a tree of actors. + * This is not interrupted by user callbacks. + * @param[out] disconnectionList On return, the list of disconnected actors which require notification. + */ + void RecursiveDisconnectFromScene(ActorContainer& disconnectionList); + + /** + * @brief Propagates layout direction recursively. + * @param[in] direction New layout direction. + */ + void InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set = false); + + /** + * @brief Recursively emits the visibility-changed-signal on the actor tree. + * + * @param[in] visible The new visibility of the actor + * @param[in] type Whether the actor's visible property has changed or a parent's + */ + void EmitVisibilityChangedSignalRecursively(bool visible, + DevelActor::VisibilityChange::Type type); + private: /** * @brief Emits the ChildAdded signal for this actor diff --git a/dali/internal/event/actors/actor-property-handler.cpp b/dali/internal/event/actors/actor-property-handler.cpp index 6d58df5..648b135 100644 --- a/dali/internal/event/actors/actor-property-handler.cpp +++ b/dali/internal/event/actors/actor-property-handler.cpp @@ -536,7 +536,7 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property if(Scripting::GetEnumerationProperty(property, LAYOUT_DIRECTION_TABLE, LAYOUT_DIRECTION_TABLE_COUNT, direction)) { - actor.InheritLayoutDirectionRecursively(direction, true); + actor.mParentImpl.InheritLayoutDirectionRecursively(direction, true); } break; }