Support to get shader language version for shader static API
[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) 2024 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    * @note It returns false if the core hasn't been initialised yet.
96    */
97   static bool IsShuttingDown();
98
99   /**
100    * Get a pointer to the TLS or NULL if not initialized
101    * @return pointer to the TLS
102    */
103   static ThreadLocalStorage* GetInternal();
104
105   /**
106    * get platform abstraction
107    * @return reference to core
108    */
109   Dali::Integration::PlatformAbstraction& GetPlatformAbstraction();
110
111   /**
112    * Retrieve the update manager
113    * @return reference to update manager
114    */
115   SceneGraph::UpdateManager& GetUpdateManager();
116
117   /**
118    * Returns the Notification Manager
119    * @return reference to the Notification Manager
120    */
121   NotificationManager& GetNotificationManager();
122
123   /**
124    * Returns the Shader Factory
125    * @return reference to the Shader Factory
126    */
127   ShaderFactory& GetShaderFactory();
128
129   /**
130    * Returns the current stage.
131    * @return A pointer to the current stage.
132    */
133   StagePtr GetCurrentStage();
134
135   /**
136    * Returns the gesture event processor.
137    * @return A reference to the gesture event processor.
138    */
139   GestureEventProcessor& GetGestureEventProcessor();
140
141   /**
142    * Return the relayout controller
143    * @Return Return a reference to the relayout controller
144    */
145   RelayoutController& GetRelayoutController();
146
147   /**
148    * Returns the Object registry.
149    * @return A reference to the Object registry
150    */
151   ObjectRegistry& GetObjectRegistry();
152
153   /**
154    * @brief Gets the event thread services.
155    * @return A reference to the event thread services
156    */
157   EventThreadServices& GetEventThreadServices();
158
159   /**
160    * @brief Gets the property notification manager.
161    * @return A reference to the property notification manager
162    */
163   PropertyNotificationManager& GetPropertyNotificationManager();
164
165   /**
166    * @brief Gets the animation play list.
167    * @return A reference to the animation play list
168    */
169   AnimationPlaylist& GetAnimationPlaylist();
170
171   /**
172    * @brief Returns whether the blend equation is supported in the system or not.
173    * @param[in] blendEquation blend equation to be checked.
174    * @return True if the blend equation supported.
175    */
176   bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation);
177
178   /**
179    * @brief Returns shading language version.
180    */
181   uint32_t GetShaderLanguageVersion();
182
183   /**
184    * @brief Returns shader prefix of shading language version.
185    */
186   std::string GetShaderVersionPrefix();
187
188   /**
189    * @brief Returns vertex shader prefix including shading language version.
190    */
191   std::string GetVertexShaderPrefix();
192
193   /**
194    * @brief Returns fragment shader prefix including shading language version and extension information.
195    */
196   std::string GetFragmentShaderPrefix();
197
198   /**
199    * Add a Scene to the Core.
200    * This is only used by the Scene to add itself to the core when the Scene is created.
201    * @param[in] scene The Scene.
202    */
203   void AddScene(Scene* scene);
204
205   /**
206    * Remove a Scene from the Core.
207    * This is only used by the Scene to remove itself from the core when the Scene is destroyed.
208    * @param[in] scene The Scene.
209    */
210   void RemoveScene(Scene* scene);
211
212   /**
213    * @copydoc Dali::SingletonService::Register()
214    */
215   void Register(const std::type_info& info, BaseHandle singleton);
216
217   /**
218    * @copydoc Dali::SingletonService::UnregisterAll()
219    */
220   void UnregisterAll();
221
222   /**
223    * @copydoc Dali::SingletonService::GetSingleton()
224    */
225   BaseHandle GetSingleton(const std::type_info& info) const;
226
227 private:
228   /**
229    * Virtual Destructor
230    */
231   ~ThreadLocalStorage() override;
232
233   // Undefined
234   ThreadLocalStorage(const ThreadLocalStorage&);
235   ThreadLocalStorage& operator=(ThreadLocalStorage&);
236
237 private:
238   Core* mCore; ///< reference to core
239
240   // using the address of the type name string as compiler will allocate these once per library
241   // and we don't support un/re-loading of dali libraries while singleton service is alive
242   using SingletonPair      = std::pair<const char*, BaseHandle>;
243   using SingletonContainer = std::vector<SingletonPair>;
244   using SingletonConstIter = SingletonContainer::const_iterator;
245
246   SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
247 };
248
249 } // namespace Internal
250
251 // Helpers for public-api forwarding methods
252
253 inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
254 {
255   DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
256
257   BaseObject& handle = service.GetBaseObject();
258
259   return static_cast<Internal::ThreadLocalStorage&>(handle);
260 }
261
262 inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
263 {
264   DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
265
266   const BaseObject& handle = service.GetBaseObject();
267
268   return static_cast<const Internal::ThreadLocalStorage&>(handle);
269 }
270
271 } // namespace Dali
272
273 #endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H