2 * Copyright (c) 2023 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");
64 isShuttingDown = false;
67 ThreadLocalStorage::~ThreadLocalStorage() = default;
69 void ThreadLocalStorage::Remove()
71 threadLocal = nullptr;
72 isShuttingDown = true;
75 ThreadLocalStorage& ThreadLocalStorage::Get()
77 DALI_ASSERT_ALWAYS(threadLocal);
82 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
84 Dali::SingletonService singletonService;
87 singletonService = Dali::SingletonService(threadLocal);
89 return singletonService;
92 bool ThreadLocalStorage::Created()
94 // see if the TLS has been set yet
95 return (threadLocal != nullptr);
98 bool ThreadLocalStorage::IsShuttingDown()
100 return isShuttingDown;
103 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
108 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
110 return mCore->GetPlatform();
113 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
115 return mCore->GetUpdateManager();
118 NotificationManager& ThreadLocalStorage::GetNotificationManager()
120 return mCore->GetNotificationManager();
123 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
125 return mCore->GetShaderFactory();
128 StagePtr ThreadLocalStorage::GetCurrentStage()
130 return mCore->GetCurrentStage();
133 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
135 return mCore->GetGestureEventProcessor();
138 RelayoutController& ThreadLocalStorage::GetRelayoutController()
140 return mCore->GetRelayoutController();
143 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
145 return mCore->GetObjectRegistry();
148 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
150 return mCore->GetEventThreadServices();
153 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
155 return mCore->GetPropertyNotificationManager();
158 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
160 return mCore->GetAnimationPlaylist();
163 bool ThreadLocalStorage::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
165 return mCore->GetGlAbstraction().IsBlendEquationSupported(blendEquation);
168 std::string ThreadLocalStorage::GetShaderVersionPrefix()
170 return mCore->GetGlAbstraction().GetShaderVersionPrefix();
173 std::string ThreadLocalStorage::GetVertexShaderPrefix()
175 return mCore->GetGlAbstraction().GetVertexShaderPrefix();
178 std::string ThreadLocalStorage::GetFragmentShaderPrefix()
180 return mCore->GetGlAbstraction().GetFragmentShaderPrefix();
183 void ThreadLocalStorage::AddScene(Scene* scene)
185 mCore->AddScene(scene);
188 void ThreadLocalStorage::RemoveScene(Scene* scene)
190 mCore->RemoveScene(scene);
193 void ThreadLocalStorage::Register(const std::type_info& info, BaseHandle singleton)
197 DALI_LOG_SINGLETON_SERVICE(Debug::General, "Singleton Added: %s\n", info.name());
198 mSingletonContainer.push_back(SingletonPair(info.name(), singleton));
200 Integration::Processor* processor = dynamic_cast<Integration::Processor*>(&singleton.GetBaseObject());
203 mCore->RegisterProcessor(*processor);
208 void ThreadLocalStorage::UnregisterAll()
210 mSingletonContainer.clear();
213 BaseHandle ThreadLocalStorage::GetSingleton(const std::type_info& info) const
217 const SingletonContainer::const_iterator end = mSingletonContainer.end();
218 for(SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter)
220 // comparing the addresses as these are allocated statically per library
221 if((*iter).first == info.name())
223 object = (*iter).second;
230 } // namespace Internal