Change DebugPriority name and Debug priority
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/common/thread-local-storage.h>
20
21 // INTERNAL INCLUDES
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>
27
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");
31
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)) \
35   {                                                                                 \
36     std::string string(message);                                                    \
37     Dali::TizenPlatform::LogMessage(Debug::INFO, string);                           \
38   }
39
40 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ##__VA_ARGS__)
41 #else
42
43 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message)
44 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...)
45
46 #endif
47
48 namespace Dali
49 {
50 namespace Internal
51 {
52 namespace
53 {
54 thread_local ThreadLocalStorage* threadLocal = nullptr;
55 }
56
57 ThreadLocalStorage::ThreadLocalStorage(Core* core)
58 : mCore(core)
59 {
60   DALI_ASSERT_ALWAYS(threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object");
61
62   threadLocal = this;
63 }
64
65 ThreadLocalStorage::~ThreadLocalStorage() = default;
66
67 void ThreadLocalStorage::Remove()
68 {
69   threadLocal = nullptr;
70 }
71
72 ThreadLocalStorage& ThreadLocalStorage::Get()
73 {
74   DALI_ASSERT_ALWAYS(threadLocal);
75
76   return *threadLocal;
77 }
78
79 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
80 {
81   Dali::SingletonService singletonService;
82   if(threadLocal)
83   {
84     singletonService = Dali::SingletonService(threadLocal);
85   }
86   return singletonService;
87 }
88
89 bool ThreadLocalStorage::Created()
90 {
91   // see if the TLS has been set yet
92   return (threadLocal != nullptr);
93 }
94
95 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
96 {
97   return threadLocal;
98 }
99
100 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
101 {
102   return mCore->GetPlatform();
103 }
104
105 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
106 {
107   return mCore->GetUpdateManager();
108 }
109
110 NotificationManager& ThreadLocalStorage::GetNotificationManager()
111 {
112   return mCore->GetNotificationManager();
113 }
114
115 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
116 {
117   return mCore->GetShaderFactory();
118 }
119
120 StagePtr ThreadLocalStorage::GetCurrentStage()
121 {
122   return mCore->GetCurrentStage();
123 }
124
125 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
126 {
127   return mCore->GetGestureEventProcessor();
128 }
129
130 RelayoutController& ThreadLocalStorage::GetRelayoutController()
131 {
132   return mCore->GetRelayoutController();
133 }
134
135 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
136 {
137   return mCore->GetObjectRegistry();
138 }
139
140 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
141 {
142   return mCore->GetEventThreadServices();
143 }
144
145 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
146 {
147   return mCore->GetPropertyNotificationManager();
148 }
149
150 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
151 {
152   return mCore->GetAnimationPlaylist();
153 }
154
155 bool ThreadLocalStorage::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
156 {
157   return mCore->GetGlAbstraction().IsBlendEquationSupported(blendEquation);
158 }
159
160 std::string ThreadLocalStorage::GetShaderVersionPrefix()
161 {
162   return mCore->GetGlAbstraction().GetShaderVersionPrefix();
163 }
164
165 std::string ThreadLocalStorage::GetVertexShaderPrefix()
166 {
167   return mCore->GetGlAbstraction().GetVertexShaderPrefix();
168 }
169
170 std::string ThreadLocalStorage::GetFragmentShaderPrefix()
171 {
172   return mCore->GetGlAbstraction().GetFragmentShaderPrefix();
173 }
174
175 void ThreadLocalStorage::AddScene(Scene* scene)
176 {
177   mCore->AddScene(scene);
178 }
179
180 void ThreadLocalStorage::RemoveScene(Scene* scene)
181 {
182   mCore->RemoveScene(scene);
183 }
184
185 void ThreadLocalStorage::Register(const std::type_info& info, BaseHandle singleton)
186 {
187   if(singleton)
188   {
189     DALI_LOG_SINGLETON_SERVICE(Debug::General, "Singleton Added: %s\n", info.name());
190     mSingletonContainer.push_back(SingletonPair(info.name(), singleton));
191
192     Integration::Processor* processor = dynamic_cast<Integration::Processor*>(&singleton.GetBaseObject());
193     if(processor)
194     {
195       mCore->RegisterProcessor(*processor);
196     }
197   }
198 }
199
200 void ThreadLocalStorage::UnregisterAll()
201 {
202   mSingletonContainer.clear();
203 }
204
205 BaseHandle ThreadLocalStorage::GetSingleton(const std::type_info& info) const
206 {
207   BaseHandle object;
208
209   const SingletonContainer::const_iterator end = mSingletonContainer.end();
210   for(SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter)
211   {
212     // comparing the addresses as these are allocated statically per library
213     if((*iter).first == info.name())
214     {
215       object = (*iter).second;
216     }
217   }
218
219   return object;
220 }
221
222 } // namespace Internal
223
224 } // namespace Dali