1 #ifndef DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
2 #define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
5 * Copyright (c) 2022 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
96 static bool IsSuttingDown();
99 * Get a pointer to the TLS or NULL if not initialized
100 * @return pointer to the TLS
102 static ThreadLocalStorage* GetInternal();
105 * get platform abstraction
106 * @return reference to core
108 Dali::Integration::PlatformAbstraction& GetPlatformAbstraction();
111 * Retrieve the update manager
112 * @return reference to update manager
114 SceneGraph::UpdateManager& GetUpdateManager();
117 * Returns the Notification Manager
118 * @return reference to the Notification Manager
120 NotificationManager& GetNotificationManager();
123 * Returns the Shader Factory
124 * @return reference to the Shader Factory
126 ShaderFactory& GetShaderFactory();
129 * Returns the current stage.
130 * @return A pointer to the current stage.
132 StagePtr GetCurrentStage();
135 * Returns the gesture event processor.
136 * @return A reference to the gesture event processor.
138 GestureEventProcessor& GetGestureEventProcessor();
141 * Return the relayout controller
142 * @Return Return a reference to the relayout controller
144 RelayoutController& GetRelayoutController();
147 * Returns the Object registry.
148 * @return A reference to the Object registry
150 ObjectRegistry& GetObjectRegistry();
153 * @brief Gets the event thread services.
154 * @return A reference to the event thread services
156 EventThreadServices& GetEventThreadServices();
159 * @brief Gets the property notification manager.
160 * @return A reference to the property notification manager
162 PropertyNotificationManager& GetPropertyNotificationManager();
165 * @brief Gets the animation play list.
166 * @return A reference to the animation play list
168 AnimationPlaylist& GetAnimationPlaylist();
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.
175 bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation);
178 * @brief Returns shader prefix of shading language version.
180 std::string GetShaderVersionPrefix();
183 * @brief Returns vertex shader prefix including shading language version.
185 std::string GetVertexShaderPrefix();
188 * @brief Returns fragment shader prefix including shading language version and extension information.
190 std::string GetFragmentShaderPrefix();
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.
197 void AddScene(Scene* scene);
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.
204 void RemoveScene(Scene* scene);
207 * @copydoc Dali::SingletonService::Register()
209 void Register(const std::type_info& info, BaseHandle singleton);
212 * @copydoc Dali::SingletonService::UnregisterAll()
214 void UnregisterAll();
217 * @copydoc Dali::SingletonService::GetSingleton()
219 BaseHandle GetSingleton(const std::type_info& info) const;
225 ~ThreadLocalStorage() override;
228 ThreadLocalStorage(const ThreadLocalStorage&);
229 ThreadLocalStorage& operator=(ThreadLocalStorage&);
232 Core* mCore; ///< reference to core
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;
240 SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
243 } // namespace Internal
245 // Helpers for public-api forwarding methods
247 inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
249 DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
251 BaseObject& handle = service.GetBaseObject();
253 return static_cast<Internal::ThreadLocalStorage&>(handle);
256 inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
258 DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
260 const BaseObject& handle = service.GetBaseObject();
262 return static_cast<const Internal::ThreadLocalStorage&>(handle);
267 #endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H