Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
#endif
-inline void ResetValue( bool& updated, uint32_t& value, uint32_t newValue, ConditionalWait& conditionalWait )
+template< typename T >
+inline void ResetValue( bool& updated, T& value, T newValue, ConditionalWait& conditionalWait )
{
ConditionalWait::ScopedLock lock( conditionalWait );
if( !updated )
: mUrl( url ),
mVectorRenderer(),
mConditionalWait(),
- mResourceReadyTrigger(),
mAnimationFinishedTrigger(),
mPlayState( PlayState::STOPPED ),
mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ),
mDestroyThread( false ),
mResourceReady( false ),
mCurrentFrameUpdated( false ),
+ mCurrentLoopUpdated( false ),
mForward( true ),
mUpdateFrameNumber( false ),
+ mNeedAnimationFinishedTrigger( true ),
mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
{
Initialize();
ConditionalWait::ScopedLock lock( mConditionalWait );
mDestroyThread = true;
mConditionalWait.Notify( lock );
-
- // This should be called in the main thread to stop waiting for the dequeuable buffer.
- mVectorRenderer.StopRender();
}
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join [%p]\n", this );
Join();
}
Rasterize();
}
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Run: End of thread\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Run: End of thread [%p]\n", this );
}
void VectorRasterizeThread::SetRenderer( Renderer renderer )
mVectorRenderer.SetRenderer( renderer );
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetRenderer\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetRenderer [%p]\n", this );
}
void VectorRasterizeThread::SetSize( uint32_t width, uint32_t height )
mResourceReady = false;
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetSize: width = %d, height = %d\n", width, height );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetSize: width = %d, height = %d [%p]\n", width, height, this );
}
}
mPlayState = PlayState::PLAYING;
mConditionalWait.Notify( lock );
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PlayAnimation: Play\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PlayAnimation: Play [%p]\n", this );
}
}
if( mPlayState != PlayState::STOPPED && mPlayState != PlayState::STOPPING )
{
mNeedRender = true;
+ mNeedAnimationFinishedTrigger = false;
mPlayState = PlayState::STOPPING;
mConditionalWait.Notify( lock );
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop [%p]\n", this );
}
}
{
mPlayState = PlayState::PAUSED;
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause [%p]\n", this );
}
}
mNeedRender = true;
mConditionalWait.Notify( lock );
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::RenderFrame: Render\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::RenderFrame: Render [%p]\n", this );
}
}
-void VectorRasterizeThread::SetResourceReadyCallback( EventThreadCallback* callback )
-{
- ConditionalWait::ScopedLock lock( mConditionalWait );
- mResourceReadyTrigger = std::unique_ptr< EventThreadCallback >( callback );
-}
-
void VectorRasterizeThread::SetAnimationFinishedCallback( EventThreadCallback* callback )
{
ConditionalWait::ScopedLock lock( mConditionalWait );
ConditionalWait::ScopedLock lock( mConditionalWait );
mLoopCount = count;
+ mCurrentLoop = 0;
+ mCurrentLoopUpdated = true;
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetLoopCount: [%d]\n", count );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetLoopCount: [%d] [%p]\n", count, this );
}
}
mResourceReady = false;
}
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetPlayRangeInFrame: [%d, %d]\n", mStartFrame, mEndFrame );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetPlayRange: [%d, %d] [%p]\n", mStartFrame, mEndFrame, this );
}
}
}
{
ConditionalWait::ScopedLock lock( mConditionalWait );
+ if( mCurrentFrame == frameNumber )
+ {
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetCurrentFrameNumber: Set same frame [%d] [%p]\n", frameNumber, this );
+ return;
+ }
+
if( frameNumber >= mStartFrame && frameNumber <= mEndFrame )
{
mCurrentFrame = frameNumber;
mResourceReady = false;
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetCurrentFrameNumber: frame number = %d\n", mCurrentFrame );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetCurrentFrameNumber: frame number = %d [%p]\n", mCurrentFrame, this );
}
else
{
ConditionalWait::ScopedLock lock( mConditionalWait );
mStopBehavior = stopBehavior;
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetStopBehavior: stop behavor = %d\n", mStopBehavior );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetStopBehavior: stop behavor = %d [%p]\n", mStopBehavior, this );
}
void VectorRasterizeThread::SetLoopingMode( DevelImageVisual::LoopingMode::Type loopingMode )
ConditionalWait::ScopedLock lock( mConditionalWait );
mLoopingMode = loopingMode;
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetLoopingMode: looping mode = %d\n", mLoopingMode );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetLoopingMode: looping mode = %d [%p]\n", mLoopingMode, this );
+}
+
+VectorRasterizeThread::UploadCompletedSignalType& VectorRasterizeThread::UploadCompletedSignal()
+{
+ return mVectorRenderer.UploadCompletedSignal();
}
void VectorRasterizeThread::Initialize()
SetSize( width, height );
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Initialize: file = %s [%d frames, %f fps]\n", mUrl.c_str(), mTotalFrame, mFrameRate );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Initialize: file = %s [%d frames, %f fps] [%p]\n", mUrl.c_str(), mTotalFrame, mFrameRate, this );
}
void VectorRasterizeThread::Rasterize()
{
- bool resourceReady, stopped = false;
+ bool stopped = false, needAnimationFinishedTrigger;
uint32_t currentFrame, startFrame, endFrame;
- int32_t loopCount;
+ int32_t loopCount, currentLoopCount;
{
ConditionalWait::ScopedLock lock( mConditionalWait );
if( ( mPlayState == PlayState::PAUSED || mPlayState == PlayState::STOPPED ) && !mNeedRender && !mDestroyThread )
{
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Wait\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Wait [%p]\n", this );
mConditionalWait.Wait( lock );
}
mCurrentFrame = mForward ? mCurrentFrame + 1 : mCurrentFrame - 1;
}
- resourceReady = mResourceReady;
currentFrame = mCurrentFrame;
startFrame = mStartFrame;
endFrame = mEndFrame;
loopCount = mLoopCount;
+ currentLoopCount = mCurrentLoop;
+ needAnimationFinishedTrigger = mNeedAnimationFinishedTrigger;
- mNeedRender = false;
mResourceReady = true;
+ mNeedRender = false;
mCurrentFrameUpdated = false;
+ mCurrentLoopUpdated = false;
mUpdateFrameNumber = true;
+ mNeedAnimationFinishedTrigger = true;
}
auto currentFrameStartTime = std::chrono::system_clock::now();
}
else
{
- if( loopCount < 0 || ++mCurrentLoop < loopCount ) // repeat forever or before the last loop
+ if( loopCount < 0 || ++currentLoopCount < loopCount ) // repeat forever or before the last loop
{
ResetValue( mCurrentFrameUpdated, mCurrentFrame, startFrame, mConditionalWait ); // If the current frame is changed in the event thread, don't overwrite it.
mUpdateFrameNumber = false;
{
animationFinished = true; // end of animation
}
+ ResetValue( mCurrentLoopUpdated, mCurrentLoop, currentLoopCount, mConditionalWait );
}
}
else if( currentFrame == startFrame && !mForward ) // first frame
{
- if( loopCount < 0 || ++mCurrentLoop < loopCount ) // repeat forever or before the last loop
+ if( loopCount < 0 || ++currentLoopCount < loopCount ) // repeat forever or before the last loop
{
mForward = true;
}
{
animationFinished = true; // end of animation
}
+ ResetValue( mCurrentLoopUpdated, mCurrentLoop, currentLoopCount, mConditionalWait );
}
if( animationFinished )
}
// Rasterize
- mVectorRenderer.Render( currentFrame );
-
- if( !resourceReady )
+ if( !mVectorRenderer.Render( currentFrame ) )
{
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Resource ready trigger\n" );
-
- mResourceReadyTrigger->Trigger();
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Rendering failed. Try again later.[%d] [%p]\n", currentFrame, this );
+ mUpdateFrameNumber = false;
}
if( stopped )
mCurrentLoop = 0;
// Animation is finished
- mAnimationFinishedTrigger->Trigger();
+ if( needAnimationFinishedTrigger )
+ {
+ mAnimationFinishedTrigger->Trigger();
+ }
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished [current = %d] [%p]\n", currentFrame, this );
}
auto timeToSleepUntil = currentFrameStartTime + std::chrono::nanoseconds( mFrameDurationNanoSeconds );
#if defined(DEBUG_ENABLED)
auto sleepDuration = std::chrono::duration_cast< std::chrono::milliseconds >( timeToSleepUntil - std::chrono::system_clock::now() );
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: [current = %d, sleep duration = %lld]\n", currentFrame, sleepDuration.count() );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: [current = %d, sleep duration = %lld] [%p]\n", currentFrame, sleepDuration.count(), this );
#endif
std::this_thread::sleep_until( timeToSleepUntil );