1 #ifndef DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H
2 #define DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H
5 * Copyright (c) 2024 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 <memory> // for std::unique_ptr
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/size-negotiation/relayout-container.h>
29 #include <dali/integration-api/ordered-set.h>
30 #include <dali/internal/common/memory-pool-object-allocator.h>
37 * @brief Container to encapsulate information required for relayout.
39 * Uses a memory pool to manage data allocations.
41 class MemoryPoolRelayoutContainer : public RelayoutContainer
45 * Struct to store the relayout information
49 Dali::Actor actor; ///< The actor to relayout
50 Vector2 size; ///< The desired size of the actor
51 #if defined(LOW_SPEC_MEMORY_MANAGEMENT_ENABLED)
52 struct RelayoutInfoCompareLess
54 bool operator()(const RelayoutInfo* lhs, const RelayoutInfo* rhs) const noexcept
56 return lhs->actor < rhs->actor;
60 struct RelayoutInfoHash
62 std::size_t operator()(const RelayoutInfo* x) const noexcept
64 return reinterpret_cast<std::size_t>(x->actor.GetObjectPtr());
67 struct RelayoutInfoCompare
69 bool operator()(const RelayoutInfo* lhs, const RelayoutInfo* rhs) const noexcept
71 return lhs->actor == rhs->actor;
78 * @brief Default constructor
80 * @param objectAllocator A memory pool that can allocate memory for RelayoutInfos
82 MemoryPoolRelayoutContainer(MemoryPoolObjectAllocator<RelayoutInfo>& objectAllocator);
87 ~MemoryPoolRelayoutContainer() override;
90 * @brief Add relayout information to the container if it does'nt already exist
92 * @param actor The actor to relayout
93 * @param size The size to relayout
95 void Add(const Dali::Actor& actor, const Vector2& size) override;
98 * @brief Remove information from the container
103 * @brief Retrieve relayout information for the latest added
105 * @param[out] actorOut Latest added actor
106 * @param[out] sizeOt Latest added size
108 void GetBack(Dali::Actor& actorOut, Vector2& sizeOut) const;
111 * @brief The count of information in the container
116 * @brief Set the capacity of the container
118 * @param capacity The new capacity for the container
120 void Reserve(size_t capacity);
123 * @brief Reset the container, freeing all memory
129 * @brief Returns if the container contains the actor or not
131 * @param actor The actor to search for
132 * @return Return if the actor was found or not
134 bool Contains(const Dali::Actor& actor);
137 #if defined(LOW_SPEC_MEMORY_MANAGEMENT_ENABLED)
138 using RelayoutInfoContainer = Dali::Integration::OrderedSet<RelayoutInfo, false, RelayoutInfo::RelayoutInfoCompareLess>;
140 using RelayoutInfoContainer = Dali::Integration::OrderedSet<RelayoutInfo, false, RelayoutInfo::RelayoutInfoHash, RelayoutInfo::RelayoutInfoCompare>;
143 RelayoutInfoContainer mRelayoutInfos; ///< The list of relayout infos
145 MemoryPoolObjectAllocator<RelayoutInfo>& mAllocator; ///< The memory pool from which the infos are allocated
147 std::unique_ptr<RelayoutInfo> mDummyRelayoutInfo; ///< Dummy pointer that will be used to compare relayout infors what we already holded.
150 } // namespace Internal
154 #endif // DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H