summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
12d8ca9)
Change-Id: I9f68e3ad2d116f2a6d92422c864f72479f7e6b07
#include <iostream>
#include <stdlib.h>
#include <iostream>
#include <stdlib.h>
+#include <chrono>
+#include <thread>
#include <dali-toolkit-test-suite-utils.h>
#include <toolkit-timer.h>
#include <toolkit-event-thread-callback.h>
#include <dali-toolkit-test-suite-utils.h>
#include <toolkit-timer.h>
#include <toolkit-event-thread-callback.h>
application.SendNotification();
application.Render( 16 );
application.SendNotification();
application.Render( 16 );
+ std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); // wait for one animation loop (16fps, 5frames, need 80ms)
+
DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
application.SendNotification();
application.Render(16);
application.SendNotification();
application.Render(16);
+ std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) ); // wait for next rasterize thread run
+
map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
value = map.Find( DevelImageVisual::Property::PLAY_STATE );
DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::PAUSED ) );
map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
value = map.Find( DevelImageVisual::Property::PLAY_STATE );
DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::PAUSED ) );
ToolkitTestApplication application;
tet_infoline( "UtcDaliAnimatedVectorImageVisualJumpToCurrentProgress" );
ToolkitTestApplication application;
tet_infoline( "UtcDaliAnimatedVectorImageVisualJumpToCurrentProgress" );
- Vector2 playRange( 0.2f, 0.8f );
+ Vector2 playRange( 0.2f, 0.5f );
Property::Map propertyMap;
propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
Property::Map propertyMap;
propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
DALI_TEST_EQUALS( value->Get< Vector2 >(), playRange, TEST_LOCATION );
value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
DALI_TEST_EQUALS( value->Get< Vector2 >(), playRange, TEST_LOCATION );
- Vector2 newPlayRange( 0.4f, 1.0f );
+ Vector2 newPlayRange( 0.6f, 1.0f );
Property::Map attributes;
attributes.Add( DevelImageVisual::Property::PLAY_RANGE, newPlayRange );
Property::Map attributes;
attributes.Add( DevelImageVisual::Property::PLAY_RANGE, newPlayRange );
value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
DALI_TEST_EQUALS( value->Get< Vector2 >(), newPlayRange, TEST_LOCATION );
value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
DALI_TEST_EQUALS( value->Get< Vector2 >(), newPlayRange, TEST_LOCATION );
+ attributes.Clear();
+ attributes.Add( DevelImageVisual::Property::PLAY_RANGE, playRange );
+
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
+ DALI_TEST_EQUALS( value->Get< Vector2 >(), playRange, TEST_LOCATION );
+
if( attributes.Get( progress ) )
{
mVectorRasterizeThread.SetCurrentProgress( progress );
if( attributes.Get( progress ) )
{
mVectorRasterizeThread.SetCurrentProgress( progress );
+
+ if( mVectorRasterizeThread.GetPlayState() != DevelImageVisual::PlayState::PLAYING )
+ {
+ mVectorRasterizeThread.RenderFrame();
+ Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger rendering
+ }
Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
#endif
Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
#endif
+inline void ResetToStart( bool& updated, uint32_t& value, uint32_t startValue, ConditionalWait& conditionalWait )
+{
+ ConditionalWait::ScopedLock lock( conditionalWait );
+ if( !updated )
+ {
+ value = startValue;
+ }
+}
+
} // unnamed namespace
VectorRasterizeThread::VectorRasterizeThread( const std::string& url )
: mUrl( url ),
mVectorRenderer(),
mConditionalWait(),
} // unnamed namespace
VectorRasterizeThread::VectorRasterizeThread( const std::string& url )
: mUrl( url ),
mVectorRenderer(),
mConditionalWait(),
mResourceReadyTrigger(),
mAnimationFinishedTrigger(),
mPlayRange( 0.0f, 1.0f ),
mResourceReadyTrigger(),
mAnimationFinishedTrigger(),
mPlayRange( 0.0f, 1.0f ),
mNeedRender( false ),
mDestroyThread( false ),
mResourceReady( false ),
mNeedRender( false ),
mDestroyThread( false ),
mResourceReady( false ),
+ mCurrentFrameUpdated( false ),
mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
{
mVectorRenderer = VectorAnimationRenderer::New( mUrl );
mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
{
mVectorRenderer = VectorAnimationRenderer::New( mUrl );
//TODO: check the return value
StartRender();
//TODO: check the return value
StartRender();
- while( IsThreadReady() )
+ while( !mDestroyThread )
{
mPlayState = DevelImageVisual::PlayState::STOPPED;
{
mPlayState = DevelImageVisual::PlayState::STOPPED;
- // Reset the current frame and the current loop
- mCurrentFrame = mStartFrame;
- mCurrentLoop = 0;
-
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" );
}
}
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" );
}
}
ConditionalWait::ScopedLock lock( mConditionalWait );
mLoopCount = count;
ConditionalWait::ScopedLock lock( mConditionalWait );
mLoopCount = count;
-
- // Reset progress
- mCurrentLoop = 0;
{
mCurrentFrame = mStartFrame;
{
mCurrentFrame = mStartFrame;
+ mCurrentFrameUpdated = true;
mResourceReady = false;
}
else if( mEndFrame < mCurrentFrame )
{
mCurrentFrame = mEndFrame;
mResourceReady = false;
}
else if( mEndFrame < mCurrentFrame )
{
mCurrentFrame = mEndFrame;
+ mCurrentFrameUpdated = true;
mResourceReady = false;
}
}
mResourceReady = false;
}
}
if( mTotalFrame != 0 )
{
mCurrentFrame = static_cast< uint32_t >( mTotalFrame * progress + 0.5f );
if( mTotalFrame != 0 )
{
mCurrentFrame = static_cast< uint32_t >( mTotalFrame * progress + 0.5f );
+ mCurrentFrameUpdated = true;
}
mResourceReady = false;
}
mResourceReady = false;
-bool VectorRasterizeThread::IsThreadReady()
-{
- ConditionalWait::ScopedLock lock( mConditionalWait );
-
- if( mPlayState != DevelImageVisual::PlayState::PLAYING && !mNeedRender && !mDestroyThread )
- {
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::IsThreadReady: Wait\n" );
-
- mConditionalWait.Wait( lock );
- }
-
- // Keep the thread alive if this thread is NOT to be destroyed
- return !mDestroyThread;
-}
-
bool VectorRasterizeThread::StartRender()
{
//TODO: check the return value
bool VectorRasterizeThread::StartRender()
{
//TODO: check the return value
void VectorRasterizeThread::Rasterize()
{
void VectorRasterizeThread::Rasterize()
{
- bool needRender, resourceReady;
+ bool resourceReady;
+ uint32_t currentFrame, startFrame, endFrame;
+ int32_t loopCount;
+ DevelImageVisual::PlayState playState;
{
ConditionalWait::ScopedLock lock( mConditionalWait );
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- needRender = mNeedRender;
+
+ if( mPlayState != DevelImageVisual::PlayState::PLAYING && !mNeedRender && !mDestroyThread )
+ {
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Wait\n" );
+
+ if( mPlayState == DevelImageVisual::PlayState::STOPPED )
+ {
+ // Reset the current frame and the current loop
+ mCurrentFrame = mStartFrame;
+ mCurrentLoop = 0;
+ }
+ mConditionalWait.Wait( lock );
+ }
+
resourceReady = mResourceReady;
resourceReady = mResourceReady;
+ currentFrame = mCurrentFrame++;
+ startFrame = mStartFrame;
+ endFrame = mEndFrame;
+ loopCount = mLoopCount;
+ playState = mPlayState;
+
+ mNeedRender = false;
+ mResourceReady = true;
+ mCurrentFrameUpdated = false;
}
auto currentFrameStartTime = std::chrono::system_clock::now();
// Rasterize
}
auto currentFrameStartTime = std::chrono::system_clock::now();
// Rasterize
- mVectorRenderer.Render( mCurrentFrame );
+ mVectorRenderer.Render( currentFrame );
- if( mPlayState == DevelImageVisual::PlayState::PLAYING )
+ if( playState == DevelImageVisual::PlayState::PLAYING )
- if( ++mCurrentFrame >= mEndFrame )
+ if( currentFrame >= endFrame )
- mCurrentFrame = mStartFrame;
+ ResetToStart( mCurrentFrameUpdated, mCurrentFrame, startFrame, mConditionalWait ); // If the current frame is changed in the event thread, don't overwrite it.
- if( mCurrentLoop >= mLoopCount )
+ if( mCurrentLoop >= loopCount )
- // Animation is finished
mPlayState = DevelImageVisual::PlayState::STOPPED;
mPlayState = DevelImageVisual::PlayState::STOPPED;
- // Reset the current frame and the current loop
- mCurrentFrame = mStartFrame;
- mCurrentLoop = 0;
-
+ // Animation is finished
mAnimationFinishedTrigger->Trigger();
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" );
}
else
{
mAnimationFinishedTrigger->Trigger();
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" );
}
else
{
- mCurrentFrame = mStartFrame;
+ ResetToStart( mCurrentFrameUpdated, mCurrentFrame, startFrame, mConditionalWait );
- if( needRender )
- {
- mNeedRender = false;
- }
-
if( !resourceReady )
{
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Resource ready trigger\n" );
mResourceReadyTrigger->Trigger();
if( !resourceReady )
{
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Resource ready trigger\n" );
mResourceReadyTrigger->Trigger();
}
auto timeToSleepUntil = currentFrameStartTime + std::chrono::nanoseconds( mFrameDurationNanoSeconds );
}
auto timeToSleepUntil = currentFrameStartTime + std::chrono::nanoseconds( mFrameDurationNanoSeconds );
- * @brief Called by the rasterize thread which ensures a wait if required.
- * @return false if the thread should stop.
- */
- bool IsThreadReady();
-
- /**
* @brief Start rendering
*/
bool StartRender();
* @brief Start rendering
*/
bool StartRender();
std::string mUrl;
VectorAnimationRenderer mVectorRenderer;
ConditionalWait mConditionalWait;
std::string mUrl;
VectorAnimationRenderer mVectorRenderer;
ConditionalWait mConditionalWait;
std::unique_ptr< EventThreadCallback > mResourceReadyTrigger;
std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
Vector2 mPlayRange;
std::unique_ptr< EventThreadCallback > mResourceReadyTrigger;
std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
Vector2 mPlayRange;
bool mNeedRender;
bool mDestroyThread; ///< Whether the thread be destroyed
bool mResourceReady;
bool mNeedRender;
bool mDestroyThread; ///< Whether the thread be destroyed
bool mResourceReady;
+ bool mCurrentFrameUpdated;
const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
};
const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
};