Merge "Reuse latest pipeline if possible" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.h
index 5b6e635..91ffd97 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__
-#define __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__
+#ifndef DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H
+#define DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
+// EXTERNAL INCLUDES
+#include <cstdint>
+#include <memory> // for unique_ptr
+
 // INTERNAL INCLUDES
+#include <dali/internal/common/memory-pool-object-allocator.h>
+#include <dali/internal/common/ordered-set.h>
+#include <dali/internal/event/size-negotiation/memory-pool-relayout-container.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/base-object.h>
 #include <dali/public-api/size-negotiation/relayout-container.h>
-#include <dali/internal/common/memory-pool-object-allocator.h>
-#include <dali/internal/event/size-negotiation/memory-pool-relayout-container.h>
 
 namespace Dali
 {
-
 namespace Integration
 {
 class RenderController;
@@ -35,7 +39,6 @@ class RenderController;
 
 namespace Internal
 {
-
 /**
  * @brief The relayout controller is responsible for taking request from actors to relayout their sizes.
  * The requests are actioned on at the end of the frame where all actors that have made a request are
@@ -44,18 +47,17 @@ namespace Internal
 class RelayoutController : public Dali::BaseObject
 {
 public:
-
   /**
    * @brief Constructor.
    * We should only create a unique instance.
    * @param[in] controller to request a render from the RenderController if core is not processing events.
    */
-  RelayoutController( Integration::RenderController& controller );
+  RelayoutController(Integration::RenderController& controller);
 
   /**
    * Destructor
    */
-  virtual ~RelayoutController();
+  ~RelayoutController() override;
 
   /**
    * @brief Get the singleton of RelayoutController object.
@@ -74,7 +76,7 @@ public:
    * @param[in] actor The actor to request relayout on
    * @param[in] dimension The dimension(s) to request the relayout on. Defaults to all dimensions
    */
-  void RequestRelayout( Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
+  void RequestRelayout(Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
 
   /**
    * @brief Request to relayout of all actors in the sub-tree below the given actor.
@@ -85,7 +87,7 @@ public:
    *
    * @param[in] actor The actor to request relayout on
    */
-  void RequestRelayoutTree( Dali::Actor& actor );
+  void RequestRelayoutTree(Dali::Actor& actor);
 
   /**
    * @brief Force propagate relayout flags through the tree. This is similiar to Request Relayout
@@ -96,7 +98,7 @@ public:
    * @param[in] actor The actor to propagate from
    * @param[in] dimension The dimension to propagate on
    */
-  void PropagateFlags( Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
+  void PropagateFlags(Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
 
   /**
    * @brief Relayouts all actors that have been marked as dirty
@@ -108,7 +110,7 @@ public:
    *
    * @param[in] enabled Flag to indicate whether the controller should be enabled or disabled
    */
-  void SetEnabled( bool enabled );
+  void SetEnabled(bool enabled);
 
   /**
    * @brief Return true if the relayout controller is currently performing a relayout
@@ -122,10 +124,15 @@ public:
    *
    * @param[in] processingEvents whether core is processing events.
    */
-  void SetProcessingCoreEvents( bool processingEvents );
+  void SetProcessingCoreEvents(bool processingEvents);
 
-public: // CALLBACKS
+  /**
+   * Get the capacity of the memory pool containing relayout info
+   * (It Should be regularly purged!)
+   */
+  uint32_t GetMemoryPoolCapacity();
 
+public: // CALLBACKS
   /**
    * @brief Callback raised after the application creates the scene
    */
@@ -136,11 +143,10 @@ public: // CALLBACKS
    *
    * @param[in] object The object being destroyed
    */
-  void OnObjectDestroyed( const Dali::RefObject* object );
+  void OnObjectDestroyed(const Dali::RefObject* object);
 
 private:
-
-  typedef Dali::Vector< BaseObject* > RawActorList;
+  using RawActorList = Dali::Internal::OrderedSet<Dali::Internal::Actor, false>;
 
   /**
    * @brief Request for relayout. Relays out whole scene.
@@ -152,14 +158,14 @@ private:
    *
    * @param[in] actor The root of the sub tree to add
    */
-  void AddRequest( Dali::Actor& actor );
+  void AddRequest(Dali::Actor& actor);
 
   /**
    * @brief Remove actor from request list
    *
    * @param[in] actor The root of the sub tree to remove
    */
-  void RemoveRequest( Dali::Actor& actor );
+  void RemoveRequest(Dali::Actor& actor);
 
   /**
    * @brief Disconnect the Relayout() method from the Stage::EventProcessingFinishedSignal().
@@ -175,7 +181,7 @@ private:
    * @param[in] topOfSubTreeStack The top of the sub tree that this actor is in
    * @param[in] potentialRedundantSubRoots Actors collected as potentially already being included in relayout
    */
-  void PropagateAll( Dali::Actor& actor, Dimension::Type dimension, std::vector< Dali::Actor >& topOfSubTreeStack, std::vector< Dali::Actor >& potentialRedundantSubRoots );
+  void PropagateAll(Dali::Actor& actor, Dimension::Type dimension, std::vector<Dali::Actor>& topOfSubTreeStack, std::vector<Dali::Actor>& potentialRedundantSubRoots);
 
   /**
    * Queue an actor on the relayout container
@@ -184,39 +190,34 @@ private:
    * @param[in] actors The container to add the actor to
    * @param[in] size The size that this actor should be
    */
-  void QueueActor( Dali::Actor& actor, RelayoutContainer& actors, Vector2 size );
-
-  /**
-   * @brief Find the given object in the list and null it out
-   *
-   * @param[in] list The list to search
-   * @param[in] object The object to search for
-   */
-  void FindAndZero( const RawActorList& list, const Dali::RefObject* object );
+  void QueueActor(Internal::Actor* actor, RelayoutContainer& actors, Vector2 size);
 
   // Undefined
-  RelayoutController(const RelayoutController&);
-  RelayoutController& operator=(const RelayoutController&);
+  RelayoutController(const RelayoutController&) = delete;
+  RelayoutController& operator=(const RelayoutController&) = delete;
 
 private:
+  Integration::RenderController&                                       mRenderController;
+  MemoryPoolObjectAllocator<MemoryPoolRelayoutContainer::RelayoutInfo> mRelayoutInfoAllocator;
+
+  SlotDelegate<RelayoutController> mSlotDelegate;
 
-  Integration::RenderController& mRenderController;
-  MemoryPoolObjectAllocator< MemoryPoolRelayoutContainer::RelayoutInfo > mRelayoutInfoAllocator;
+  RawActorList mDirtyLayoutSubTrees; ///< List of roots of sub trees that are dirty
 
-  SlotDelegate< RelayoutController > mSlotDelegate;
+  std::unique_ptr<MemoryPoolRelayoutContainer> mRelayoutStack; ///< Stack for relayouting
 
-  RawActorList mDirtyLayoutSubTrees;    ///< List of roots of sub trees that are dirty
-  MemoryPoolRelayoutContainer* mRelayoutStack;  ///< Stack for relayouting
-  bool mRelayoutConnection : 1;         ///< Whether EventProcessingFinishedSignal signal is connected.
-  bool mRelayoutFlag : 1;               ///< Relayout flag to avoid unnecessary calls
-  bool mEnabled : 1;                    ///< Initially disabled. Must be enabled at some point.
-  bool mPerformingRelayout : 1;         ///< The relayout controller is currently performing a relayout
-  bool mProcessingCoreEvents : 1;       ///< Whether core is processing events.
+  std::vector<Dali::Actor> mPotentialRedundantSubRoots; ///< Stack of Actor when RequestLayout comes. Keep it as member to avoid vector size reserving.
+  std::vector<Dali::Actor> mTopOfSubTreeStack;
 
+  bool mRelayoutConnection : 1;   ///< Whether EventProcessingFinishedSignal signal is connected.
+  bool mRelayoutFlag : 1;         ///< Relayout flag to avoid unnecessary calls
+  bool mEnabled : 1;              ///< Initially disabled. Must be enabled at some point.
+  bool mPerformingRelayout : 1;   ///< The relayout controller is currently performing a relayout
+  bool mProcessingCoreEvents : 1; ///< Whether core is processing events.
 };
 
 } // namespace Internal
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__
+#endif // DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H