2 * Copyright (c) 2020 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/debug.h>
23 #include <dali/integration-api/adaptor-framework/adaptor.h>
26 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
44 } // unnamed namespace
46 VectorAnimationManager::VectorAnimationManager()
48 mLifecycleObservers(),
49 mVectorAnimationThread( nullptr ),
50 mProcessorRegistered( false )
54 VectorAnimationManager::~VectorAnimationManager()
56 for( auto&& iter : mEventCallbacks )
60 mEventCallbacks.clear();
62 if( mProcessorRegistered )
64 Adaptor::Get().UnregisterProcessor( *this );
67 for( auto observer : mLifecycleObservers )
69 observer->VectorAnimationManagerDestroyed();
73 void VectorAnimationManager::AddObserver( VectorAnimationManager::LifecycleObserver& observer )
75 DALI_ASSERT_DEBUG( mLifecycleObservers.end() == std::find( mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer));
76 mLifecycleObservers.push_back( &observer );
79 void VectorAnimationManager::RemoveObserver( VectorAnimationManager::LifecycleObserver& observer)
81 auto iterator=std::find(mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer);
82 if( iterator != mLifecycleObservers.end() )
84 mLifecycleObservers.erase(iterator);
88 VectorAnimationThread& VectorAnimationManager::GetVectorAnimationThread()
90 if( !mVectorAnimationThread )
92 mVectorAnimationThread = std::unique_ptr< VectorAnimationThread >( new VectorAnimationThread() );
93 mVectorAnimationThread->Start();
95 return *mVectorAnimationThread;
98 void VectorAnimationManager::RegisterEventCallback( CallbackBase* callback )
100 mEventCallbacks.push_back( callback );
102 if( !mProcessorRegistered )
104 Adaptor::Get().RegisterProcessor( *this );
105 mProcessorRegistered = true;
109 void VectorAnimationManager::UnregisterEventCallback( CallbackBase* callback )
111 auto iter = std::find( mEventCallbacks.begin(), mEventCallbacks.end(), callback );
112 if( iter != mEventCallbacks.end() )
114 mEventCallbacks.erase( iter );
116 if( mEventCallbacks.empty() )
118 if( Adaptor::IsAvailable() )
120 Adaptor::Get().UnregisterProcessor( *this );
121 mProcessorRegistered = false;
127 void VectorAnimationManager::Process()
129 for( auto&& iter : mEventCallbacks )
131 CallbackBase::Execute( *iter );
134 mEventCallbacks.clear();
136 Adaptor::Get().UnregisterProcessor( *this );
137 mProcessorRegistered = false;
140 } // namespace Internal
142 } // namespace Toolkit