/*
- * 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.
// 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
mUrl( imageUrl ),
mVectorRasterizeThread( imageUrl.GetUrl() ),
mVisualSize(),
+ mVisualScale( Vector2::ONE ),
mPlacementActor(),
mLoopCount( LOOP_FOREVER ),
mStartFrame( 0 ),
mEndFrame( 0 ),
mResendFlag( 0 ),
- mActionStatus( DevelAnimatedVectorImageVisual::Action::STOP )
+ mActionStatus( DevelAnimatedVectorImageVisual::Action::STOP ),
+ mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ),
+ mLoopingMode( DevelImageVisual::LoopingMode::RESTART ),
+ mRendererAdded( false )
{
// the rasterized image is with pre-multiplied alpha format
mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
- mVectorRasterizeThread.SetResourceReadyCallback( new EventThreadCallback( MakeCallback( this, &AnimatedVectorImageVisual::OnResourceReady ) ) );
+ mVectorRasterizeThread.UploadCompletedSignal().Connect( this, &AnimatedVectorImageVisual::OnUploadCompleted );
mVectorRasterizeThread.SetAnimationFinishedCallback( new EventThreadCallback( MakeCallback( this, &AnimatedVectorImageVisual::OnAnimationFinished ) ) );
mVectorRasterizeThread.Start();
void AnimatedVectorImageVisual::GetNaturalSize( Vector2& naturalSize )
{
- if( mImpl->mRenderer ) // Check if we have a rendered image
+ if( mVisualSize != Vector2::ZERO )
{
- auto textureSet = mImpl->mRenderer.GetTextures();
- if( textureSet )
- {
- if( textureSet.GetTextureCount() > 0 )
- {
- auto texture = textureSet.GetTexture( 0 );
- naturalSize.x = texture.GetWidth();
- naturalSize.y = texture.GetHeight();
- return;
- }
- }
+ naturalSize = mVisualSize;
+ }
+ else
+ {
+ uint32_t width, height;
+ mVectorRasterizeThread.GetDefaultSize( width, height );
+ naturalSize.x = width;
+ naturalSize.y = height;
}
- uint32_t width, height;
- mVectorRasterizeThread.GetDefaultSize( width, height );
- naturalSize.x = width;
- naturalSize.y = height;
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this );
}
void AnimatedVectorImageVisual::DoCreatePropertyMap( Property::Map& map ) const
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 = mStopBehavior;
+ if( 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 = mLoopingMode;
+ if( Scripting::GetEnumerationProperty( value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode ) )
+ {
+ mLoopingMode = DevelImageVisual::LoopingMode::Type( loopingMode );
+ mResendFlag |= RESEND_LOOPING_MODE;
+ }
+ break;
+ }
}
}
mPlacementActor = actor;
mVectorRasterizeThread.SetRenderer( mImpl->mRenderer );
+
+ // Add property notification for scaling & size
+ mScaleNotification = actor.AddPropertyNotification( Actor::Property::WORLD_SCALE, StepCondition( 0.1f, 1.0f ) );
+ mScaleNotification.NotifySignal().Connect( this, &AnimatedVectorImageVisual::OnScaleNotification );
+
+ mSizeNotification = actor.AddPropertyNotification( Actor::Property::SIZE, StepCondition( 3.0f ) );
+ mSizeNotification.NotifySignal().Connect( this, &AnimatedVectorImageVisual::OnSizeNotification );
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnStage [%p]\n", this );
}
void AnimatedVectorImageVisual::DoSetOffStage( Actor& actor )
actor.RemoveRenderer( mImpl->mRenderer );
mImpl->mRenderer.Reset();
+
+ mRendererAdded = false;
}
+ // Remove property notification
+ actor.RemovePropertyNotification( mScaleNotification );
+ actor.RemovePropertyNotification( mSizeNotification );
+
mPlacementActor.Reset();
// Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
mVisualSize = Vector2::ZERO;
+ mVisualScale = Vector2::ONE;
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffStage [%p]\n", this );
}
void AnimatedVectorImageVisual::OnSetTransform()
{
Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize );
- if( IsOnStage() )
+ if( IsOnStage() && visualSize != mVisualSize )
{
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f\n", visualSize.width, visualSize.height );
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this );
- if( visualSize != mVisualSize )
- {
- mVisualSize = visualSize;
+ mVisualSize = visualSize;
- uint32_t width = static_cast< uint32_t >( visualSize.width );
- uint32_t height = static_cast< uint32_t >( visualSize.height );
-
- mVectorRasterizeThread.SetSize( width, height );
- }
+ SetVectorImageSize();
SendAnimationData();
// Render one frame
mVectorRasterizeThread.RenderFrame();
}
-
- if( mVectorRasterizeThread.IsResourceReady() )
- {
- Actor actor = mPlacementActor.GetHandle();
- if( actor )
- {
- actor.AddRenderer( mImpl->mRenderer );
- mPlacementActor.Reset();
- }
-
- ResourceReady( Toolkit::Visual::ResourceStatus::READY );
- }
}
}
if( mVectorRasterizeThread.GetPlayState() != DevelImageVisual::PlayState::STOPPED )
{
mVectorRasterizeThread.StopAnimation();
+ }
- OnAnimationFinished();
+ if( mImpl->mRenderer )
+ {
+ mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED );
}
+
mActionStatus = DevelAnimatedVectorImageVisual::Action::STOP;
break;
}
}
}
-void AnimatedVectorImageVisual::OnResourceReady()
+void AnimatedVectorImageVisual::OnUploadCompleted()
{
// If weak handle is holding a placement actor, it is the time to add the renderer to actor.
Actor actor = mPlacementActor.GetHandle();
- if( actor )
+ if( actor && !mRendererAdded )
{
actor.AddRenderer( mImpl->mRenderer );
- // reset the weak handle so that the renderer only get added to actor once
- mPlacementActor.Reset();
-
- ResourceReady( Toolkit::Visual::ResourceStatus::READY );
+ mRendererAdded = true;
}
+
+ ResourceReady( Toolkit::Visual::ResourceStatus::READY );
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnUploadCompleted: Renderer is added [%p]\n", this );
}
void AnimatedVectorImageVisual::OnAnimationFinished()
{
- if( mImpl->mEventObserver )
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mActionStatus, this );
+
+ if( mActionStatus != DevelAnimatedVectorImageVisual::Action::STOP )
{
- mImpl->mEventObserver->NotifyVisualEvent( *this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED );
- }
+ mActionStatus = DevelAnimatedVectorImageVisual::Action::STOP;
- mActionStatus = DevelAnimatedVectorImageVisual::Action::STOP;
+ if( mImpl->mEventObserver )
+ {
+ mImpl->mEventObserver->NotifyVisualEvent( *this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED );
+ }
+ }
if( mImpl->mRenderer )
{
mVectorRasterizeThread.SetPlayRange( mStartFrame, mEndFrame );
}
+ if( mResendFlag & RESEND_STOP_BEHAVIOR )
+ {
+ mVectorRasterizeThread.SetStopBehavior( mStopBehavior );
+ }
+
+ if( mResendFlag & RESEND_LOOPING_MODE )
+ {
+ mVectorRasterizeThread.SetLoopingMode( mLoopingMode );
+ }
+
if( IsOnStage() )
{
if( isPlaying )
}
}
+void AnimatedVectorImageVisual::SetVectorImageSize()
+{
+ uint32_t width = static_cast< uint32_t >( mVisualSize.width * mVisualScale.width );
+ uint32_t height = static_cast< uint32_t >( mVisualSize.height * mVisualScale.height );
+
+ mVectorRasterizeThread.SetSize( width, height );
+
+ if( IsOnStage() && mVectorRasterizeThread.GetPlayState() != DevelImageVisual::PlayState::PLAYING )
+ {
+ mVectorRasterizeThread.RenderFrame();
+ Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger rendering
+ }
+}
+
+void AnimatedVectorImageVisual::OnScaleNotification( PropertyNotification& source )
+{
+ Actor actor = mPlacementActor.GetHandle();
+ if( actor )
+ {
+ Vector3 scale = actor.GetProperty< Vector3 >( Actor::Property::WORLD_SCALE );
+ mVisualScale.width = scale.width;
+ mVisualScale.height = scale.height;
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this );
+
+ SetVectorImageSize();
+ }
+}
+
+void AnimatedVectorImageVisual::OnSizeNotification( PropertyNotification& source )
+{
+ Actor actor = mPlacementActor.GetHandle();
+ if( actor )
+ {
+ Vector3 size = actor.GetCurrentSize();
+ mVisualSize.width = size.width;
+ mVisualSize.height = size.height;
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this );
+
+ SetVectorImageSize();
+ }
+}
+
} // namespace Internal
} // namespace Toolkit