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=fcb3811501037777838531f4949b74f22a867467;hp=84ae1c920e990fa5239fa4b1dfde21eac2980474;hb=e3a661ed9b8268e1ebac5ab26088673de706c509;hpb=c20463e1d4a77117810c67adfec49bcdfab5efde 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 84ae1c9..fcb3811 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) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -57,6 +57,7 @@ DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::WrapMode, MIRRORED_REPEAT ) DALI_ENUM_TO_STRING_TABLE_END( WRAP_MODE ) const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); +constexpr auto LOOP_FOREVER = -1; #if defined(DEBUG_ENABLED) Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ANIMATED_IMAGE"); @@ -153,13 +154,13 @@ 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 ), +: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ), mFrameDelayTimer(), mPlacementActor(), mPixelArea( FULL_TEXTURE_RECT ), @@ -171,11 +172,14 @@ AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache ) mCacheSize( 1 ), mBatchSize( 1 ), mFrameDelay( 100 ), + mLoopCount( LOOP_FOREVER ), + mCurrentLoopIndex( 0 ), mUrlIndex( 0 ), mFrameCount( 0 ), mImageSize(), mWrapModeU( WrapMode::DEFAULT ), mWrapModeV( WrapMode::DEFAULT ), + mActionStatus( DevelAnimatedImageVisual::Action::PLAY ), mStartFirstFrame(false) {} @@ -231,6 +235,7 @@ void AnimatedImageVisual::DoCreatePropertyMap( Property::Map& map ) const map.Insert( Toolkit::ImageVisual::Property::BATCH_SIZE, static_cast(mBatchSize) ); 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) ); } void AnimatedImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const @@ -238,6 +243,38 @@ void AnimatedImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) cons // Do nothing } +void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, const Dali::Property::Value& attributes ) +{ + // Check if action is valid for this visual type and perform action if possible + + switch ( actionId ) + { + case DevelAnimatedImageVisual::Action::PAUSE: + { + // Pause will be executed on next timer tick + mActionStatus = DevelAnimatedImageVisual::Action::PAUSE; + break; + } + case DevelAnimatedImageVisual::Action::PLAY: + { + if( IsOnStage() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY ) + { + mFrameDelayTimer.Start(); + } + mActionStatus = DevelAnimatedImageVisual::Action::PLAY; + break; + } + case DevelAnimatedImageVisual::Action::STOP: + { + // 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; + break; + } + } +} + void AnimatedImageVisual::DoSetProperties( const Property::Map& propertyMap ) { // url[s] already passed in from constructor @@ -275,6 +312,10 @@ void AnimatedImageVisual::DoSetProperties( const Property::Map& propertyMap ) { DoSetProperty( Toolkit::ImageVisual::Property::FRAME_DELAY, keyValue.second ); } + else if( keyValue.first == LOOP_COUNT_NAME ) + { + DoSetProperty( Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second ); + } } } } @@ -291,7 +332,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); @@ -304,7 +345,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); @@ -345,6 +386,16 @@ void AnimatedImageVisual::DoSetProperty( Property::Index index, } break; } + + case Toolkit::DevelImageVisual::Property::LOOP_COUNT: + { + int loopCount; + if( value.Get( loopCount ) ) + { + mLoopCount = loopCount; + } + break; + } } } @@ -444,21 +495,25 @@ void AnimatedImageVisual::LoadFirstBatch() { mImageCache = new RollingGifImageCache( textureManager, *mGifLoading, mFrameCount, *this, cacheSize, batchSize ); } - else if( batchSize > 0 && cacheSize > 0 ) + else if( mImageUrls ) { - if( cacheSize < numUrls ) + if( batchSize > 0 && cacheSize > 0 ) { - mImageCache = new RollingImageCache( textureManager, *mImageUrls, *this, cacheSize, batchSize ); + if( cacheSize < numUrls ) + { + mImageCache = new RollingImageCache( textureManager, *mImageUrls, *this, cacheSize, batchSize ); + } + else + { + mImageCache = new FixedImageCache( textureManager, *mImageUrls, *this, batchSize ); + } } else { - mImageCache = new FixedImageCache( textureManager, *mImageUrls, *this, batchSize ); + mImageCache = new RollingImageCache( textureManager, *mImageUrls, *this, 1, 1 ); } } - else - { - mImageCache = new RollingImageCache( textureManager, *mImageUrls, *this, 1, 1 ); - } + if (!mImageCache) { DALI_LOG_ERROR("mImageCache is null"); @@ -543,11 +598,28 @@ void AnimatedImageVisual::FrameReady( TextureSet textureSet ) bool AnimatedImageVisual::DisplayNextFrame() { + if( mActionStatus == DevelAnimatedImageVisual::Action::STOP || mActionStatus == DevelAnimatedImageVisual::Action::PAUSE ) + { + return false; + } if( mFrameCount > 1 ) { // Wrap the frame index ++mCurrentFrameIndex; - mCurrentFrameIndex %= mFrameCount; + + if( mLoopCount < 0 || mCurrentLoopIndex <= mLoopCount) + { + mCurrentFrameIndex %= mFrameCount; + if( mCurrentFrameIndex == 0 ) + { + ++mCurrentLoopIndex; + } + } + else + { + // This will stop timer + return false; + } } DALI_LOG_INFO( gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::DisplayNextFrame(this:%p) FrameCount:%d\n", this, mCurrentFrameIndex); @@ -562,12 +634,14 @@ bool AnimatedImageVisual::DisplayNextFrame() } TextureSet textureSet; - if (mImageCache) - textureSet = mImageCache->NextFrame(); - if( textureSet ) + if( mImageCache ) { - SetImageSize( textureSet ); - mImpl->mRenderer.SetTextures( textureSet ); + textureSet = mImageCache->NextFrame(); + if( textureSet ) + { + SetImageSize( textureSet ); + mImpl->mRenderer.SetTextures( textureSet ); + } } // Keep timer ticking