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 mVectorAnimationThread( nullptr ),
49 mProcessorRegistered( false )
53 VectorAnimationManager::~VectorAnimationManager()
55 for( auto&& iter : mEventCallbacks )
59 mEventCallbacks.clear();
61 if( mProcessorRegistered )
63 Adaptor::Get().UnregisterProcessor( *this );
67 VectorAnimationThread& VectorAnimationManager::GetVectorAnimationThread()
69 if( !mVectorAnimationThread )
71 mVectorAnimationThread = std::unique_ptr< VectorAnimationThread >( new VectorAnimationThread() );
72 mVectorAnimationThread->Start();
74 return *mVectorAnimationThread;
77 void VectorAnimationManager::RegisterEventCallback( CallbackBase* callback )
79 mEventCallbacks.push_back( callback );
81 if( !mProcessorRegistered )
83 Adaptor::Get().RegisterProcessor( *this );
84 mProcessorRegistered = true;
88 void VectorAnimationManager::UnregisterEventCallback( CallbackBase* callback )
90 auto iter = std::find( mEventCallbacks.begin(), mEventCallbacks.end(), callback );
91 if( iter != mEventCallbacks.end() )
93 mEventCallbacks.erase( iter );
95 if( mEventCallbacks.empty() )
97 if( Adaptor::IsAvailable() )
99 Adaptor::Get().UnregisterProcessor( *this );
100 mProcessorRegistered = false;
106 void VectorAnimationManager::Process()
108 for( auto&& iter : mEventCallbacks )
110 CallbackBase::Execute( *iter );
113 mEventCallbacks.clear();
115 Adaptor::Get().UnregisterProcessor( *this );
116 mProcessorRegistered = false;
119 } // namespace Internal
121 } // namespace Toolkit