X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fthread-local-storage.cpp;h=86e848d99dec4cd1631af6782d16ad47486399b8;hb=d67b366a74050ddec47340ff10a0188c0d381561;hp=8ce6c1113c73f68eefc1182e5711427dcec49a09;hpb=bc9255ec35bec7223cd6a18fb2b3a6fcc273936b;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 8ce6c11..86e848d 100644 --- a/dali/internal/event/common/thread-local-storage.cpp +++ b/dali/internal/event/common/thread-local-storage.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -19,36 +19,57 @@ #include // INTERNAL INCLUDES +#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 { -thread_local ThreadLocalStorage* threadLocal = nullptr; -} +thread_local ThreadLocalStorage* threadLocal = nullptr; +thread_local bool isShuttingDown = false; +} // namespace ThreadLocalStorage::ThreadLocalStorage(Core* core) -: mCore( core ) +: mCore(core) { - DALI_ASSERT_ALWAYS( threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object" ); + DALI_ASSERT_ALWAYS(threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object"); - threadLocal = this; + threadLocal = this; + isShuttingDown = false; } -ThreadLocalStorage::~ThreadLocalStorage() -{ -} +ThreadLocalStorage::~ThreadLocalStorage() = default; void ThreadLocalStorage::Remove() { - threadLocal = nullptr; + threadLocal = nullptr; + isShuttingDown = true; } ThreadLocalStorage& ThreadLocalStorage::Get() @@ -58,12 +79,27 @@ ThreadLocalStorage& ThreadLocalStorage::Get() return *threadLocal; } +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 != nullptr); } +bool ThreadLocalStorage::IsShuttingDown() +{ + return isShuttingDown; +} + ThreadLocalStorage* ThreadLocalStorage::GetInternal() { return threadLocal; @@ -124,14 +160,71 @@ AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist() return mCore->GetAnimationPlaylist(); } -void ThreadLocalStorage::AddScene( Scene* scene ) +bool ThreadLocalStorage::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation) +{ + return mCore->GetGlAbstraction().IsBlendEquationSupported(blendEquation); +} + +std::string ThreadLocalStorage::GetShaderVersionPrefix() { - mCore->AddScene( scene ); + return mCore->GetGlAbstraction().GetShaderVersionPrefix(); } -void ThreadLocalStorage::RemoveScene( Scene* scene ) +std::string ThreadLocalStorage::GetVertexShaderPrefix() { - mCore->RemoveScene( scene ); + 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); + } + } +} + +void ThreadLocalStorage::UnregisterAll() +{ + 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