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-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
22 #include <dali/integration-api/adaptor-framework/adaptor.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
36 #if defined(DEBUG_ENABLED)
37 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
40 } // unnamed namespace
42 VectorAnimationManager::VectorAnimationManager()
44 mLifecycleObservers(),
45 mVectorAnimationThread(nullptr),
46 mProcessorRegistered(false)
50 VectorAnimationManager::~VectorAnimationManager()
52 for(auto&& iter : mEventCallbacks)
56 mEventCallbacks.clear();
58 if(mProcessorRegistered)
60 Adaptor::Get().UnregisterProcessor(*this, true);
63 for(auto observer : mLifecycleObservers)
65 observer->VectorAnimationManagerDestroyed();
69 void VectorAnimationManager::AddObserver(VectorAnimationManager::LifecycleObserver& observer)
71 DALI_ASSERT_DEBUG(mLifecycleObservers.end() == std::find(mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer));
72 mLifecycleObservers.push_back(&observer);
75 void VectorAnimationManager::RemoveObserver(VectorAnimationManager::LifecycleObserver& observer)
77 auto iterator = std::find(mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer);
78 if(iterator != mLifecycleObservers.end())
80 mLifecycleObservers.erase(iterator);
84 VectorAnimationThread& VectorAnimationManager::GetVectorAnimationThread()
86 if(!mVectorAnimationThread)
88 mVectorAnimationThread = std::unique_ptr<VectorAnimationThread>(new VectorAnimationThread());
89 mVectorAnimationThread->Start();
91 return *mVectorAnimationThread;
94 void VectorAnimationManager::RegisterEventCallback(CallbackBase* callback)
96 mEventCallbacks.push_back(callback);
98 if(!mProcessorRegistered)
100 Adaptor::Get().RegisterProcessor(*this, true); // Use post processor to trigger after layoutting
101 mProcessorRegistered = true;
105 void VectorAnimationManager::UnregisterEventCallback(CallbackBase* callback)
107 auto iter = std::find(mEventCallbacks.begin(), mEventCallbacks.end(), callback);
108 if(iter != mEventCallbacks.end())
110 mEventCallbacks.erase(iter);
112 if(mEventCallbacks.empty())
114 if(Adaptor::IsAvailable())
116 Adaptor::Get().UnregisterProcessor(*this, true);
117 mProcessorRegistered = false;
123 void VectorAnimationManager::Process(bool postProcessor)
125 for(auto&& iter : mEventCallbacks)
127 CallbackBase::Execute(*iter);
130 mEventCallbacks.clear();
132 Adaptor::Get().UnregisterProcessor(*this, true);
133 mProcessorRegistered = false;
136 } // namespace Internal
138 } // namespace Toolkit