Support to get shader language version for shader static API
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.cpp
1 /*
2  * Copyright (c) 2024 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/processor-interface.h>
23 #include <dali/internal/common/core-impl.h>
24 #include <dali/internal/event/common/event-thread-services.h>
25 #include <dali/public-api/common/dali-common.h>
26
27 #if defined(DEBUG_ENABLED)
28 #include <dali/integration-api/debug.h>
29 Debug::Filter* gSingletonServiceLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SINGLETON_SERVICE");
30
31 // 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
32 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message)                           \
33   if(gSingletonServiceLogFilter && gSingletonServiceLogFilter->IsEnabledFor(level)) \
34   {                                                                                 \
35     std::string string(message);                                                    \
36     Dali::TizenPlatform::LogMessage(Debug::INFO, string);                           \
37   }
38
39 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ##__VA_ARGS__)
40 #else
41
42 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message)
43 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...)
44
45 #endif
46
47 namespace Dali
48 {
49 namespace Internal
50 {
51 namespace
52 {
53 thread_local ThreadLocalStorage* threadLocal    = nullptr;
54 thread_local bool                isShuttingDown = false;
55 } // namespace
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   isShuttingDown = false;
64 }
65
66 ThreadLocalStorage::~ThreadLocalStorage() = default;
67
68 void ThreadLocalStorage::Remove()
69 {
70   threadLocal    = nullptr;
71   isShuttingDown = true;
72 }
73
74 ThreadLocalStorage& ThreadLocalStorage::Get()
75 {
76   DALI_ASSERT_ALWAYS(threadLocal);
77
78   return *threadLocal;
79 }
80
81 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
82 {
83   Dali::SingletonService singletonService;
84   if(threadLocal)
85   {
86     singletonService = Dali::SingletonService(threadLocal);
87   }
88   return singletonService;
89 }
90
91 bool ThreadLocalStorage::Created()
92 {
93   // see if the TLS has been set yet
94   return (threadLocal != nullptr);
95 }
96
97 bool ThreadLocalStorage::IsShuttingDown()
98 {
99   return isShuttingDown;
100 }
101
102 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
103 {
104   return threadLocal;
105 }
106
107 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
108 {
109   return mCore->GetPlatform();
110 }
111
112 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
113 {
114   return mCore->GetUpdateManager();
115 }
116
117 NotificationManager& ThreadLocalStorage::GetNotificationManager()
118 {
119   return mCore->GetNotificationManager();
120 }
121
122 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
123 {
124   return mCore->GetShaderFactory();
125 }
126
127 StagePtr ThreadLocalStorage::GetCurrentStage()
128 {
129   return mCore->GetCurrentStage();
130 }
131
132 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
133 {
134   return mCore->GetGestureEventProcessor();
135 }
136
137 RelayoutController& ThreadLocalStorage::GetRelayoutController()
138 {
139   return mCore->GetRelayoutController();
140 }
141
142 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
143 {
144   return mCore->GetObjectRegistry();
145 }
146
147 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
148 {
149   return mCore->GetEventThreadServices();
150 }
151
152 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
153 {
154   return mCore->GetPropertyNotificationManager();
155 }
156
157 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
158 {
159   return mCore->GetAnimationPlaylist();
160 }
161
162 bool ThreadLocalStorage::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
163 {
164   return mCore->GetGraphicsConfig().IsBlendEquationSupported(blendEquation);
165 }
166
167 uint32_t ThreadLocalStorage::GetShaderLanguageVersion()
168 {
169   return mCore->GetGraphicsConfig().GetShaderLanguageVersion();
170 }
171
172 std::string ThreadLocalStorage::GetShaderVersionPrefix()
173 {
174   return mCore->GetGraphicsConfig().GetShaderVersionPrefix();
175 }
176
177 std::string ThreadLocalStorage::GetVertexShaderPrefix()
178 {
179   return mCore->GetGraphicsConfig().GetVertexShaderPrefix();
180 }
181
182 std::string ThreadLocalStorage::GetFragmentShaderPrefix()
183 {
184   return mCore->GetGraphicsConfig().GetFragmentShaderPrefix();
185 }
186
187 void ThreadLocalStorage::AddScene(Scene* scene)
188 {
189   mCore->AddScene(scene);
190 }
191
192 void ThreadLocalStorage::RemoveScene(Scene* scene)
193 {
194   mCore->RemoveScene(scene);
195 }
196
197 void ThreadLocalStorage::Register(const std::type_info& info, BaseHandle singleton)
198 {
199   if(singleton)
200   {
201     DALI_LOG_SINGLETON_SERVICE(Debug::General, "Singleton Added: %s\n", info.name());
202     mSingletonContainer.push_back(SingletonPair(info.name(), singleton));
203   }
204 }
205
206 void ThreadLocalStorage::UnregisterAll()
207 {
208   mSingletonContainer.clear();
209 }
210
211 BaseHandle ThreadLocalStorage::GetSingleton(const std::type_info& info) const
212 {
213   BaseHandle object;
214
215   const SingletonContainer::const_iterator end = mSingletonContainer.end();
216   for(SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter)
217   {
218     // comparing the addresses as these are allocated statically per library
219     if((*iter).first == info.name())
220     {
221       object = (*iter).second;
222     }
223   }
224
225   return object;
226 }
227
228 } // namespace Internal
229
230 } // namespace Dali