/*
- * 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.
#include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
#include <dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h>
#include <dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h>
-#include <dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.h>
+#include <dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h>
#include <dali-toolkit/devel-api/image-loader/image-atlas.h>
#include <dali-toolkit/devel-api/image-loader/texture-manager.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
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 )
* | new cache
* | cache->LoadBatch()
* |
- * | DoSetOnStage()
+ * | DoSetOnScene()
* | PrepareTextureSet()
* | cache->FirstFrame()
* | CreateRenderer() (Doesn't become ready until first frame loads)
AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties )
{
AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache, shaderFactory ) );
- visual->InitializeGif( imageUrl );
+ visual->InitializeAnimatedImage( imageUrl );
visual->SetProperties( properties );
if( visual->mFrameCount > 0 )
AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl )
{
AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache, shaderFactory ) );
- visual->InitializeGif( imageUrl );
+ visual->InitializeAnimatedImage( imageUrl );
if( visual->mFrameCount > 0 )
{
return visual;
}
-void AnimatedImageVisual::InitializeGif( const VisualUrl& imageUrl )
+void AnimatedImageVisual::InitializeAnimatedImage( const VisualUrl& imageUrl )
{
mImageUrl = imageUrl;
- mGifLoading = GifLoading::New( imageUrl.GetUrl(), imageUrl.IsLocalResource() );
- mFrameCount = mGifLoading->GetImageCount();
- mGifLoading->LoadFrameDelays( mFrameDelayContainer );
+ mAnimatedImageLoading = AnimatedImageLoading::New( imageUrl.GetUrl(), imageUrl.IsLocalResource() );
+ mFrameCount = mAnimatedImageLoading.GetImageCount();
}
AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory )
-: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::ANIMATED_IMAGE ),
mFrameDelayTimer(),
mPlacementActor(),
mImageVisualShaderFactory( shaderFactory ),
mPixelArea( FULL_TEXTURE_RECT ),
mImageUrl(),
- mGifLoading( nullptr ),
- mCurrentFrameIndex( 0 ),
+ mAnimatedImageLoading(),
+ mFrameIndexForJumpTo( 0 ),
mImageUrls( NULL ),
mImageCache( NULL ),
- mCacheSize( 1 ),
- mBatchSize( 1 ),
+ mCacheSize( 2 ),
+ mBatchSize( 2 ),
mFrameDelay( 100 ),
mLoopCount( LOOP_FOREVER ),
mCurrentLoopIndex( 0 ),
mWrapModeU( WrapMode::DEFAULT ),
mWrapModeV( WrapMode::DEFAULT ),
mActionStatus( DevelAnimatedImageVisual::Action::PLAY ),
- mStartFirstFrame(false)
+ mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ),
+ mStartFirstFrame(false),
+ mIsJumpTo( false )
{}
AnimatedImageVisual::~AnimatedImageVisual()
{
if( mImageUrl.IsValid() )
{
- mImageSize = mGifLoading->GetImageSize();
+ mImageSize = mAnimatedImageLoading.GetImageSize();
}
else if( mImageUrls && mImageUrls->size() > 0 )
{
{
map.Clear();
+ bool sync = IsSynchronousLoadingRequired();
+ map.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, sync );
+
map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::ANIMATED_IMAGE );
if( mImageUrl.IsValid() )
map.Insert( Toolkit::ImageVisual::Property::CACHE_SIZE, static_cast<int>(mCacheSize) );
map.Insert( Toolkit::ImageVisual::Property::FRAME_DELAY, static_cast<int>(mFrameDelay) );
map.Insert( Toolkit::DevelImageVisual::Property::LOOP_COUNT, static_cast<int>(mLoopCount) );
+
+ map.Insert( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mStopBehavior );
}
void AnimatedImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
}
case DevelAnimatedImageVisual::Action::PLAY:
{
- if( IsOnStage() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY )
+ if( mFrameDelayTimer && IsOnScene() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY )
{
mFrameDelayTimer.Start();
}
{
// 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( IsOnScene() )
+ {
+ DisplayNextFrame();
+ }
+ break;
+ }
+ case DevelAnimatedImageVisual::Action::JUMP_TO:
+ {
+ int32_t frameNumber;
+ if( attributes.Get( frameNumber ) )
+ {
+ if( frameNumber < 0 || frameNumber >= static_cast<int32_t>( mFrameCount ) )
+ {
+ DALI_LOG_ERROR( "Invalid frame index used.\n" );
+ }
+ else
+ {
+ mIsJumpTo = true;
+ mFrameIndexForJumpTo = frameNumber;
+ if( IsOnScene() )
+ {
+ DisplayNextFrame();
+ }
+ }
+ }
break;
}
}
{
DoSetProperty( Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second );
}
+ else if( keyValue.first == STOP_BEHAVIOR_NAME )
+ {
+ DoSetProperty( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second );
+ }
}
}
}
int batchSize;
if( value.Get( batchSize ) )
{
- mBatchSize = batchSize;
+ if( batchSize < 2 )
+ {
+ DALI_LOG_ERROR( "The minimum value of batch size is 2." );
+ }
+ else
+ {
+ mBatchSize = batchSize;
+ }
}
break;
}
int cacheSize;
if( value.Get( cacheSize ) )
{
- mCacheSize = cacheSize;
+ if( cacheSize < 2 )
+ {
+ DALI_LOG_ERROR( "The minimum value of cache size is 2." );
+ }
+ else
+ {
+ mCacheSize = cacheSize;
+ }
}
break;
}
}
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;
+ }
+
+ case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
+ {
+ bool sync = false;
+ value.Get( sync );
+ if( sync )
+ {
+ mImpl->mFlags |= Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
+ }
+ else
+ {
+ mImpl->mFlags &= ~Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
+ }
+ break;
+ }
}
}
-void AnimatedImageVisual::DoSetOnStage( Actor& actor )
+void AnimatedImageVisual::DoSetOnScene( Actor& actor )
{
mPlacementActor = actor;
TextureSet textureSet = PrepareTextureSet();
}
}
-void AnimatedImageVisual::DoSetOffStage( Actor& actor )
+void AnimatedImageVisual::DoSetOffScene( Actor& actor )
{
DALI_ASSERT_DEBUG( (bool)mImpl->mRenderer && "There should always be a renderer whilst on stage");
{
bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
bool atlasing = false;
- Shader shader = mImageVisualShaderFactory.GetShader( mFactoryCache, atlasing, defaultWrapMode );
+ Shader shader = mImageVisualShaderFactory.GetShader( mFactoryCache, atlasing, defaultWrapMode, IsRoundedCornerRequired() );
Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
{
mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea );
}
-
- mCurrentFrameIndex = 0;
}
void AnimatedImageVisual::LoadFirstBatch()
mUrlIndex = 0;
TextureManager& textureManager = mFactoryCache.GetTextureManager();
- if( mGifLoading != nullptr )
+ if( mAnimatedImageLoading )
{
- mImageCache = new RollingGifImageCache( textureManager, *mGifLoading, mFrameCount, *this, cacheSize, batchSize );
+ mImageCache = new RollingAnimatedImageCache( textureManager, mAnimatedImageLoading, mFrameCount, *this, cacheSize, batchSize, IsSynchronousLoadingRequired() );
}
else if( mImageUrls )
{
if (!mImageCache)
{
- DALI_LOG_ERROR("mImageCache is null");
+ DALI_LOG_ERROR("mImageCache is null\n");
}
}
mPlacementActor.Reset();
}
- mCurrentFrameIndex = 0;
-
if( mFrameCount > 1 )
{
int frameDelay = mFrameDelay; // from URL array
- if( mFrameDelayContainer.Count() > 0 ) // from GIF
+ if( mAnimatedImageLoading && mImageCache )
{
- frameDelay = mFrameDelayContainer[0];
+ frameDelay = mImageCache->GetFrameInterval( 0 );
}
-
mFrameDelayTimer = Timer::New( frameDelay );
mFrameDelayTimer.TickSignal().Connect( this, &AnimatedImageVisual::DisplayNextFrame );
mFrameDelayTimer.Start();
{
TextureSet textureSet;
if (mImageCache)
+ {
textureSet = mImageCache->FirstFrame();
+ }
+
if( textureSet )
{
SetImageSize( textureSet );
}
- else
- {
- DALI_LOG_INFO(gAnimImgLogFilter,Debug::Concise,"ResourceReady(ResourceStatus::FAILED)\n");
- ResourceReady( Toolkit::Visual::ResourceStatus::FAILED );
- }
return textureSet;
}
void AnimatedImageVisual::FrameReady( TextureSet textureSet )
{
- SetImageSize( textureSet );
-
- if( mStartFirstFrame )
+ if(textureSet)
{
- StartFirstFrame( textureSet );
+ SetImageSize(textureSet);
+
+ if(mStartFirstFrame)
+ {
+ StartFirstFrame(textureSet);
+ }
+ else
+ {
+ if(mImpl->mRenderer)
+ {
+ mImpl->mRenderer.SetTextures(textureSet);
+ }
+ }
}
else
{
- if(mImpl->mRenderer)
- {
- mImpl->mRenderer.SetTextures( textureSet );
- }
+ DALI_LOG_INFO( gAnimImgLogFilter, Debug::Concise, "ResourceReady(ResourceStatus::FAILED)\n" );
+ ResourceReady( Toolkit::Visual::ResourceStatus::FAILED );
}
}
bool AnimatedImageVisual::DisplayNextFrame()
{
- if( mActionStatus == DevelAnimatedImageVisual::Action::STOP || mActionStatus == DevelAnimatedImageVisual::Action::PAUSE )
+ bool nextFrame = false;
+ uint32_t frameIndex = mImageCache->GetCurrentFrameIndex();
+
+ if( mIsJumpTo )
+ {
+ mIsJumpTo = false;
+ frameIndex = mFrameIndexForJumpTo;
+ }
+ 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)
+ frameIndex = 0;
+ if( mStopBehavior == DevelImageVisual::StopBehavior::FIRST_FRAME )
{
- mCurrentFrameIndex %= mFrameCount;
- if( mCurrentFrameIndex == 0 )
- {
- ++mCurrentLoopIndex;
- }
+ frameIndex = 0;
+ }
+ else if( mStopBehavior == DevelImageVisual::StopBehavior::LAST_FRAME )
+ {
+ frameIndex = 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 )
+ {
+ nextFrame = true;
+ frameIndex++;
+ if( frameIndex >= mFrameCount )
+ {
+ frameIndex %= mFrameCount;
+ ++mCurrentLoopIndex;
+ }
- if( mFrameDelayTimer.GetInterval() != delay )
+ if(mLoopCount >= 0 && mCurrentLoopIndex >= mLoopCount)
+ {
+ // This will stop timer
+ mActionStatus = DevelAnimatedImageVisual::Action::STOP;
+ return DisplayNextFrame();
+ }
+ }
+ // TODO : newly added one.
+ if( mAnimatedImageLoading && mImageCache )
{
- mFrameDelayTimer.SetInterval( delay );
+ unsigned int delay = mImageCache->GetFrameInterval( frameIndex );
+ if( mFrameDelayTimer.GetInterval() != delay )
+ {
+ mFrameDelayTimer.SetInterval( delay );
+ }
}
}
+ DALI_LOG_INFO( gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::DisplayNextFrame(this:%p) CurrentFrameIndex:%d\n", this, frameIndex);
+
TextureSet textureSet;
if( mImageCache )
{
- textureSet = mImageCache->NextFrame();
+ if(nextFrame)
+ {
+ textureSet = mImageCache->NextFrame();
+ }
+ else
+ {
+ textureSet = mImageCache->Frame( frameIndex );
+ }
+
if( textureSet )
{
SetImageSize( textureSet );
}
}
- // Keep timer ticking
- return true;
+ return ( mActionStatus == DevelAnimatedImageVisual::Action::PLAY ) ? true : false;
}