[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / memory-pool-relayout-container.h
index 02eda8f..38e7601 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H__
-#define __DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H__
+#ifndef DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H
+#define DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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 <memory> // for std::unique_ptr
 
 // INTERNAL INCLUDES
-#include <dali/public-api/size-negotiation/relayout-container.h>
-#include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/actors/actor.h>
+#include <dali/public-api/common/dali-vector.h>
+#include <dali/public-api/size-negotiation/relayout-container.h>
 
+#include <dali/integration-api/ordered-set.h>
 #include <dali/internal/common/memory-pool-object-allocator.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 /**
  * @brief Container to encapsulate information required for relayout.
  *
@@ -40,14 +41,37 @@ namespace Internal
 class MemoryPoolRelayoutContainer : public RelayoutContainer
 {
 public:
-
   /**
    * Struct to store the relayout information
    */
   struct RelayoutInfo
   {
-    Dali::Actor actor;            ///< The actor to relayout
-    Vector2 size;           ///< The desired size of the actor
+    Dali::Actor actor; ///< The actor to relayout
+    Vector2     size;  ///< The desired size of the actor
+#if defined(LOW_SPEC_MEMORY_MANAGEMENT_ENABLED)
+    struct RelayoutInfoCompareLess
+    {
+      bool operator()(const RelayoutInfo* lhs, const RelayoutInfo* rhs) const noexcept
+      {
+        return lhs->actor < rhs->actor;
+      }
+    };
+#else
+    struct RelayoutInfoHash
+    {
+      std::size_t operator()(const RelayoutInfo* x) const noexcept
+      {
+        return reinterpret_cast<std::size_t>(x->actor.GetObjectPtr());
+      }
+    };
+    struct RelayoutInfoCompare
+    {
+      bool operator()(const RelayoutInfo* lhs, const RelayoutInfo* rhs) const noexcept
+      {
+        return lhs->actor == rhs->actor;
+      }
+    };
+#endif
   };
 
   /**
@@ -55,12 +79,12 @@ public:
    *
    * @param objectAllocator A memory pool that can allocate memory for RelayoutInfos
    */
-  MemoryPoolRelayoutContainer( MemoryPoolObjectAllocator< RelayoutInfo >& objectAllocator );
+  MemoryPoolRelayoutContainer(MemoryPoolObjectAllocator<RelayoutInfo>& objectAllocator);
 
   /**
    * Virtual destructor
    */
-  virtual ~MemoryPoolRelayoutContainer();
+  ~MemoryPoolRelayoutContainer() override;
 
   /**
    * @brief Add relayout information to the container if it does'nt already exist
@@ -68,7 +92,7 @@ public:
    * @param actor The actor to relayout
    * @param size The size to relayout
    */
-  virtual void Add( const Dali::Actor& actor, const Vector2& size );
+  void Add(const Dali::Actor& actor, const Vector2& size) override;
 
   /**
    * @brief Remove information from the container
@@ -76,11 +100,12 @@ public:
   void PopBack();
 
   /**
-   * @brief Retrieve relayout information for the given index
+   * @brief Retrieve relayout information for the latest added
    *
-   * @param index The index of the information to retrieve
+   * @param[out] actorOut Latest added actor
+   * @param[out] sizeOt Latest added size
    */
-  void Get( size_t index, Dali::Actor& actorOut, Vector2& sizeOut  ) const;
+  void GetBack(Dali::Actor& actorOut, Vector2& sizeOut) const;
 
   /**
    * @brief The count of information in the container
@@ -92,32 +117,38 @@ public:
    *
    * @param capacity The new capacity for the container
    */
-  void Reserve( size_t capacity );
+  void Reserve(size_t capacity);
 
   /**
    * @brief Reset the container, freeing all memory
    */
   void Clear();
 
+private:
   /**
    * @brief Returns if the container contains the actor or not
    *
    * @param actor The actor to search for
    * @return Return if the actor was found or not
    */
-  bool Contains( const Dali::Actor& actor );
+  bool Contains(const Dali::Actor& actor);
 
 private:
+#if defined(LOW_SPEC_MEMORY_MANAGEMENT_ENABLED)
+  using RelayoutInfoContainer = Dali::Integration::OrderedSet<RelayoutInfo, false, RelayoutInfo::RelayoutInfoCompareLess>;
+#else
+  using RelayoutInfoContainer = Dali::Integration::OrderedSet<RelayoutInfo, false, RelayoutInfo::RelayoutInfoHash, RelayoutInfo::RelayoutInfoCompare>;
+#endif
 
-  typedef Vector< RelayoutInfo* > RelayoutInfoContainer;
+  RelayoutInfoContainer mRelayoutInfos; ///< The list of relayout infos
 
-  RelayoutInfoContainer mRelayoutInfos;     ///< The list of relayout infos
+  MemoryPoolObjectAllocator<RelayoutInfo>& mAllocator; ///< The memory pool from which the infos are allocated
 
-  MemoryPoolObjectAllocator< RelayoutInfo >& mAllocator;         ///< The memory pool from which the infos are allocated
+  std::unique_ptr<RelayoutInfo> mDummyRelayoutInfo; ///< Dummy pointer that will be used to compare relayout infors what we already holded.
 };
 
 } // namespace Internal
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H__
+#endif // DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H