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 struct RelayoutInfoHash
53 std::size_t operator()(const RelayoutInfo* x) const noexcept
55 return reinterpret_cast<std::size_t>(x->actor.GetObjectPtr());
58 struct RelayoutInfoCompare
60 bool operator()(const RelayoutInfo* lhs, const RelayoutInfo* rhs) const noexcept
62 return lhs->actor == rhs->actor;
68 * @brief Default constructor
70 * @param objectAllocator A memory pool that can allocate memory for RelayoutInfos
72 MemoryPoolRelayoutContainer(MemoryPoolObjectAllocator<RelayoutInfo>& objectAllocator);
77 ~MemoryPoolRelayoutContainer() override;
80 * @brief Add relayout information to the container if it does'nt already exist
82 * @param actor The actor to relayout
83 * @param size The size to relayout
85 void Add(const Dali::Actor& actor, const Vector2& size) override;
88 * @brief Remove information from the container
93 * @brief Retrieve relayout information for the latest added
95 * @param[out] actorOut Latest added actor
96 * @param[out] sizeOt Latest added size
98 void GetBack(Dali::Actor& actorOut, Vector2& sizeOut) const;
101 * @brief The count of information in the container
106 * @brief Set the capacity of the container
108 * @param capacity The new capacity for the container
110 void Reserve(size_t capacity);
113 * @brief Reset the container, freeing all memory
119 * @brief Returns if the container contains the actor or not
121 * @param actor The actor to search for
122 * @return Return if the actor was found or not
124 bool Contains(const Dali::Actor& actor);
127 using RelayoutInfoContainer = Dali::Integration::OrderedSet<RelayoutInfo, false, RelayoutInfo::RelayoutInfoHash, RelayoutInfo::RelayoutInfoCompare>;
129 RelayoutInfoContainer mRelayoutInfos; ///< The list of relayout infos
131 MemoryPoolObjectAllocator<RelayoutInfo>& mAllocator; ///< The memory pool from which the infos are allocated
133 std::unique_ptr<RelayoutInfo> mDummyRelayoutInfo; ///< Dummy pointer that will be used to compare relayout infors what we already holded.
136 } // namespace Internal
140 #endif // DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H