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;
57 ThreadLocalStorage::ThreadLocalStorage(Core* core)
60 DALI_ASSERT_ALWAYS(threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object");
65 ThreadLocalStorage::~ThreadLocalStorage() = default;
67 void ThreadLocalStorage::Remove()
69 threadLocal = nullptr;
72 ThreadLocalStorage& ThreadLocalStorage::Get()
74 DALI_ASSERT_ALWAYS(threadLocal);
79 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
81 Dali::SingletonService singletonService;
84 singletonService = Dali::SingletonService(threadLocal);
86 return singletonService;
89 bool ThreadLocalStorage::Created()
91 // see if the TLS has been set yet
92 return (threadLocal != nullptr);
95 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
100 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
102 return mCore->GetPlatform();
105 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
107 return mCore->GetUpdateManager();
110 NotificationManager& ThreadLocalStorage::GetNotificationManager()
112 return mCore->GetNotificationManager();
115 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
117 return mCore->GetShaderFactory();
120 StagePtr ThreadLocalStorage::GetCurrentStage()
122 return mCore->GetCurrentStage();
125 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
127 return mCore->GetGestureEventProcessor();
130 RelayoutController& ThreadLocalStorage::GetRelayoutController()
132 return mCore->GetRelayoutController();
135 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
137 return mCore->GetObjectRegistry();
140 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
142 return mCore->GetEventThreadServices();
145 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
147 return mCore->GetPropertyNotificationManager();
150 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
152 return mCore->GetAnimationPlaylist();
155 bool ThreadLocalStorage::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
157 return mCore->GetGlAbstraction().IsBlendEquationSupported(blendEquation);
160 std::string ThreadLocalStorage::GetShaderVersionPrefix()
162 return mCore->GetGlAbstraction().GetShaderVersionPrefix();
165 std::string ThreadLocalStorage::GetVertexShaderPrefix()
167 return mCore->GetGlAbstraction().GetVertexShaderPrefix();
170 std::string ThreadLocalStorage::GetFragmentShaderPrefix()
172 return mCore->GetGlAbstraction().GetFragmentShaderPrefix();
175 void ThreadLocalStorage::AddScene(Scene* scene)
177 mCore->AddScene(scene);
180 void ThreadLocalStorage::RemoveScene(Scene* scene)
182 mCore->RemoveScene(scene);
185 void ThreadLocalStorage::Register(const std::type_info& info, BaseHandle singleton)
189 DALI_LOG_SINGLETON_SERVICE(Debug::General, "Singleton Added: %s\n", info.name());
190 mSingletonContainer.push_back(SingletonPair(info.name(), singleton));
192 Integration::Processor* processor = dynamic_cast<Integration::Processor*>(&singleton.GetBaseObject());
195 mCore->RegisterProcessor(*processor);
200 void ThreadLocalStorage::UnregisterAll()
202 mSingletonContainer.clear();
205 BaseHandle ThreadLocalStorage::GetSingleton(const std::type_info& info) const
209 const SingletonContainer::const_iterator end = mSingletonContainer.end();
210 for(SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter)
212 // comparing the addresses as these are allocated statically per library
213 if((*iter).first == info.name())
215 object = (*iter).second;
222 } // namespace Internal