X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fanimated-vector-image-visual.cpp;h=fead0e60bfc1204cb2b86e746d7684b304679d61;hp=bf3b51932a808cd8acec7a6f319d573cd9f30409;hb=ed11499452da1ccd5fdfa36324881dc66a5281bc;hpb=33f29d762e4410026a85521f05b7b66aa2d087d1 diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index bf3b519..fead0e6 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -19,10 +19,9 @@ #include // EXTERNAL INCLUDES -#include +#include #include #include -#include #include // INTERNAL INCLUDES @@ -34,6 +33,7 @@ #include #include #include +#include namespace Dali { @@ -84,7 +84,7 @@ AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New( VisualFactoryCache& } AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl ) -: Visual::Base( factoryCache, Visual::FittingMode::FILL ), +: Visual::Base( factoryCache, Visual::FittingMode::FILL, static_cast( Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE ) ), mUrl( imageUrl ), mAnimationData(), mVectorAnimationTask( new VectorAnimationTask( factoryCache, imageUrl.GetUrl() ) ), @@ -93,26 +93,42 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factor mVisualScale( Vector2::ONE ), mPlacementActor(), mPlayState( DevelImageVisual::PlayState::STOPPED ), + mEventCallback( nullptr ), mRendererAdded( false ), - mRasterizationTriggered( false ) + mCoreShutdown(false) { // the rasterized image is with pre-multiplied alpha format mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; mVectorAnimationTask->UploadCompletedSignal().Connect( this, &AnimatedVectorImageVisual::OnUploadCompleted ); mVectorAnimationTask->SetAnimationFinishedCallback( new EventThreadCallback( MakeCallback( this, &AnimatedVectorImageVisual::OnAnimationFinished ) ) ); + + auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager(); + vectorAnimationManager.AddObserver(*this); } AnimatedVectorImageVisual::~AnimatedVectorImageVisual() { - if( mRasterizationTriggered && Adaptor::IsAvailable() ) + if( ! mCoreShutdown ) { - Adaptor::Get().UnregisterProcessor( *this ); + auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager(); + vectorAnimationManager.RemoveObserver(*this); + + if( mEventCallback ) + { + mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback( mEventCallback ); + } + + // Finalize animation task and disconnect the signal in the main thread + mVectorAnimationTask->UploadCompletedSignal().Disconnect( this, &AnimatedVectorImageVisual::OnUploadCompleted ); + mVectorAnimationTask->Finalize(); } +} - // Finalize animation task and disconnect the signal in the main thread - mVectorAnimationTask->UploadCompletedSignal().Disconnect( this, &AnimatedVectorImageVisual::OnUploadCompleted ); - mVectorAnimationTask->Finalize(); +void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed() +{ + // Core is shutting down. Don't talk to the plugin any more. + mCoreShutdown = true; } void AnimatedVectorImageVisual::GetNaturalSize( Vector2& naturalSize ) @@ -217,7 +233,7 @@ void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Prop } case Toolkit::DevelImageVisual::Property::PLAY_RANGE: { - Property::Array* array = value.GetArray(); + const Property::Array* array = value.GetArray(); if( array ) { mAnimationData.playRange = *array; @@ -248,7 +264,7 @@ void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Prop } } -void AnimatedVectorImageVisual::DoSetOnStage( Actor& actor ) +void AnimatedVectorImageVisual::DoSetOnScene( Actor& actor ) { Shader shader; @@ -297,10 +313,10 @@ void AnimatedVectorImageVisual::DoSetOnStage( Actor& actor ) DevelWindow::VisibilityChangedSignal( window ).Connect( this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged ); } - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnStage [%p]\n", this ); + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this ); } -void AnimatedVectorImageVisual::DoSetOffStage( Actor& actor ) +void AnimatedVectorImageVisual::DoSetOffScene( Actor& actor ) { StopAnimation(); SendAnimationData(); @@ -331,14 +347,14 @@ void AnimatedVectorImageVisual::DoSetOffStage( Actor& actor ) mVisualSize = Vector2::ZERO; mVisualScale = Vector2::ONE; - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffStage [%p]\n", this ); + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this ); } void AnimatedVectorImageVisual::OnSetTransform() { Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize ); - if( IsOnStage() && visualSize != mVisualSize ) + if( IsOnScene() && visualSize != mVisualSize ) { DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this ); @@ -363,7 +379,7 @@ void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, cons { case DevelAnimatedVectorImageVisual::Action::PLAY: { - if( IsOnStage() && mVisualSize != Vector2::ZERO ) + if( IsOnScene() && mVisualSize != Vector2::ZERO ) { if( mAnimationData.playState != DevelImageVisual::PlayState::PLAYING ) { @@ -406,7 +422,7 @@ void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, cons } case DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY: { - Property::Map* map = attributes.GetMap(); + const Property::Map* map = attributes.GetMap(); if( map ) { DoSetProperties( *map ); @@ -418,15 +434,6 @@ void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, cons TriggerVectorRasterization(); } -void AnimatedVectorImageVisual::Process() -{ - SendAnimationData(); - - mRasterizationTriggered = false; - - Adaptor::Get().UnregisterProcessor( *this ); -} - void AnimatedVectorImageVisual::OnUploadCompleted() { // If weak handle is holding a placement actor, it is the time to add the renderer to actor. @@ -509,12 +516,12 @@ void AnimatedVectorImageVisual::StopAnimation() void AnimatedVectorImageVisual::TriggerVectorRasterization() { - if( !mRasterizationTriggered ) + if( !mEventCallback && !mCoreShutdown ) { + mEventCallback = MakeCallback( this, &AnimatedVectorImageVisual::OnProcessEvents ); + auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager(); + vectorAnimationManager.RegisterEventCallback( mEventCallback ); Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger event processing - - Adaptor::Get().RegisterProcessor( *this ); - mRasterizationTriggered = true; } } @@ -576,6 +583,13 @@ void AnimatedVectorImageVisual::OnWindowVisibilityChanged( Window window, bool v } } +void AnimatedVectorImageVisual::OnProcessEvents() +{ + SendAnimationData(); + + mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager +} + } // namespace Internal } // namespace Toolkit