2 * Copyright (c) 2019 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-rasterize-thread.h>
22 #include <dali/devel-api/adaptor-framework/thread-settings.h>
23 #include <dali/integration-api/adaptors/adaptor.h>
24 #include <dali/integration-api/debug.h>
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
44 } // unnamed namespace
46 VectorRasterizeThread::VectorRasterizeThread()
50 mDestroyThread( false ),
51 mIsThreadStarted( false ),
52 mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
56 VectorRasterizeThread::~VectorRasterizeThread()
60 ConditionalWait::ScopedLock lock( mConditionalWait );
61 mDestroyThread = true;
62 mConditionalWait.Notify( lock );
65 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join [%p]\n", this );
70 void VectorRasterizeThread::SetCompletedCallback( CallbackBase* callback )
72 ConditionalWait::ScopedLock lock( mConditionalWait );
74 mCompletedCallback = std::unique_ptr< CallbackBase >( callback );
77 void VectorRasterizeThread::AddTask( VectorAnimationTaskPtr task )
79 if( !mIsThreadStarted )
82 mIsThreadStarted = true;
85 // Lock while adding task to the queue
86 ConditionalWait::ScopedLock lock( mConditionalWait );
88 if( mRasterizeTasks.end() == std::find( mRasterizeTasks.begin(), mRasterizeTasks.end(), task ) )
90 mRasterizeTasks.push_back( task );
92 // wake up the animation thread
93 mConditionalWait.Notify( lock );
97 void VectorRasterizeThread::Run()
99 SetThreadName( "VectorRasterizeThread" );
100 mLogFactory.InstallLogFunction();
102 while( !mDestroyThread )
108 void VectorRasterizeThread::Rasterize()
110 VectorAnimationTaskPtr nextTask;
112 // Lock while popping task out from the queue
113 ConditionalWait::ScopedLock lock( mConditionalWait );
116 if( mRasterizeTasks.empty() )
118 mConditionalWait.Wait( lock );
121 // pop out the next task from the queue
122 if( !mRasterizeTasks.empty() )
124 std::vector< VectorAnimationTaskPtr >::iterator next = mRasterizeTasks.begin();
126 mRasterizeTasks.erase( next );
132 bool keepAnimation = nextTask->Rasterize();
134 if( mCompletedCallback )
136 CallbackBase::Execute( *mCompletedCallback, nextTask, keepAnimation );
141 } // namespace Internal
143 } // namespace Toolkit