X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fthread-local-storage.cpp;h=6ebfc682f1bcf6f0e9a9e1297de43a33be56c704;hb=5de727a5d6b9ef995c93eff4d4e47a086784a332;hp=7885bc90bce2a7143203628c33d9e943e740a7af;hpb=8f2c5571c924479b6a07a2c2187dedd9c685baf0;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/thread-local-storage.cpp b/dali/internal/event/common/thread-local-storage.cpp index 7885bc9..6ebfc68 100644 --- a/dali/internal/event/common/thread-local-storage.cpp +++ b/dali/internal/event/common/thread-local-storage.cpp @@ -1,81 +1,100 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // CLASS HEADER #include -// EXTERNAL INCLUDES -#include -#include - // INTERNAL INCLUDES +#include +#include #include -#include -#include -#include +#include #include -#include + +#if defined(DEBUG_ENABLED) +#include +Debug::Filter* gSingletonServiceLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SINGLETON_SERVICE"); + +// 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 +#define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message) \ + if(gSingletonServiceLogFilter && gSingletonServiceLogFilter->IsEnabledFor(level)) \ + { \ + std::string string(message); \ + Dali::TizenPlatform::LogMessage(Debug::INFO, string); \ + } + +#define DALI_LOG_SINGLETON_SERVICE(level, format, ...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ##__VA_ARGS__) +#else + +#define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message) +#define DALI_LOG_SINGLETON_SERVICE(level, format, ...) + +#endif namespace Dali { - namespace Internal { - namespace { -#ifdef EMSCRIPTEN - std::auto_ptr threadLocal; -#else - boost::thread_specific_ptr threadLocal; -#endif +thread_local ThreadLocalStorage* threadLocal = nullptr; } ThreadLocalStorage::ThreadLocalStorage(Core* core) : mCore(core) { - DALI_ASSERT_ALWAYS( threadLocal.get() == NULL && "Cannot create more than one ThreadLocalStorage object" ); - - // reset is used to store a new value associated with this thread - threadLocal.reset(this); + DALI_ASSERT_ALWAYS(threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object"); + threadLocal = this; } -ThreadLocalStorage::~ThreadLocalStorage() -{ -} +ThreadLocalStorage::~ThreadLocalStorage() = default; void ThreadLocalStorage::Remove() { - threadLocal.reset(); + threadLocal = nullptr; } ThreadLocalStorage& ThreadLocalStorage::Get() { - ThreadLocalStorage* tls = threadLocal.get(); + DALI_ASSERT_ALWAYS(threadLocal); - DALI_ASSERT_ALWAYS(tls); + return *threadLocal; +} - return *tls; +Dali::SingletonService ThreadLocalStorage::GetSingletonService() +{ + Dali::SingletonService singletonService; + if(threadLocal) + { + singletonService = Dali::SingletonService(threadLocal); + } + return singletonService; } bool ThreadLocalStorage::Created() { // see if the TLS has been set yet - return (threadLocal.get() != NULL); + return (threadLocal != nullptr); +} + +ThreadLocalStorage* ThreadLocalStorage::GetInternal() +{ + return threadLocal; } Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction() @@ -93,54 +112,111 @@ NotificationManager& ThreadLocalStorage::GetNotificationManager() return mCore->GetNotificationManager(); } -ResourceManager& ThreadLocalStorage::GetResourceManager() +ShaderFactory& ThreadLocalStorage::GetShaderFactory() { - return mCore->GetResourceManager(); + return mCore->GetShaderFactory(); } -ResourceClient& ThreadLocalStorage::GetResourceClient() +StagePtr ThreadLocalStorage::GetCurrentStage() { - return mCore->GetResourceClient(); + return mCore->GetCurrentStage(); } -ImageFactory& ThreadLocalStorage::GetImageFactory() +GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor() { - return mCore->GetImageFactory(); + return mCore->GetGestureEventProcessor(); } -ModelFactory& ThreadLocalStorage::GetModelFactory() +RelayoutController& ThreadLocalStorage::GetRelayoutController() { - return mCore->GetModelFactory(); + return mCore->GetRelayoutController(); } -FontFactory& ThreadLocalStorage::GetFontFactory() +ObjectRegistry& ThreadLocalStorage::GetObjectRegistry() { - return mCore->GetFontFactory(); + return mCore->GetObjectRegistry(); } -ShaderFactory& ThreadLocalStorage::GetShaderFactory() +EventThreadServices& ThreadLocalStorage::GetEventThreadServices() { - return mCore->GetShaderFactory(); + return mCore->GetEventThreadServices(); } -StagePtr ThreadLocalStorage::GetCurrentStage() +PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager() { - return mCore->GetCurrentStage(); + return mCore->GetPropertyNotificationManager(); } -EventToUpdate& ThreadLocalStorage::GetEventToUpdate() +AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist() { - return GetUpdateManager().GetEventToUpdate(); + return mCore->GetAnimationPlaylist(); } -GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor() +bool ThreadLocalStorage::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation) { - return mCore->GetGestureEventProcessor(); + return mCore->GetGlAbstraction().IsBlendEquationSupported(blendEquation); +} + +std::string ThreadLocalStorage::GetShaderVersionPrefix() +{ + return mCore->GetGlAbstraction().GetShaderVersionPrefix(); +} + +std::string ThreadLocalStorage::GetVertexShaderPrefix() +{ + return mCore->GetGlAbstraction().GetVertexShaderPrefix(); +} + +std::string ThreadLocalStorage::GetFragmentShaderPrefix() +{ + return mCore->GetGlAbstraction().GetFragmentShaderPrefix(); +} + +void ThreadLocalStorage::AddScene(Scene* scene) +{ + mCore->AddScene(scene); +} + +void ThreadLocalStorage::RemoveScene(Scene* scene) +{ + mCore->RemoveScene(scene); +} + +void ThreadLocalStorage::Register(const std::type_info& info, BaseHandle singleton) +{ + if(singleton) + { + DALI_LOG_SINGLETON_SERVICE(Debug::General, "Singleton Added: %s\n", info.name()); + mSingletonContainer.push_back(SingletonPair(info.name(), singleton)); + + Integration::Processor* processor = dynamic_cast(&singleton.GetBaseObject()); + if(processor) + { + mCore->RegisterProcessor(*processor); + } + } } -EmojiFactory& ThreadLocalStorage::GetEmojiFactory() +void ThreadLocalStorage::UnregisterAll() { - return mCore->GetEmojiFactory(); + mSingletonContainer.clear(); +} + +BaseHandle ThreadLocalStorage::GetSingleton(const std::type_info& info) const +{ + BaseHandle object; + + const SingletonContainer::const_iterator end = mSingletonContainer.end(); + for(SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter) + { + // comparing the addresses as these are allocated statically per library + if((*iter).first == info.name()) + { + object = (*iter).second; + } + } + + return object; } } // namespace Internal