ToolkitTestApplication application;
tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map" );
+ int startFrame = 1, endFrame = 3;
+ Property::Array playRange;
+ playRange.PushBack( startFrame );
+ playRange.PushBack( endFrame );
+
Property::Map propertyMap;
propertyMap.Add( "visualType", DevelVisual::ANIMATED_VECTOR_IMAGE )
- .Add( "url", TEST_VECTOR_IMAGE_FILE_NAME )
- .Add( "loopCount", 3 )
- .Add( "playRange", Vector2( 0.2f, 0.8f ) );
+ .Add( "url", TEST_VECTOR_IMAGE_FILE_NAME )
+ .Add( "loopCount", 3 )
+ .Add( "playRange", playRange )
+ .Add( "stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME )
+ .Add( "loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE );
Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
DALI_TEST_CHECK( visual );
Renderer renderer = actor.GetRendererAt( 0u );
DALI_TEST_CHECK( renderer );
+ Property::Map resultMap;
+ visual.CreatePropertyMap( resultMap );
+
+ // check the property values from the returned map from a visual
+ Property::Value* value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get< std::string >() == TEST_VECTOR_IMAGE_FILE_NAME );
+
+ value = resultMap.Find( DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get< int >() == 3 );
+
+ value = resultMap.Find( DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY );
+ DALI_TEST_CHECK( value );
+
+ Property::Array* result = value->GetArray();
+ DALI_TEST_CHECK( result );
+
+ DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame );
+ DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame );
+
+ value = resultMap.Find( DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::StopBehavior::FIRST_FRAME );
+
+ value = resultMap.Find( DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::LoopingMode::AUTO_REVERSE );
+
actor.Unparent( );
DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
Property::Map propertyMap;
propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
- .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
- .Add( DevelImageVisual::Property::LOOP_COUNT, 3 )
- .Add( DevelImageVisual::Property::PLAY_RANGE, playRange );
+ .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, 3 )
+ .Add( DevelImageVisual::Property::PLAY_RANGE, playRange );
// request AnimatedVectorImageVisual with a property map
VisualFactory factory = VisualFactory::Get();
DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame );
DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame );
+ value = resultMap.Find( DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::StopBehavior::CURRENT_FRAME );
+
+ value = resultMap.Find( DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::LoopingMode::RESTART );
+
// request AnimatedVectorImageVisual with an URL
Visual::Base visual2 = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() );
Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
- DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::PLAYING ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
tet_infoline( "Test Pause action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes );
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 ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED );
tet_infoline( "Test Play action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
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::PLAYING ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
tet_infoline( "Test Stop action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
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::STOPPED ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
tet_infoline( "Test Stop action again" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
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::STOPPED ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
tet_infoline( "Test Play action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
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::PLAYING ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
tet_infoline( "Off stage" );
dummyControl.Unparent();
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 ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED );
tet_infoline( "On stage again" );
Stage::GetCurrent().Add( dummyControl );
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 ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED );
tet_infoline( "Test Play action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
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::PLAYING ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
// Change Size
Vector3 newSize( 100.0f, 100.0f, 0.0f );
Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
- DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::STOPPED ) );
+ DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
DALI_TEST_EQUALS( gAnimationFinishedSignalFired, true, TEST_LOCATION );
END_TEST;
}
+
+int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliAnimatedVectorImageVisualStopBehavior" );
+
+ Property::Map propertyMap;
+ propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, 3 )
+ .Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME );
+
+ Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+ DALI_TEST_CHECK( visual );
+
+ DummyControl actor = DummyControl::New( true );
+ DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+
+ Vector2 controlSize( 20.f, 30.f );
+ actor.SetSize( controlSize );
+
+ Stage::GetCurrent().Add( actor );
+
+ Property::Map attributes;
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // Trigger count is 2 - resource ready and animation finished
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
+
+ Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
+ DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION ); // Should be the first frame
+
+ // Change stop behavior
+ attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME );
+
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+ attributes.Clear();
+
+ // Play again
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // Trigger count is 1 - animation finished
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+
+ Property::Value* value1 = map.Find( DevelImageVisual::Property::TOTAL_FRAME_NUMBER );
+ int totalFrameNumber = value1->Get< int >();
+
+ value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
+ DALI_TEST_EQUALS( value->Get< int >(), totalFrameNumber - 1, TEST_LOCATION ); // Should be the last frame
+
+ // Change stop behavior
+ attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME );
+ attributes.Add( DevelImageVisual::Property::LOOP_COUNT, -1 );
+
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+ attributes.Clear();
+
+ // Play again
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // Pause
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes );
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
+ int currentFrameNumber = value->Get< int >();
+
+ // Stop
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
+
+ // Trigger count is 1 - animation finished
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
+ DALI_TEST_EQUALS( value->Get< int >(), currentFrameNumber, TEST_LOCATION ); // Should be same with currentFrameNumber
+
+ END_TEST;
+}
+
+int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliAnimatedVectorImageVisualLoopingMode" );
+
+ Property::Map propertyMap;
+ propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, 3 )
+ .Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME )
+ .Add( DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE );
+
+ Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+ DALI_TEST_CHECK( visual );
+
+ DummyControl actor = DummyControl::New( true );
+ DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+
+ Vector2 controlSize( 20.f, 30.f );
+ actor.SetSize( controlSize );
+
+ Stage::GetCurrent().Add( actor );
+
+ Property::Map attributes;
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // Trigger count is 2 - resource ready and animation finished
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
+
+ Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
+ DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION ); // Should be the first frame because of auto reverse
+
+ // Change stop behavior
+ attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME );
+
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+ // Play again
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // Trigger count is 1 - animation finished
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
+ DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION ); // Should be the first frame
+
+ // Change looping mode
+ attributes.Add( DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART );
+
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+ // Play again
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // Trigger count is 1 - animation finished
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ Property::Value* value1 = map.Find( DevelImageVisual::Property::TOTAL_FRAME_NUMBER );
+ int totalFrameNumber = value1->Get< int >();
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
+ DALI_TEST_EQUALS( value->Get< int >(), totalFrameNumber - 1, TEST_LOCATION ); // Should be the last frame
+
+ END_TEST;
+}
#define DALI_TOOLKIT_DEVEL_API_VISUALS_IMAGE_VISUAL_PROPERTIES_DEVEL_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
ORIENTATION_CORRECTION = Dali::Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION,
/**
- * @brief Overlays the auxiliary iamge on top of an NPatch image.
+ * @brief Overlays the auxiliary image on top of an NPatch image.
*
* The resulting visual image will be at least as large as the
* smallest possible n-patch or the auxiliary image, whichever is
/**
* @brief The playing state the AnimatedVectorImageVisual will use.
- * @details Name "playState", type PlayState (Property::INTEGER)
+ * @details Name "playState", Type PlayState::Type (Property::INTEGER)
* @note This property is read-only.
*/
PLAY_STATE = ORIENTATION_CORRECTION + 5,
* @details Name "totalFrameNumber", Type Property::INTEGER.
* @note This property is read-only.
*/
- TOTAL_FRAME_NUMBER = ORIENTATION_CORRECTION + 7
+ TOTAL_FRAME_NUMBER = ORIENTATION_CORRECTION + 7,
+
+ /**
+ * @brief The stop behavior the AnimatedVectorImageVisual will use.
+ * @details Name "stopBehavior", Type StopBehavior::Type (Property::INTEGER)
+ * @note Default value is StopBehavior::CURRENT_FRAME.
+ */
+ STOP_BEHAVIOR = ORIENTATION_CORRECTION + 8,
+
+ /**
+ * @brief The looping mode the AnimatedVectorImageVisual will use.
+ * @details Name "loopingMode", Type LoopingMode::Type (Property::INTEGER)
+ * @note Default value is LoopingMode::RESTART.
+ */
+ LOOPING_MODE = ORIENTATION_CORRECTION + 9
};
} //namespace Property
/**
* @brief Enumeration for what state the animation is in.
*/
-enum class PlayState
+namespace PlayState
+{
+
+enum Type
{
STOPPED, ///< Animation has stopped
PLAYING, ///< The animation is playing
PAUSED ///< The animation is paused
};
+} // namespace PlayState
+
+/**
+ * @brief Enumeration for what to do when the animation is stopped.
+ */
+namespace StopBehavior
+{
+
+enum Type
+{
+ CURRENT_FRAME, ///< When the animation is stopped, the current frame is shown.
+ FIRST_FRAME, ///< When the animation is stopped, the first frame is shown.
+ LAST_FRAME ///< When the animation is stopped, the last frame is shown.
+};
+
+} // namespace StopBehavoir
+
+/**
+ * @brief Enumeration for what looping mode is in.
+ */
+namespace LoopingMode
+{
+
+enum Type
+{
+ RESTART, ///< When the animation arrives at the end in looping mode, the animation restarts from the beginning.
+ AUTO_REVERSE ///< When the animation arrives at the end in looping mode, the animation reverses direction and runs backwards again.
+};
+
+} // namespace LoopingMode
+
} // namespace DevelImageVisual
} // namespace Toolkit
// Flags for re-sending data to the rasterize thread
enum Flags
{
- RESEND_PLAY_RANGE = 1 << 0,
- RESEND_LOOP_COUNT = 1 << 1
+ RESEND_PLAY_RANGE = 1 << 0,
+ RESEND_LOOP_COUNT = 1 << 1,
+ RESEND_STOP_BEHAVIOR = 1 << 2,
+ RESEND_LOOPING_MODE = 1 << 3
};
+// stop behavior
+DALI_ENUM_TO_STRING_TABLE_BEGIN( STOP_BEHAVIOR )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::Toolkit::DevelImageVisual::StopBehavior, CURRENT_FRAME )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::Toolkit::DevelImageVisual::StopBehavior, FIRST_FRAME )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::Toolkit::DevelImageVisual::StopBehavior, LAST_FRAME )
+DALI_ENUM_TO_STRING_TABLE_END( STOP_BEHAVIOR )
+
+// looping mode
+DALI_ENUM_TO_STRING_TABLE_BEGIN( LOOPING_MODE )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::Toolkit::DevelImageVisual::LoopingMode, RESTART )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::Toolkit::DevelImageVisual::LoopingMode, AUTO_REVERSE )
+DALI_ENUM_TO_STRING_TABLE_END( LOOPING_MODE )
+
#if defined(DEBUG_ENABLED)
Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
#endif
mStartFrame( 0 ),
mEndFrame( 0 ),
mResendFlag( 0 ),
- mActionStatus( DevelAnimatedVectorImageVisual::Action::STOP )
+ mActionStatus( DevelAnimatedVectorImageVisual::Action::STOP ),
+ mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ),
+ mLoopingMode( DevelImageVisual::LoopingMode::RESTART )
{
// the rasterized image is with pre-multiplied alpha format
mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
map.Insert( Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast< int >( mVectorRasterizeThread.GetPlayState() ) );
map.Insert( Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast< int32_t >( mVectorRasterizeThread.GetCurrentFrameNumber() ) );
map.Insert( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast< int32_t >( mVectorRasterizeThread.GetTotalFrameNumber() ) );
+
+ map.Insert( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mStopBehavior );
+ map.Insert( Toolkit::DevelImageVisual::Property::LOOPING_MODE, mLoopingMode );
}
void AnimatedVectorImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
{
DoSetProperty( Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second );
}
+ else if( keyValue.first == STOP_BEHAVIOR_NAME )
+ {
+ DoSetProperty( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second );
+ }
+ else if( keyValue.first == LOOPING_MODE_NAME )
+ {
+ DoSetProperty( Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second );
+ }
}
}
}
}
break;
}
+ case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
+ {
+ int32_t stopBehavior;
+ Scripting::GetEnumerationProperty( value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior );
+ mStopBehavior = DevelImageVisual::StopBehavior::Type( stopBehavior );
+ mResendFlag |= RESEND_STOP_BEHAVIOR;
+ break;
+ }
+ case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
+ {
+ int32_t loopingMode;
+ Scripting::GetEnumerationProperty( value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode );
+ mLoopingMode = DevelImageVisual::LoopingMode::Type( loopingMode );
+ mResendFlag |= RESEND_LOOPING_MODE;
+ break;
+ }
}
}
mVectorRasterizeThread.SetPlayRange( mStartFrame, mEndFrame );
}
+ if( mResendFlag & RESEND_STOP_BEHAVIOR )
+ {
+ mVectorRasterizeThread.SetStopBehavior( mStopBehavior );
+ }
+
+ if( mResendFlag & RESEND_LOOPING_MODE )
+ {
+ mVectorRasterizeThread.SetLoopingMode( mLoopingMode );
+ }
+
if( IsOnStage() )
{
if( isPlaying )
int32_t mEndFrame;
uint32_t mResendFlag;
DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
+ DevelImageVisual::StopBehavior::Type mStopBehavior;
+ DevelImageVisual::LoopingMode::Type mLoopingMode;
};
} // namespace Internal
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 )
+inline void ResetValue( bool& updated, uint32_t& value, uint32_t newValue, ConditionalWait& conditionalWait )
{
ConditionalWait::ScopedLock lock( conditionalWait );
if( !updated )
{
- value = startValue;
+ value = newValue;
+ updated = true;
}
}
mConditionalWait(),
mResourceReadyTrigger(),
mAnimationFinishedTrigger(),
- mPlayState( DevelImageVisual::PlayState::STOPPED ),
+ mPlayState( PlayState::STOPPED ),
+ mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ),
+ mLoopingMode( DevelImageVisual::LoopingMode::RESTART ),
mFrameDurationNanoSeconds( 0 ),
mFrameRate( 60.0f ),
mCurrentFrame( 0 ),
mDestroyThread( false ),
mResourceReady( false ),
mCurrentFrameUpdated( false ),
+ mForward( true ),
+ mUpdateFrameNumber( false ),
mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
{
Initialize();
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( mPlayState != DevelImageVisual::PlayState::PLAYING )
+ if( mPlayState != PlayState::PLAYING )
{
- mPlayState = DevelImageVisual::PlayState::PLAYING;
+ mNeedRender = true;
+ mUpdateFrameNumber = false;
+ mPlayState = PlayState::PLAYING;
mConditionalWait.Notify( lock );
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PlayAnimation: Start\n" );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PlayAnimation: Play\n" );
}
}
void VectorRasterizeThread::StopAnimation()
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( mPlayState != DevelImageVisual::PlayState::STOPPED )
+ if( mPlayState != PlayState::STOPPED && mPlayState != PlayState::STOPPING )
{
- mPlayState = DevelImageVisual::PlayState::STOPPED;
-
- mCurrentFrame = mStartFrame;
- mCurrentFrameUpdated = true;
+ mNeedRender = true;
+ mPlayState = PlayState::STOPPING;
+ mConditionalWait.Notify( lock );
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" );
}
void VectorRasterizeThread::PauseAnimation()
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( mPlayState == DevelImageVisual::PlayState::PLAYING )
+ if( mPlayState == PlayState::PLAYING )
{
- mPlayState = DevelImageVisual::PlayState::PAUSED;
+ mPlayState = PlayState::PAUSED;
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause\n" );
}
}
}
+DevelImageVisual::PlayState::Type VectorRasterizeThread::GetPlayState() const
+{
+ DevelImageVisual::PlayState::Type state = DevelImageVisual::PlayState::STOPPED;
+
+ switch( mPlayState )
+ {
+ case PlayState::PLAYING:
+ {
+ state = DevelImageVisual::PlayState::PLAYING;
+ break;
+ }
+ case PlayState::PAUSED:
+ {
+ state = DevelImageVisual::PlayState::PAUSED;
+ break;
+ }
+ case PlayState::STOPPING:
+ case PlayState::STOPPED:
+ {
+ state = DevelImageVisual::PlayState::STOPPED;
+ break;
+ }
+ }
+
+ return state;
+}
+
+bool VectorRasterizeThread::IsResourceReady() const
+{
+ return mResourceReady;
+}
+
void VectorRasterizeThread::SetCurrentFrameNumber( uint32_t frameNumber )
{
ConditionalWait::ScopedLock lock( mConditionalWait );
mResourceReady = false;
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetCurrentFrameNumber: frame number = %f (%d)\n", mCurrentFrame );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetCurrentFrameNumber: frame number = %d\n", mCurrentFrame );
}
else
{
mVectorRenderer.GetDefaultSize( width, height );
}
-DevelImageVisual::PlayState VectorRasterizeThread::GetPlayState() const
+void VectorRasterizeThread::SetStopBehavior( DevelImageVisual::StopBehavior::Type stopBehavior )
{
- return mPlayState;
+ ConditionalWait::ScopedLock lock( mConditionalWait );
+ mStopBehavior = stopBehavior;
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetStopBehavior: stop behavor = %d\n", mStopBehavior );
}
-bool VectorRasterizeThread::IsResourceReady() const
+void VectorRasterizeThread::SetLoopingMode( DevelImageVisual::LoopingMode::Type loopingMode )
{
- return mResourceReady;
+ ConditionalWait::ScopedLock lock( mConditionalWait );
+ mLoopingMode = loopingMode;
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetLoopingMode: looping mode = %d\n", mLoopingMode );
}
void VectorRasterizeThread::Initialize()
mTotalFrame = mVectorRenderer.GetTotalFrameNumber();
- mEndFrame = mTotalFrame;
+ mEndFrame = mTotalFrame - 1;
mFrameRate = mVectorRenderer.GetFrameRate();
mFrameDurationNanoSeconds = NANOSECONDS_PER_SECOND / mFrameRate;
void VectorRasterizeThread::Rasterize()
{
- bool resourceReady;
+ bool resourceReady, stopped = false;
uint32_t currentFrame, startFrame, endFrame;
int32_t loopCount;
- DevelImageVisual::PlayState playState;
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( mPlayState != DevelImageVisual::PlayState::PLAYING && !mNeedRender && !mDestroyThread )
+ if( ( mPlayState == PlayState::PAUSED || mPlayState == PlayState::STOPPED ) && !mNeedRender && !mDestroyThread )
{
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Wait\n" );
-
- if( mPlayState == DevelImageVisual::PlayState::STOPPED )
- {
- // Reset the current loop
- mCurrentLoop = 0;
- }
mConditionalWait.Wait( lock );
}
+ if( mPlayState == PlayState::PLAYING && mUpdateFrameNumber )
+ {
+ mCurrentFrame = mForward ? mCurrentFrame + 1 : mCurrentFrame - 1;
+ }
+
resourceReady = mResourceReady;
- currentFrame = mCurrentFrame++;
+ currentFrame = mCurrentFrame;
startFrame = mStartFrame;
endFrame = mEndFrame;
loopCount = mLoopCount;
- playState = mPlayState;
mNeedRender = false;
mResourceReady = true;
mCurrentFrameUpdated = false;
+ mUpdateFrameNumber = true;
}
auto currentFrameStartTime = std::chrono::system_clock::now();
- // Rasterize
- mVectorRenderer.Render( currentFrame );
+ if( mPlayState == PlayState::STOPPING )
+ {
+ currentFrame = GetStoppedFrame( startFrame, endFrame, currentFrame );
+ ResetValue( mCurrentFrameUpdated, mCurrentFrame, currentFrame, mConditionalWait );
- if( playState == DevelImageVisual::PlayState::PLAYING )
+ stopped = true;
+ }
+ else if( mPlayState == PlayState::PLAYING )
{
- if( currentFrame >= endFrame )
+ bool animationFinished = false;
+
+ if( currentFrame >= endFrame ) // last frame
{
- if( loopCount < 0 )
+ if( mLoopingMode == DevelImageVisual::LoopingMode::AUTO_REVERSE )
{
- // repeat forever
- ResetToStart( mCurrentFrameUpdated, mCurrentFrame, startFrame, mConditionalWait ); // If the current frame is changed in the event thread, don't overwrite it.
+ mForward = false;
}
else
{
- mCurrentLoop++;
- if( mCurrentLoop >= loopCount )
+ if( loopCount < 0 || ++mCurrentLoop < loopCount ) // repeat forever or before the last loop
{
- mPlayState = DevelImageVisual::PlayState::STOPPED;
-
- ResetToStart( mCurrentFrameUpdated, mCurrentFrame, startFrame, mConditionalWait );
-
- // Animation is finished
- mAnimationFinishedTrigger->Trigger();
-
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" );
+ ResetValue( mCurrentFrameUpdated, mCurrentFrame, startFrame, mConditionalWait ); // If the current frame is changed in the event thread, don't overwrite it.
+ mUpdateFrameNumber = false;
}
else
{
- ResetToStart( mCurrentFrameUpdated, mCurrentFrame, startFrame, mConditionalWait );
+ animationFinished = true; // end of animation
}
}
}
+ else if( currentFrame == startFrame && !mForward ) // first frame
+ {
+ if( loopCount < 0 || ++mCurrentLoop < loopCount ) // repeat forever or before the last loop
+ {
+ mForward = true;
+ }
+ else
+ {
+ animationFinished = true; // end of animation
+ }
+ }
+
+ if( animationFinished )
+ {
+ if( mStopBehavior == DevelImageVisual::StopBehavior::CURRENT_FRAME )
+ {
+ stopped = true;
+ }
+ else
+ {
+ mPlayState = PlayState::STOPPING;
+ }
+ }
}
+ // Rasterize
+ mVectorRenderer.Render( currentFrame );
+
if( !resourceReady )
{
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Resource ready trigger\n" );
mResourceReadyTrigger->Trigger();
}
+ if( stopped )
+ {
+ mPlayState = PlayState::STOPPED;
+ mForward = true;
+ mCurrentLoop = 0;
+
+ // Animation is finished
+ mAnimationFinishedTrigger->Trigger();
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" );
+ }
+
auto timeToSleepUntil = currentFrameStartTime + std::chrono::nanoseconds( mFrameDurationNanoSeconds );
#if defined(DEBUG_ENABLED)
std::this_thread::sleep_until( timeToSleepUntil );
}
+uint32_t VectorRasterizeThread::GetStoppedFrame( uint32_t startFrame, uint32_t endFrame, uint32_t currentFrame )
+{
+ uint32_t frame = currentFrame;
+
+ switch( mStopBehavior )
+ {
+ case DevelImageVisual::StopBehavior::FIRST_FRAME:
+ {
+ frame = startFrame;
+ break;
+ }
+ case DevelImageVisual::StopBehavior::LAST_FRAME:
+ {
+ if( mLoopingMode == DevelImageVisual::LoopingMode::AUTO_REVERSE )
+ {
+ frame = startFrame;
+ }
+ else
+ {
+ frame = endFrame;
+ }
+ break;
+ }
+ case DevelImageVisual::StopBehavior::CURRENT_FRAME:
+ {
+ frame = currentFrame;
+ break;
+ }
+ }
+
+ return frame;
+}
+
} // namespace Internal
} // namespace Toolkit
* @brief Get the play state
* @return The play state
*/
- DevelImageVisual::PlayState GetPlayState() const;
+ DevelImageVisual::PlayState::Type GetPlayState() const;
/**
* @brief Queries whether the resource is ready.
*/
void GetDefaultSize( uint32_t& width, uint32_t& height ) const;
+ /**
+ * @brief Sets the stop behavior of the animation. This is performed when the animation is stopped.
+ * @param[in] stopBehavior The stop behavior
+ */
+ void SetStopBehavior( DevelImageVisual::StopBehavior::Type stopBehavior );
+
+ /**
+ * @brief Sets the looping mode.
+ * Animation plays forwards and then restarts from the beginning or runs backwards again.
+ * @param[in] loopingMode The looping mode
+ */
+ void SetLoopingMode( DevelImageVisual::LoopingMode::Type loopingMode );
+
protected:
/**
private:
/**
- * @brief Initialize the vector renderer.
+ * @brief Initializes the vector renderer.
*/
void Initialize();
/**
- * @brief Rasterize the current frame.
+ * @brief Rasterizes the current frame.
*/
void Rasterize();
+ /**
+ * @brief Gets the frame number when the animation is stopped according to the stop behavior.
+ */
+ uint32_t GetStoppedFrame( uint32_t startFrame, uint32_t endFrame, uint32_t currentFrame );
+
// Undefined
VectorRasterizeThread( const VectorRasterizeThread& thread ) = delete;
private:
+ enum class PlayState
+ {
+ STOPPING, ///< The animation is stopping
+ STOPPED, ///< The animation has stopped
+ PLAYING, ///< The animation is playing
+ PAUSED ///< The animation is paused
+ };
+
std::string mUrl;
VectorAnimationRenderer mVectorRenderer;
ConditionalWait mConditionalWait;
std::unique_ptr< EventThreadCallback > mResourceReadyTrigger;
std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
Vector2 mPlayRange;
- DevelImageVisual::PlayState mPlayState;
+ PlayState mPlayState;
+ DevelImageVisual::StopBehavior::Type mStopBehavior;
+ DevelImageVisual::LoopingMode::Type mLoopingMode;
int64_t mFrameDurationNanoSeconds;
float mFrameRate;
uint32_t mCurrentFrame;
bool mDestroyThread; ///< Whether the thread be destroyed
bool mResourceReady;
bool mCurrentFrameUpdated;
+ bool mForward;
+ bool mUpdateFrameNumber;
const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
};
const char * const PLAY_STATE_NAME( "playState" );
const char * const CURRENT_FRAME_NUMBER_NAME( "currentFrameNumber" );
const char * const TOTAL_FRAME_NUMBER_NAME( "totalFrameNumber" );
+const char * const STOP_BEHAVIOR_NAME( "stopBehavior" );
+const char * const LOOPING_MODE_NAME( "loopingMode" );
// Text visual
const char * const TEXT_PROPERTY( "text" );
extern const char * const PLAY_STATE_NAME;
extern const char * const CURRENT_FRAME_NUMBER_NAME;
extern const char * const TOTAL_FRAME_NUMBER_NAME;
+extern const char * const STOP_BEHAVIOR_NAME;
+extern const char * const LOOPING_MODE_NAME;
// Text visual
extern const char * const TEXT_PROPERTY;