Remove Atlas parameter for TextureManager cache system
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-animation-manager.cpp
1 /*
2  * Copyright (c) 2023 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-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/adaptor-framework/adaptor.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34 namespace
35 {
36 #if defined(DEBUG_ENABLED)
37 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
38 #endif
39
40 } // unnamed namespace
41
42 VectorAnimationManager::VectorAnimationManager()
43 : mEventCallbacks(),
44   mLifecycleObservers(),
45   mVectorAnimationThread(nullptr),
46   mProcessorRegistered(false)
47 {
48 }
49
50 VectorAnimationManager::~VectorAnimationManager()
51 {
52   mEventCallbacks.clear();
53
54   if(mProcessorRegistered)
55   {
56     Adaptor::Get().UnregisterProcessor(*this, true);
57   }
58
59   for(auto observer : mLifecycleObservers)
60   {
61     observer->VectorAnimationManagerDestroyed();
62   }
63 }
64
65 void VectorAnimationManager::AddObserver(VectorAnimationManager::LifecycleObserver& observer)
66 {
67   DALI_ASSERT_DEBUG(mLifecycleObservers.end() == std::find(mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer));
68   mLifecycleObservers.push_back(&observer);
69 }
70
71 void VectorAnimationManager::RemoveObserver(VectorAnimationManager::LifecycleObserver& observer)
72 {
73   auto iterator = std::find(mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer);
74   if(iterator != mLifecycleObservers.end())
75   {
76     mLifecycleObservers.erase(iterator);
77   }
78 }
79
80 VectorAnimationThread& VectorAnimationManager::GetVectorAnimationThread()
81 {
82   if(!mVectorAnimationThread)
83   {
84     mVectorAnimationThread = std::unique_ptr<VectorAnimationThread>(new VectorAnimationThread());
85     mVectorAnimationThread->Start();
86   }
87   return *mVectorAnimationThread;
88 }
89
90 void VectorAnimationManager::RegisterEventCallback(CallbackBase* callback)
91 {
92   mEventCallbacks.emplace_back(std::unique_ptr<Dali::CallbackBase>(callback));
93
94   if(!mProcessorRegistered)
95   {
96     Adaptor::Get().RegisterProcessor(*this, true); // Use post processor to trigger after layoutting
97     mProcessorRegistered = true;
98   }
99 }
100
101 void VectorAnimationManager::UnregisterEventCallback(CallbackBase* callback)
102 {
103   auto iter = std::find_if(mEventCallbacks.begin(),
104                            mEventCallbacks.end(),
105                            [callback](const std::unique_ptr<CallbackBase>& element) {
106                              return element.get() == callback;
107                            });
108   if(iter != mEventCallbacks.end())
109   {
110     mEventCallbacks.erase(iter);
111
112     if(mEventCallbacks.empty())
113     {
114       if(Adaptor::IsAvailable())
115       {
116         Adaptor::Get().UnregisterProcessor(*this, true);
117         mProcessorRegistered = false;
118       }
119     }
120   }
121 }
122
123 void VectorAnimationManager::Process(bool postProcessor)
124 {
125   for(auto&& iter : mEventCallbacks)
126   {
127     CallbackBase::Execute(*iter);
128   }
129   mEventCallbacks.clear();
130
131   Adaptor::Get().UnregisterProcessor(*this, true);
132   mProcessorRegistered = false;
133 }
134
135 } // namespace Internal
136
137 } // namespace Toolkit
138
139 } // namespace Dali