[Tizen] Make assertion when SetParent is not called on the main thread
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.h
1 #ifndef DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
2 #define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
3
4 /*
5  * Copyright (c) 2022 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 <dali/public-api/common/vector-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/common/singleton-service.h>
26 #include <dali/internal/event/common/scene-impl.h>
27 #include <dali/internal/event/common/stage-def.h>
28
29 namespace Dali
30 {
31 struct Vector2;
32
33 namespace Integration
34 {
35 class PlatformAbstraction;
36 }
37
38 namespace Internal
39 {
40 class Core;
41 class NotificationManager;
42 class ShaderFactory;
43 class GestureEventProcessor;
44 class RelayoutController;
45 class ObjectRegistry;
46 class EventThreadServices;
47 class PropertyNotificationManager;
48 class AnimationPlaylist;
49
50 namespace SceneGraph
51 {
52 class UpdateManager;
53 }
54
55 /**
56  * Class to store a pointer to core in thread local storage.
57  *
58  */
59 class ThreadLocalStorage : public Dali::BaseObject
60 {
61 public:
62   /**
63    * Constructor
64    * Creates the TLS and adds a pointer to core
65    * @param [in] core reference to core
66    */
67   ThreadLocalStorage(Core* core);
68
69   /**
70    * Remove core pointer.
71    * Prevents the core pointer being automatically deleted when the thread exits.
72    */
73   void Remove();
74
75   /**
76    * Get the TLS
77    * @return reference to the TLS
78    */
79   static ThreadLocalStorage& Get();
80
81   /**
82    * @copydoc Dali::SingletonService::Get()
83    */
84   static Dali::SingletonService GetSingletonService();
85
86   /**
87    * Checks if the TLS has been created
88    * @return if the TLS has been created
89    */
90   static bool Created();
91
92   /**
93    * Checks if the system is shutting down
94    * @return true if the system is shutting down
95    */
96   static bool IsSuttingDown();
97
98   /**
99    * Get a pointer to the TLS or NULL if not initialized
100    * @return pointer to the TLS
101    */
102   static ThreadLocalStorage* GetInternal();
103
104   /**
105    * get platform abstraction
106    * @return reference to core
107    */
108   Dali::Integration::PlatformAbstraction& GetPlatformAbstraction();
109
110   /**
111    * Retrieve the update manager
112    * @return reference to update manager
113    */
114   SceneGraph::UpdateManager& GetUpdateManager();
115
116   /**
117    * Returns the Notification Manager
118    * @return reference to the Notification Manager
119    */
120   NotificationManager& GetNotificationManager();
121
122   /**
123    * Returns the Shader Factory
124    * @return reference to the Shader Factory
125    */
126   ShaderFactory& GetShaderFactory();
127
128   /**
129    * Returns the current stage.
130    * @return A pointer to the current stage.
131    */
132   StagePtr GetCurrentStage();
133
134   /**
135    * Returns the gesture event processor.
136    * @return A reference to the gesture event processor.
137    */
138   GestureEventProcessor& GetGestureEventProcessor();
139
140   /**
141    * Return the relayout controller
142    * @Return Return a reference to the relayout controller
143    */
144   RelayoutController& GetRelayoutController();
145
146   /**
147    * Returns the Object registry.
148    * @return A reference to the Object registry
149    */
150   ObjectRegistry& GetObjectRegistry();
151
152   /**
153    * @brief Gets the event thread services.
154    * @return A reference to the event thread services
155    */
156   EventThreadServices& GetEventThreadServices();
157
158   /**
159    * @brief Gets the property notification manager.
160    * @return A reference to the property notification manager
161    */
162   PropertyNotificationManager& GetPropertyNotificationManager();
163
164   /**
165    * @brief Gets the animation play list.
166    * @return A reference to the animation play list
167    */
168   AnimationPlaylist& GetAnimationPlaylist();
169
170   /**
171    * @brief Returns whether the blend equation is supported in the system or not.
172    * @param[in] blendEquation blend equation to be checked.
173    * @return True if the blend equation supported.
174    */
175   bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation);
176
177   /**
178    * @brief Returns shader prefix of shading language version.
179    */
180   std::string GetShaderVersionPrefix();
181
182   /**
183    * @brief Returns vertex shader prefix including shading language version.
184    */
185   std::string GetVertexShaderPrefix();
186
187   /**
188    * @brief Returns fragment shader prefix including shading language version and extension information.
189    */
190   std::string GetFragmentShaderPrefix();
191
192   /**
193    * Add a Scene to the Core.
194    * This is only used by the Scene to add itself to the core when the Scene is created.
195    * @param[in] scene The Scene.
196    */
197   void AddScene(Scene* scene);
198
199   /**
200    * Remove a Scene from the Core.
201    * This is only used by the Scene to remove itself from the core when the Scene is destroyed.
202    * @param[in] scene The Scene.
203    */
204   void RemoveScene(Scene* scene);
205
206   /**
207    * @copydoc Dali::SingletonService::Register()
208    */
209   void Register(const std::type_info& info, BaseHandle singleton);
210
211   /**
212    * @copydoc Dali::SingletonService::UnregisterAll()
213    */
214   void UnregisterAll();
215
216   /**
217    * @copydoc Dali::SingletonService::GetSingleton()
218    */
219   BaseHandle GetSingleton(const std::type_info& info) const;
220
221 private:
222   /**
223    * Virtual Destructor
224    */
225   ~ThreadLocalStorage() override;
226
227   // Undefined
228   ThreadLocalStorage(const ThreadLocalStorage&);
229   ThreadLocalStorage& operator=(ThreadLocalStorage&);
230
231 private:
232   Core* mCore; ///< reference to core
233
234   // using the address of the type name string as compiler will allocate these once per library
235   // and we don't support un/re-loading of dali libraries while singleton service is alive
236   using SingletonPair      = std::pair<const char*, BaseHandle>;
237   using SingletonContainer = std::vector<SingletonPair>;
238   using SingletonConstIter = SingletonContainer::const_iterator;
239
240   SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
241 };
242
243 } // namespace Internal
244
245 // Helpers for public-api forwarding methods
246
247 inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
248 {
249   DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
250
251   BaseObject& handle = service.GetBaseObject();
252
253   return static_cast<Internal::ThreadLocalStorage&>(handle);
254 }
255
256 inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
257 {
258   DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
259
260   const BaseObject& handle = service.GetBaseObject();
261
262   return static_cast<const Internal::ThreadLocalStorage&>(handle);
263 }
264
265 } // namespace Dali
266
267 #endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H