Revert "[Tizen] Relayout only if the actor is on Scene"
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / memory-pool-relayout-container.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // FILE HEADER
19 #include "memory-pool-relayout-container.h"
20
21 namespace Dali
22 {
23 namespace Internal
24 {
25 MemoryPoolRelayoutContainer::MemoryPoolRelayoutContainer(MemoryPoolObjectAllocator<RelayoutInfo>& objectAllocator)
26 : mAllocator(objectAllocator)
27 {
28 }
29
30 MemoryPoolRelayoutContainer::~MemoryPoolRelayoutContainer() = default;
31
32 bool MemoryPoolRelayoutContainer::Contains(const Dali::Actor& actor)
33 {
34   for(RelayoutInfoContainer::Iterator it = mRelayoutInfos.Begin(), itEnd = mRelayoutInfos.End(); it != itEnd; ++it)
35   {
36     RelayoutInfo* info = *it;
37
38     if(info->actor == actor)
39     {
40       return true;
41     }
42   }
43
44   return false;
45 }
46
47 void MemoryPoolRelayoutContainer::Add(const Dali::Actor& actor, const Vector2& size)
48 {
49   if(!Contains(actor))
50   {
51     RelayoutInfo* info = mAllocator.Allocate();
52     info->actor        = actor;
53     info->size         = size;
54
55     mRelayoutInfos.PushBack(info);
56   }
57 }
58
59 void MemoryPoolRelayoutContainer::PopBack()
60 {
61   if(mRelayoutInfos.Size() > 0)
62   {
63     RelayoutInfoContainer::Iterator back = mRelayoutInfos.End();
64     back--;
65     RelayoutInfo* info = *back;
66     mAllocator.Destroy(info);
67     mRelayoutInfos.Erase(back);
68   }
69 }
70
71 void MemoryPoolRelayoutContainer::Get(size_t index, Dali::Actor& actorOut, Vector2& sizeOut) const
72 {
73   DALI_ASSERT_DEBUG(index < Size());
74
75   RelayoutInfo* info = mRelayoutInfos[index];
76   actorOut           = info->actor;
77   sizeOut            = info->size;
78 }
79
80 size_t MemoryPoolRelayoutContainer::Size() const
81 {
82   return mRelayoutInfos.Size();
83 }
84
85 void MemoryPoolRelayoutContainer::Reserve(size_t capacity)
86 {
87   mRelayoutInfos.Reserve(capacity);
88 }
89
90 void MemoryPoolRelayoutContainer::Clear()
91 {
92   for(size_t i = 0; i < Size(); ++i)
93   {
94     RelayoutInfo* info = mRelayoutInfos[i];
95     mAllocator.Destroy(info);
96   }
97
98   mRelayoutInfos.Clear();
99 }
100
101 } // namespace Internal
102
103 } // namespace Dali