5f7fb1f9620d0da7181c4bfcebdf3f72794c2f0c
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.h
1 #ifndef __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__
2 #define __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/public-api/size-negotiation/relayout-container.h>
28 #include <dali/internal/common/memory-pool-object-allocator.h>
29 #include <dali/internal/event/size-negotiation/memory-pool-relayout-container.h>
30
31 namespace Dali
32 {
33
34 namespace Integration
35 {
36 class RenderController;
37 }
38
39 namespace Internal
40 {
41
42 /**
43  * @brief The relayout controller is responsible for taking request from actors to relayout their sizes.
44  * The requests are actioned on at the end of the frame where all actors that have made a request are
45  * resized.
46  */
47 class RelayoutController : public Dali::BaseObject
48 {
49 public:
50
51   /**
52    * @brief Constructor.
53    * We should only create a unique instance.
54    * @param[in] controller to request a render from the RenderController if core is not processing events.
55    */
56   RelayoutController( Integration::RenderController& controller );
57
58   /**
59    * Destructor
60    */
61   virtual ~RelayoutController();
62
63   /**
64    * @brief Get the singleton of RelayoutController object.
65    *
66    * @return A handle to the RelayoutController control.
67    */
68   static RelayoutController* Get();
69
70   /**
71    * @brief Request to relayout the given actor and all sub-actors of it.
72    *
73    * This flags the actor and all actors dependent on it for relayout. The actual
74    * relayout is performed at the end of the frame. This means that multiple calls to relayout
75    * will not cause multiple relayouts to occur.
76    *
77    * @param[in] actor The actor to request relayout on
78    * @param[in] dimension The dimension(s) to request the relayout on. Defaults to all dimensions
79    */
80   void RequestRelayout( Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
81
82   /**
83    * @brief Request to relayout of all actors in the sub-tree below the given actor.
84    *
85    * This flags the actor and all actors below it for relayout. The actual
86    * relayout is performed at the end of the frame. This means that multiple calls to relayout
87    * will not cause multiple relayouts to occur.
88    *
89    * @param[in] actor The actor to request relayout on
90    */
91   void RequestRelayoutTree( Dali::Actor& actor );
92
93   /**
94    * @brief Force propagate relayout flags through the tree. This is similiar to Request Relayout
95    * except all dependencies have their flags reset in spite of whether they are all ready set.
96    *
97    * This is useful for resetting layout flags during the layout process.
98    *
99    * @param[in] actor The actor to propagate from
100    * @param[in] dimension The dimension to propagate on
101    */
102   void PropagateFlags( Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
103
104   /**
105    * @brief Relayouts all actors that have been marked as dirty
106    */
107   void Relayout();
108
109   /**
110    * @brief Enable/disable the controller
111    *
112    * @param[in] enabled Flag to indicate whether the controller should be enabled or disabled
113    */
114   void SetEnabled( bool enabled );
115
116   /**
117    * @brief Return true if the relayout controller is currently performing a relayout
118    *
119    * @return Return true if the relayout controller is currently performing a relayout
120    */
121   bool IsPerformingRelayout() const;
122
123   /**
124    * @brief Sets whether core is processing events.
125    *
126    * @param[in] processingEvents whether core is processing events.
127    */
128   void SetProcessingCoreEvents( bool processingEvents );
129
130 public: // CALLBACKS
131
132   /**
133    * @brief Callback raised after the application creates the scene
134    */
135   void OnApplicationSceneCreated();
136
137   /**
138    * @brief Callback for when an object is destroyed
139    *
140    * @param[in] object The object being destroyed
141    */
142   void OnObjectDestroyed( const Dali::RefObject* object );
143
144 private:
145
146   using RawActorList = Dali::Vector< Dali::Internal::Actor* >;
147
148   /**
149    * @brief Request for relayout. Relays out whole scene.
150    */
151   void Request();
152
153   /**
154    * @brief Add actor to request list
155    *
156    * @param[in] actor The root of the sub tree to add
157    */
158   void AddRequest( Dali::Actor& actor );
159
160   /**
161    * @brief Remove actor from request list
162    *
163    * @param[in] actor The root of the sub tree to remove
164    */
165   void RemoveRequest( Dali::Actor& actor );
166
167   /**
168    * @brief Disconnect the Relayout() method from the Stage::EventProcessingFinishedSignal().
169    */
170   void Disconnect();
171
172   /**
173    * @brief Propagate dirty layout flags to actor and all sub-actors. This will stop propagating when a dirty actor
174    * is found.
175    *
176    * @param[in] actor The actor to propagate on
177    * @param[in] dimension The dimension to propagate on
178    * @param[in] topOfSubTreeStack The top of the sub tree that this actor is in
179    * @param[in] potentialRedundantSubRoots Actors collected as potentially already being included in relayout
180    */
181   void PropagateAll( Dali::Actor& actor, Dimension::Type dimension, std::vector< Dali::Actor >& topOfSubTreeStack, std::vector< Dali::Actor >& potentialRedundantSubRoots );
182
183   /**
184    * Queue an actor on the relayout container
185    *
186    * @param[in] actor The actor to be queued
187    * @param[in] actors The container to add the actor to
188    * @param[in] size The size that this actor should be
189    */
190   void QueueActor( Internal::Actor* actor, RelayoutContainer& actors, Vector2 size );
191
192   /**
193    * @brief Find the given object in the list and null it out
194    *
195    * @param[in] list The list to search
196    * @param[in] object The object to search for
197    */
198   void FindAndZero( const RawActorList& list, const Dali::RefObject* object );
199
200   // Undefined
201   RelayoutController(const RelayoutController&) = delete;
202   RelayoutController& operator=(const RelayoutController&) = delete;
203
204 private:
205
206   Integration::RenderController& mRenderController;
207   MemoryPoolObjectAllocator< MemoryPoolRelayoutContainer::RelayoutInfo > mRelayoutInfoAllocator;
208
209   SlotDelegate< RelayoutController > mSlotDelegate;
210
211   RawActorList mDirtyLayoutSubTrees;    ///< List of roots of sub trees that are dirty
212   MemoryPoolRelayoutContainer* mRelayoutStack;  ///< Stack for relayouting
213
214   bool mRelayoutConnection : 1;    ///< Whether EventProcessingFinishedSignal signal is connected.
215   bool mRelayoutFlag : 1;          ///< Relayout flag to avoid unnecessary calls
216   bool mEnabled : 1;               ///< Initially disabled. Must be enabled at some point.
217   bool mPerformingRelayout : 1;    ///< The relayout controller is currently performing a relayout
218   bool mProcessingCoreEvents : 1;  ///< Whether core is processing events.
219
220 };
221
222 } // namespace Internal
223
224 } // namespace Dali
225
226 #endif // __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__