X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-image%2Fanimated-image-visual.cpp;h=386013a98c470a3349a14861d2ed5a7d99c4fe75;hp=51a4cceb65cd6f120097af3c5073ae83aa1e509a;hb=248c644059d4784ab65fe3d2690022c2888edd3b;hpb=c295a64b88c2cbbdd30543afe2464060de7816fd diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp index 51a4cce..386013a 100755 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 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. @@ -30,12 +30,13 @@ #include #include #include +#include #include #include #include -#include #include #include +#include namespace Dali { @@ -48,6 +49,13 @@ namespace Internal namespace { +// 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 ) + // wrap modes DALI_ENUM_TO_STRING_TABLE_BEGIN( WRAP_MODE ) DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::WrapMode, DEFAULT ) @@ -100,9 +108,9 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, " * Time */ -AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ) +AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties ) { - AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache ) ); + AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache, shaderFactory ) ); visual->InitializeGif( imageUrl ); visual->SetProperties( properties ); @@ -114,9 +122,9 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach return visual; } -AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const Property::Array& imageUrls, const Property::Map& properties ) +AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const Property::Array& imageUrls, const Property::Map& properties ) { - AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache ) ); + AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache, shaderFactory ) ); visual->mImageUrls = new ImageCache::UrlList(); visual->mImageUrls->reserve( imageUrls.Count() ); @@ -138,9 +146,9 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach return visual; } -AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ) +AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl ) { - AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache ) ); + AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache, shaderFactory ) ); visual->InitializeGif( imageUrl ); if( visual->mFrameCount > 0 ) @@ -154,15 +162,16 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach void AnimatedImageVisual::InitializeGif( const VisualUrl& imageUrl ) { mImageUrl = imageUrl; - mGifLoading = GifLoading::New( imageUrl.GetUrl() ); + mGifLoading = GifLoading::New( imageUrl.GetUrl(), imageUrl.IsLocalResource() ); mFrameCount = mGifLoading->GetImageCount(); mGifLoading->LoadFrameDelays( mFrameDelayContainer ); } -AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), +AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory ) +: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::ANIMATED_IMAGE ), mFrameDelayTimer(), mPlacementActor(), + mImageVisualShaderFactory( shaderFactory ), mPixelArea( FULL_TEXTURE_RECT ), mImageUrl(), mGifLoading( nullptr ), @@ -180,7 +189,9 @@ AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache ) mWrapModeU( WrapMode::DEFAULT ), mWrapModeV( WrapMode::DEFAULT ), mActionStatus( DevelAnimatedImageVisual::Action::PLAY ), - mStartFirstFrame(false) + mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ), + mStartFirstFrame(false), + mIsJumpTo( false ) {} AnimatedImageVisual::~AnimatedImageVisual() @@ -236,6 +247,8 @@ void AnimatedImageVisual::DoCreatePropertyMap( Property::Map& map ) const map.Insert( Toolkit::ImageVisual::Property::CACHE_SIZE, static_cast(mCacheSize) ); map.Insert( Toolkit::ImageVisual::Property::FRAME_DELAY, static_cast(mFrameDelay) ); map.Insert( Toolkit::DevelImageVisual::Property::LOOP_COUNT, static_cast(mLoopCount) ); + + map.Insert( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mStopBehavior ); } void AnimatedImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const @@ -268,8 +281,32 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons { // STOP reset functionality will actually be done in a future change // Stop will be executed on next timer tick - mCurrentFrameIndex = 0; mActionStatus = DevelAnimatedImageVisual::Action::STOP; + if( IsOnStage() ) + { + DisplayNextFrame(); + } + break; + } + case DevelAnimatedImageVisual::Action::JUMP_TO: + { + int32_t frameNumber; + if( attributes.Get( frameNumber ) ) + { + if( frameNumber < 0 || frameNumber >= static_cast( mFrameCount ) ) + { + DALI_LOG_ERROR( "Invalid frame index used.\n" ); + } + else + { + mIsJumpTo = true; + mCurrentFrameIndex = frameNumber; + if( IsOnStage() ) + { + DisplayNextFrame(); + } + } + } break; } } @@ -316,6 +353,10 @@ void AnimatedImageVisual::DoSetProperties( const Property::Map& propertyMap ) { DoSetProperty( Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second ); } + else if( keyValue.first == STOP_BEHAVIOR_NAME ) + { + DoSetProperty( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second ); + } } } } @@ -332,7 +373,7 @@ void AnimatedImageVisual::DoSetProperty( Property::Index index, } case Toolkit::ImageVisual::Property::WRAP_MODE_U: { - int wrapMode; + int wrapMode = 0; if(Scripting::GetEnumerationProperty( value, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, wrapMode )) { mWrapModeU = Dali::WrapMode::Type(wrapMode); @@ -345,7 +386,7 @@ void AnimatedImageVisual::DoSetProperty( Property::Index index, } case Toolkit::ImageVisual::Property::WRAP_MODE_V: { - int wrapMode; + int wrapMode = 0; if(Scripting::GetEnumerationProperty( value, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, wrapMode )) { mWrapModeV = Dali::WrapMode::Type(wrapMode); @@ -396,6 +437,16 @@ void AnimatedImageVisual::DoSetProperty( Property::Index index, } 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 ); + } + break; + } } } @@ -442,7 +493,7 @@ void AnimatedImageVisual::CreateRenderer() { bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE; bool atlasing = false; - Shader shader = ImageVisual::GetImageShader( mFactoryCache, atlasing, defaultWrapMode ); + Shader shader = mImageVisualShaderFactory.GetShader( mFactoryCache, atlasing, defaultWrapMode, IsRoundedCornerRequired() ); Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); @@ -516,7 +567,7 @@ void AnimatedImageVisual::LoadFirstBatch() if (!mImageCache) { - DALI_LOG_ERROR("mImageCache is null"); + DALI_LOG_ERROR("mImageCache is null\n"); } } @@ -525,7 +576,10 @@ void AnimatedImageVisual::StartFirstFrame( TextureSet& textureSet ) DALI_LOG_INFO(gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::StartFirstFrame()\n"); mStartFirstFrame = false; - mImpl->mRenderer.SetTextures( textureSet ); + if(mImpl->mRenderer) + { + mImpl->mRenderer.SetTextures( textureSet ); + } Actor actor = mPlacementActor.GetHandle(); if( actor ) { @@ -592,51 +646,84 @@ void AnimatedImageVisual::FrameReady( TextureSet textureSet ) } else { - mImpl->mRenderer.SetTextures( textureSet ); + if(mImpl->mRenderer) + { + mImpl->mRenderer.SetTextures( textureSet ); + } } } bool AnimatedImageVisual::DisplayNextFrame() { - if( mActionStatus == DevelAnimatedImageVisual::Action::STOP || mActionStatus == DevelAnimatedImageVisual::Action::PAUSE ) + if( mIsJumpTo ) + { + mIsJumpTo = false; + } + else if( mActionStatus == DevelAnimatedImageVisual::Action::PAUSE ) { return false; } - if( mFrameCount > 1 ) + else if( mActionStatus == DevelAnimatedImageVisual::Action::STOP ) { - // Wrap the frame index - ++mCurrentFrameIndex; - - if( mLoopCount < 0 || mCurrentLoopIndex <= mLoopCount) + mCurrentLoopIndex = 0; + if( mStopBehavior == DevelImageVisual::StopBehavior::FIRST_FRAME ) { - mCurrentFrameIndex %= mFrameCount; - if( mCurrentFrameIndex == 0 ) - { - ++mCurrentLoopIndex; - } + mCurrentFrameIndex = 0; + } + else if( mStopBehavior == DevelImageVisual::StopBehavior::LAST_FRAME ) + { + mCurrentFrameIndex = mFrameCount - 1; } else { - // This will stop timer - return false; + return false; // Do not draw already rendered scene twice. } } - DALI_LOG_INFO( gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::DisplayNextFrame(this:%p) FrameCount:%d\n", this, mCurrentFrameIndex); - - if( mFrameDelayContainer.Count() > 0 ) + else { - unsigned int delay = mFrameDelayContainer[mCurrentFrameIndex]; + if( mFrameCount > 1 ) + { + // Wrap the frame index + bool finished = false; + ++mCurrentFrameIndex; + if( mCurrentFrameIndex >= mFrameCount ) + { + ++mCurrentLoopIndex; + finished = true; + } - if( mFrameDelayTimer.GetInterval() != delay ) + if( mLoopCount < 0 || mCurrentLoopIndex < mLoopCount) + { + if( finished ) + { + mCurrentFrameIndex = 0; // Back to the first frame + } + } + else + { + // This will stop timer + mActionStatus = DevelAnimatedImageVisual::Action::STOP; + return DisplayNextFrame(); + } + } + + if( mFrameDelayContainer.Count() > 0 ) { - mFrameDelayTimer.SetInterval( delay ); + unsigned int delay = mFrameDelayContainer[mCurrentFrameIndex]; + + if( mFrameDelayTimer.GetInterval() != delay ) + { + mFrameDelayTimer.SetInterval( delay ); + } } } + DALI_LOG_INFO( gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::DisplayNextFrame(this:%p) CurrentFrameIndex:%d\n", this, mCurrentFrameIndex); + TextureSet textureSet; if( mImageCache ) { - textureSet = mImageCache->NextFrame(); + textureSet = mImageCache->Frame( mCurrentFrameIndex ); if( textureSet ) { SetImageSize( textureSet ); @@ -644,8 +731,7 @@ bool AnimatedImageVisual::DisplayNextFrame() } } - // Keep timer ticking - return true; + return ( mActionStatus == DevelAnimatedImageVisual::Action::PLAY ) ? true : false; }