1 #ifndef DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
2 #define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
5 * Copyright (c) 2023 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 <dali/public-api/common/vector-wrapper.h>
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>
35 class PlatformAbstraction;
41 class NotificationManager;
43 class GestureEventProcessor;
44 class RelayoutController;
46 class EventThreadServices;
47 class PropertyNotificationManager;
48 class AnimationPlaylist;
56 * Class to store a pointer to core in thread local storage.
59 class ThreadLocalStorage : public Dali::BaseObject
64 * Creates the TLS and adds a pointer to core
65 * @param [in] core reference to core
67 ThreadLocalStorage(Core* core);
70 * Remove core pointer.
71 * Prevents the core pointer being automatically deleted when the thread exits.
77 * @return reference to the TLS
79 static ThreadLocalStorage& Get();
82 * @copydoc Dali::SingletonService::Get()
84 static Dali::SingletonService GetSingletonService();
87 * Checks if the TLS has been created
88 * @return if the TLS has been created
90 static bool Created();
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.
97 static bool IsShuttingDown();
100 * Get a pointer to the TLS or NULL if not initialized
101 * @return pointer to the TLS
103 static ThreadLocalStorage* GetInternal();
106 * get platform abstraction
107 * @return reference to core
109 Dali::Integration::PlatformAbstraction& GetPlatformAbstraction();
112 * Retrieve the update manager
113 * @return reference to update manager
115 SceneGraph::UpdateManager& GetUpdateManager();
118 * Returns the Notification Manager
119 * @return reference to the Notification Manager
121 NotificationManager& GetNotificationManager();
124 * Returns the Shader Factory
125 * @return reference to the Shader Factory
127 ShaderFactory& GetShaderFactory();
130 * Returns the current stage.
131 * @return A pointer to the current stage.
133 StagePtr GetCurrentStage();
136 * Returns the gesture event processor.
137 * @return A reference to the gesture event processor.
139 GestureEventProcessor& GetGestureEventProcessor();
142 * Return the relayout controller
143 * @Return Return a reference to the relayout controller
145 RelayoutController& GetRelayoutController();
148 * Returns the Object registry.
149 * @return A reference to the Object registry
151 ObjectRegistry& GetObjectRegistry();
154 * @brief Gets the event thread services.
155 * @return A reference to the event thread services
157 EventThreadServices& GetEventThreadServices();
160 * @brief Gets the property notification manager.
161 * @return A reference to the property notification manager
163 PropertyNotificationManager& GetPropertyNotificationManager();
166 * @brief Gets the animation play list.
167 * @return A reference to the animation play list
169 AnimationPlaylist& GetAnimationPlaylist();
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.
176 bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation);
179 * @brief Returns shader prefix of shading language version.
181 std::string GetShaderVersionPrefix();
184 * @brief Returns vertex shader prefix including shading language version.
186 std::string GetVertexShaderPrefix();
189 * @brief Returns fragment shader prefix including shading language version and extension information.
191 std::string GetFragmentShaderPrefix();
194 * Add a Scene to the Core.
195 * This is only used by the Scene to add itself to the core when the Scene is created.
196 * @param[in] scene The Scene.
198 void AddScene(Scene* scene);
201 * Remove a Scene from the Core.
202 * This is only used by the Scene to remove itself from the core when the Scene is destroyed.
203 * @param[in] scene The Scene.
205 void RemoveScene(Scene* scene);
208 * @copydoc Dali::SingletonService::Register()
210 void Register(const std::type_info& info, BaseHandle singleton);
213 * @copydoc Dali::SingletonService::UnregisterAll()
215 void UnregisterAll();
218 * @copydoc Dali::SingletonService::GetSingleton()
220 BaseHandle GetSingleton(const std::type_info& info) const;
226 ~ThreadLocalStorage() override;
229 ThreadLocalStorage(const ThreadLocalStorage&);
230 ThreadLocalStorage& operator=(ThreadLocalStorage&);
233 Core* mCore; ///< reference to core
235 // using the address of the type name string as compiler will allocate these once per library
236 // and we don't support un/re-loading of dali libraries while singleton service is alive
237 using SingletonPair = std::pair<const char*, BaseHandle>;
238 using SingletonContainer = std::vector<SingletonPair>;
239 using SingletonConstIter = SingletonContainer::const_iterator;
241 SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
244 } // namespace Internal
246 // Helpers for public-api forwarding methods
248 inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
250 DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
252 BaseObject& handle = service.GetBaseObject();
254 return static_cast<Internal::ThreadLocalStorage&>(handle);
257 inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
259 DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
261 const BaseObject& handle = service.GetBaseObject();
263 return static_cast<const Internal::ThreadLocalStorage&>(handle);
268 #endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H