1 #ifndef DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
2 #define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
5 * Copyright (c) 2021 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 * Get a pointer to the TLS or NULL if not initialized
94 * @return pointer to the TLS
96 static ThreadLocalStorage* GetInternal();
99 * get platform abstraction
100 * @return reference to core
102 Dali::Integration::PlatformAbstraction& GetPlatformAbstraction();
105 * Retrieve the update manager
106 * @return reference to update manager
108 SceneGraph::UpdateManager& GetUpdateManager();
111 * Returns the Notification Manager
112 * @return reference to the Notification Manager
114 NotificationManager& GetNotificationManager();
117 * Returns the Shader Factory
118 * @return reference to the Shader Factory
120 ShaderFactory& GetShaderFactory();
123 * Returns the current stage.
124 * @return A pointer to the current stage.
126 StagePtr GetCurrentStage();
129 * Returns the gesture event processor.
130 * @return A reference to the gesture event processor.
132 GestureEventProcessor& GetGestureEventProcessor();
135 * Return the relayout controller
136 * @Return Return a reference to the relayout controller
138 RelayoutController& GetRelayoutController();
141 * Returns the Object registry.
142 * @return A reference to the Object registry
144 ObjectRegistry& GetObjectRegistry();
147 * @brief Gets the event thread services.
148 * @return A reference to the event thread services
150 EventThreadServices& GetEventThreadServices();
153 * @brief Gets the property notification manager.
154 * @return A reference to the property notification manager
156 PropertyNotificationManager& GetPropertyNotificationManager();
159 * @brief Gets the animation play list.
160 * @return A reference to the animation play list
162 AnimationPlaylist& GetAnimationPlaylist();
165 * @brief Returns whether the blend equation is supported in the system or not.
166 * @param[in] blendEquation blend equation to be checked.
167 * @return True if the blend equation supported.
169 bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation);
172 * @brief Returns shader prefix of shading language version.
174 std::string GetShaderVersionPrefix();
177 * @brief Returns vertex shader prefix including shading language version.
179 std::string GetVertexShaderPrefix();
182 * @brief Returns fragment shader prefix including shading language version and extension information.
184 std::string GetFragmentShaderPrefix();
187 * Add a Scene to the Core.
188 * This is only used by the Scene to add itself to the core when the Scene is created.
189 * @param[in] scene The Scene.
191 void AddScene(Scene* scene);
194 * Remove a Scene from the Core.
195 * This is only used by the Scene to remove itself from the core when the Scene is destroyed.
196 * @param[in] scene The Scene.
198 void RemoveScene(Scene* scene);
201 * @copydoc Dali::SingletonService::Register()
203 void Register(const std::type_info& info, BaseHandle singleton);
206 * @copydoc Dali::SingletonService::UnregisterAll()
208 void UnregisterAll();
211 * @copydoc Dali::SingletonService::GetSingleton()
213 BaseHandle GetSingleton(const std::type_info& info) const;
219 ~ThreadLocalStorage() override;
222 ThreadLocalStorage(const ThreadLocalStorage&);
223 ThreadLocalStorage& operator=(ThreadLocalStorage&);
226 Core* mCore; ///< reference to core
228 // using the address of the type name string as compiler will allocate these once per library
229 // and we don't support un/re-loading of dali libraries while singleton service is alive
230 using SingletonPair = std::pair<const char*, BaseHandle>;
231 using SingletonContainer = std::vector<SingletonPair>;
232 using SingletonConstIter = SingletonContainer::const_iterator;
234 SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
237 } // namespace Internal
239 // Helpers for public-api forwarding methods
241 inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
243 DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
245 BaseObject& handle = service.GetBaseObject();
247 return static_cast<Internal::ThreadLocalStorage&>(handle);
250 inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
252 DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
254 const BaseObject& handle = service.GetBaseObject();
256 return static_cast<const Internal::ThreadLocalStorage&>(handle);
261 #endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H