2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/thread-local-storage.h>
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/processor-interface.h>
24 #include <dali/internal/common/core-impl.h>
25 #include <dali/internal/event/common/event-thread-services.h>
26 #include <dali/public-api/common/dali-common.h>
28 #if defined(DEBUG_ENABLED)
29 #include <dali/integration-api/debug.h>
30 Debug::Filter* gSingletonServiceLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SINGLETON_SERVICE");
32 // Need to define own macro as the log function is not installed when this object is created so no logging is shown with DALI_LOG_INFO at construction and destruction
33 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message) \
34 if(gSingletonServiceLogFilter && gSingletonServiceLogFilter->IsEnabledFor(level)) \
36 std::string string(message); \
37 Dali::TizenPlatform::LogMessage(Debug::INFO, string); \
40 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ##__VA_ARGS__)
43 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message)
44 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...)
54 thread_local ThreadLocalStorage* threadLocal = nullptr;
55 thread_local bool isShuttingDown = false;
58 ThreadLocalStorage::ThreadLocalStorage(Core* core)
61 DALI_ASSERT_ALWAYS(threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object");
66 ThreadLocalStorage::~ThreadLocalStorage() = default;
68 void ThreadLocalStorage::Remove()
70 threadLocal = nullptr;
71 isShuttingDown = true;
74 ThreadLocalStorage& ThreadLocalStorage::Get()
76 DALI_ASSERT_ALWAYS(threadLocal);
81 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
83 Dali::SingletonService singletonService;
86 singletonService = Dali::SingletonService(threadLocal);
88 return singletonService;
91 bool ThreadLocalStorage::Created()
93 // see if the TLS has been set yet
94 return (threadLocal != nullptr);
97 bool ThreadLocalStorage::IsSuttingDown()
99 return isShuttingDown;
102 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
107 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
109 return mCore->GetPlatform();
112 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
114 return mCore->GetUpdateManager();
117 NotificationManager& ThreadLocalStorage::GetNotificationManager()
119 return mCore->GetNotificationManager();
122 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
124 return mCore->GetShaderFactory();
127 StagePtr ThreadLocalStorage::GetCurrentStage()
129 return mCore->GetCurrentStage();
132 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
134 return mCore->GetGestureEventProcessor();
137 RelayoutController& ThreadLocalStorage::GetRelayoutController()
139 return mCore->GetRelayoutController();
142 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
144 return mCore->GetObjectRegistry();
147 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
149 return mCore->GetEventThreadServices();
152 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
154 return mCore->GetPropertyNotificationManager();
157 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
159 return mCore->GetAnimationPlaylist();
162 bool ThreadLocalStorage::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
164 return mCore->GetGlAbstraction().IsBlendEquationSupported(blendEquation);
167 std::string ThreadLocalStorage::GetShaderVersionPrefix()
169 return mCore->GetGlAbstraction().GetShaderVersionPrefix();
172 std::string ThreadLocalStorage::GetVertexShaderPrefix()
174 return mCore->GetGlAbstraction().GetVertexShaderPrefix();
177 std::string ThreadLocalStorage::GetFragmentShaderPrefix()
179 return mCore->GetGlAbstraction().GetFragmentShaderPrefix();
182 void ThreadLocalStorage::AddScene(Scene* scene)
184 mCore->AddScene(scene);
187 void ThreadLocalStorage::RemoveScene(Scene* scene)
189 mCore->RemoveScene(scene);
192 void ThreadLocalStorage::Register(const std::type_info& info, BaseHandle singleton)
196 DALI_LOG_SINGLETON_SERVICE(Debug::General, "Singleton Added: %s\n", info.name());
197 mSingletonContainer.push_back(SingletonPair(info.name(), singleton));
199 Integration::Processor* processor = dynamic_cast<Integration::Processor*>(&singleton.GetBaseObject());
202 mCore->RegisterProcessor(*processor);
207 void ThreadLocalStorage::UnregisterAll()
209 mSingletonContainer.clear();
212 BaseHandle ThreadLocalStorage::GetSingleton(const std::type_info& info) const
216 const SingletonContainer::const_iterator end = mSingletonContainer.end();
217 for(SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter)
219 // comparing the addresses as these are allocated statically per library
220 if((*iter).first == info.name())
222 object = (*iter).second;
229 } // namespace Internal