X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fanimated-vector-image-visual.cpp;h=e7255ea3800daf359b2ae5710041dde8f2efc7e3;hb=2b051f9220d4e28225a57d5dabc98e093357cad6;hp=1793fbc7885d54d002cc57102c29888694d3b0b3;hpb=4fd91b026f3eca1d55f15dc4b491cf14ff39ff5c;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 1793fbc..e7255ea 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include // INTERNAL INCLUDES @@ -46,19 +47,8 @@ namespace Internal namespace { -constexpr auto LOOP_FOREVER = -1; - const Dali::Vector4 FULL_TEXTURE_RECT( 0.f, 0.f, 1.f, 1.f ); -// Flags for re-sending data to the rasterize thread -enum Flags -{ - 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 ) @@ -94,20 +84,17 @@ 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() ) ), mImageVisualShaderFactory( shaderFactory ), mVisualSize(), mVisualScale( Vector2::ONE ), - mPlayRange(), mPlacementActor(), - mLoopCount( LOOP_FOREVER ), - mResendFlag( 0 ), - mActionStatus( DevelAnimatedVectorImageVisual::Action::STOP ), - mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ), - mLoopingMode( DevelImageVisual::LoopingMode::RESTART ), - mRendererAdded( false ) + mPlayState( DevelImageVisual::PlayState::STOPPED ), + mRendererAdded( false ), + mRasterizationTriggered( false ) { // the rasterized image is with pre-multiplied alpha format mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; @@ -118,6 +105,11 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factor AnimatedVectorImageVisual::~AnimatedVectorImageVisual() { + if( mRasterizationTriggered && Adaptor::IsAvailable() ) + { + Adaptor::Get().UnregisterProcessor( *this ); + } + // Finalize animation task and disconnect the signal in the main thread mVectorAnimationTask->UploadCompletedSignal().Disconnect( this, &AnimatedVectorImageVisual::OnUploadCompleted ); mVectorAnimationTask->Finalize(); @@ -148,7 +140,7 @@ void AnimatedVectorImageVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Insert( Toolkit::ImageVisual::Property::URL, mUrl.GetUrl() ); } - map.Insert( Toolkit::DevelImageVisual::Property::LOOP_COUNT, mLoopCount ); + map.Insert( Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount ); uint32_t startFrame, endFrame; mVectorAnimationTask->GetPlayRange( startFrame, endFrame ); @@ -158,12 +150,12 @@ void AnimatedVectorImageVisual::DoCreatePropertyMap( Property::Map& map ) const playRange.PushBack( static_cast< int32_t >( endFrame ) ); map.Insert( Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange ); - map.Insert( Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast< int32_t >( mVectorAnimationTask->GetPlayState() ) ); + map.Insert( Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast< int32_t >( mPlayState ) ); map.Insert( Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast< int32_t >( mVectorAnimationTask->GetCurrentFrameNumber() ) ); map.Insert( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast< int32_t >( mVectorAnimationTask->GetTotalFrameNumber() ) ); - map.Insert( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mStopBehavior ); - map.Insert( Toolkit::DevelImageVisual::Property::LOOPING_MODE, mLoopingMode ); + map.Insert( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior ); + map.Insert( Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode ); Property::Map layerInfo; mVectorAnimationTask->GetLayerInfo( layerInfo ); @@ -205,6 +197,8 @@ void AnimatedVectorImageVisual::DoSetProperties( const Property::Map& propertyMa } } } + + TriggerVectorRasterization(); } void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Property::Value& value ) @@ -216,8 +210,8 @@ void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Prop int32_t loopCount; if( value.Get( loopCount ) ) { - mLoopCount = loopCount; - mResendFlag |= RESEND_LOOP_COUNT; + mAnimationData.loopCount = loopCount; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT; } break; } @@ -226,28 +220,28 @@ void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Prop Property::Array* array = value.GetArray(); if( array ) { - mPlayRange = *array; - mResendFlag |= RESEND_PLAY_RANGE; + mAnimationData.playRange = *array; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE; } break; } case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR: { - int32_t stopBehavior = mStopBehavior; + int32_t stopBehavior = mAnimationData.stopBehavior; if( Scripting::GetEnumerationProperty( value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior ) ) { - mStopBehavior = DevelImageVisual::StopBehavior::Type( stopBehavior ); - mResendFlag |= RESEND_STOP_BEHAVIOR; + mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type( stopBehavior ); + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR; } break; } case Toolkit::DevelImageVisual::Property::LOOPING_MODE: { - int32_t loopingMode = mLoopingMode; + int32_t loopingMode = mAnimationData.loopingMode; if( Scripting::GetEnumerationProperty( value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode ) ) { - mLoopingMode = DevelImageVisual::LoopingMode::Type( loopingMode ); - mResendFlag |= RESEND_LOOPING_MODE; + mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type( loopingMode ); + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE; } break; } @@ -309,6 +303,7 @@ void AnimatedVectorImageVisual::DoSetOnStage( Actor& actor ) void AnimatedVectorImageVisual::DoSetOffStage( Actor& actor ) { StopAnimation(); + SendAnimationData(); if( mImpl->mRenderer ) { @@ -351,19 +346,13 @@ void AnimatedVectorImageVisual::OnSetTransform() SetVectorImageSize(); - SendAnimationData(); - - if( mActionStatus == DevelAnimatedVectorImageVisual::Action::PLAY ) + if( mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING ) { - mVectorAnimationTask->PlayAnimation(); - - mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY ); - } - else - { - // Render one frame - mVectorAnimationTask->RenderFrame(); + mAnimationData.playState = DevelImageVisual::PlayState::PLAYING; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; } + + SendAnimationData(); } } @@ -376,38 +365,33 @@ void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, cons { if( IsOnStage() && mVisualSize != Vector2::ZERO ) { - mVectorAnimationTask->PlayAnimation(); - - mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY ); + if( mAnimationData.playState != DevelImageVisual::PlayState::PLAYING ) + { + mAnimationData.playState = DevelImageVisual::PlayState::PLAYING; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; + } } - mActionStatus = DevelAnimatedVectorImageVisual::Action::PLAY; + mPlayState = DevelImageVisual::PlayState::PLAYING; break; } case DevelAnimatedVectorImageVisual::Action::PAUSE: { - mVectorAnimationTask->PauseAnimation(); - - if( mImpl->mRenderer ) + if( mAnimationData.playState == DevelImageVisual::PlayState::PLAYING ) { - mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED ); + mAnimationData.playState = DevelImageVisual::PlayState::PAUSED; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; } - - mActionStatus = DevelAnimatedVectorImageVisual::Action::PAUSE; + mPlayState = DevelImageVisual::PlayState::PAUSED; break; } case DevelAnimatedVectorImageVisual::Action::STOP: { - if( mVectorAnimationTask->GetPlayState() != DevelImageVisual::PlayState::STOPPED ) + if( mAnimationData.playState != DevelImageVisual::PlayState::STOPPED ) { - mVectorAnimationTask->StopAnimation(); - } - - if( mImpl->mRenderer ) - { - mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED ); + mAnimationData.playState = DevelImageVisual::PlayState::STOPPED; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; } - - mActionStatus = DevelAnimatedVectorImageVisual::Action::STOP; + mPlayState = DevelImageVisual::PlayState::STOPPED; break; } case DevelAnimatedVectorImageVisual::Action::JUMP_TO: @@ -415,13 +399,8 @@ void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, cons int32_t frameNumber; if( attributes.Get( frameNumber ) ) { - mVectorAnimationTask->SetCurrentFrameNumber( frameNumber ); - - if( IsOnStage() && mVectorAnimationTask->GetPlayState() != DevelImageVisual::PlayState::PLAYING ) - { - mVectorAnimationTask->RenderFrame(); - Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger rendering - } + mAnimationData.currentFrame = frameNumber; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME; } break; } @@ -431,12 +410,21 @@ void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, cons if( map ) { DoSetProperties( *map ); - - SendAnimationData(); } break; } } + + TriggerVectorRasterization(); +} + +void AnimatedVectorImageVisual::Process() +{ + SendAnimationData(); + + mRasterizationTriggered = false; + + Adaptor::Get().UnregisterProcessor( *this ); } void AnimatedVectorImageVisual::OnUploadCompleted() @@ -456,11 +444,13 @@ void AnimatedVectorImageVisual::OnUploadCompleted() void AnimatedVectorImageVisual::OnAnimationFinished() { - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mActionStatus, this ); + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this ); - if( mActionStatus != DevelAnimatedVectorImageVisual::Action::STOP ) + if( mPlayState != DevelImageVisual::PlayState::STOPPED ) { - mActionStatus = DevelAnimatedVectorImageVisual::Action::STOP; + mPlayState = DevelImageVisual::PlayState::STOPPED; + + mAnimationData.playState = DevelImageVisual::PlayState::STOPPED; if( mImpl->mEventObserver ) { @@ -476,49 +466,23 @@ void AnimatedVectorImageVisual::OnAnimationFinished() void AnimatedVectorImageVisual::SendAnimationData() { - if( mResendFlag ) + if( mAnimationData.resendFlag ) { - bool isPlaying = false; - if( mVectorAnimationTask->GetPlayState() == DevelImageVisual::PlayState::PLAYING ) - { - mVectorAnimationTask->PauseAnimation(); - isPlaying = true; - } - - if( mResendFlag & RESEND_LOOP_COUNT ) - { - mVectorAnimationTask->SetLoopCount( mLoopCount ); - } - - if( mResendFlag & RESEND_PLAY_RANGE ) - { - mVectorAnimationTask->SetPlayRange( mPlayRange ); - } - - if( mResendFlag & RESEND_STOP_BEHAVIOR ) - { - mVectorAnimationTask->SetStopBehavior( mStopBehavior ); - } - - if( mResendFlag & RESEND_LOOPING_MODE ) - { - mVectorAnimationTask->SetLoopingMode( mLoopingMode ); - } + mVectorAnimationTask->SetAnimationData( mAnimationData ); - if( IsOnStage() ) + if( mImpl->mRenderer ) { - if( isPlaying ) + if( mAnimationData.playState == DevelImageVisual::PlayState::PLAYING ) { - mVectorAnimationTask->PlayAnimation(); + mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY ); } else { - mVectorAnimationTask->RenderFrame(); - Stage::GetCurrent().KeepRendering( 0.0f ); + mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED ); } } - mResendFlag = 0; + mAnimationData.resendFlag = 0; } } @@ -527,27 +491,30 @@ 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 ); - mVectorAnimationTask->SetSize( width, height ); + mAnimationData.width = width; + mAnimationData.height = height; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE; +} - if( IsOnStage() && mVectorAnimationTask->GetPlayState() != DevelImageVisual::PlayState::PLAYING ) +void AnimatedVectorImageVisual::StopAnimation() +{ + if( mAnimationData.playState != DevelImageVisual::PlayState::STOPPED ) { - mVectorAnimationTask->RenderFrame(); - Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger rendering + mAnimationData.playState = DevelImageVisual::PlayState::STOPPED; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; + + mPlayState = DevelImageVisual::PlayState::STOPPED; } } -void AnimatedVectorImageVisual::StopAnimation() +void AnimatedVectorImageVisual::TriggerVectorRasterization() { - if( mActionStatus != DevelAnimatedVectorImageVisual::Action::STOP ) + if( !mRasterizationTriggered ) { - mVectorAnimationTask->StopAnimation(); + Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger event processing - mActionStatus = DevelAnimatedVectorImageVisual::Action::STOP; - - if( mImpl->mRenderer ) - { - mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED ); - } + Adaptor::Get().RegisterProcessor( *this ); + mRasterizationTriggered = true; } } @@ -563,6 +530,9 @@ void AnimatedVectorImageVisual::OnScaleNotification( PropertyNotification& sourc DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this ); SetVectorImageSize(); + SendAnimationData(); + + Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger event processing } } @@ -578,6 +548,9 @@ void AnimatedVectorImageVisual::OnSizeNotification( PropertyNotification& source DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this ); SetVectorImageSize(); + SendAnimationData(); + + Stage::GetCurrent().KeepRendering( 0.0f ); // Trigger event processing } } @@ -586,6 +559,7 @@ void AnimatedVectorImageVisual::OnControlVisibilityChanged( Actor actor, bool vi if( !visible ) { StopAnimation(); + TriggerVectorRasterization(); DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this ); } @@ -596,6 +570,7 @@ void AnimatedVectorImageVisual::OnWindowVisibilityChanged( Window window, bool v if( !visible ) { StopAnimation(); + TriggerVectorRasterization(); DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this ); }