/*
- * 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.
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
#include "dummy-control.h"
using namespace Dali;
.Add( "url", urls )
.Add( "batchSize", 4 )
.Add( "cacheSize", 8 )
+ .Add( "loopCount", 10 )
.Add( "frameDelay", 200 )
.Add( "pixelArea", Vector4() )
.Add( "wrapModeU", WrapMode::REPEAT )
DALI_TEST_CHECK( value );
DALI_TEST_EQUALS( value->Get<int>(), 8, TEST_LOCATION );
+ value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
+
value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
DALI_TEST_CHECK( value );
DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
END_TEST;
}
+
+void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
+{
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+
+ textureTrace.Enable(true);
+ Stage::GetCurrent().Add( dummyControl );
+ application.SendNotification();
+ application.Render(16);
+
+ tet_infoline( "Test that a timer has been created" );
+ DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
+
+ for ( uint16_t i = 0; i <= loopCount; i++ )
+ {
+ for ( uint16_t j = 0; j < frameCount; j++ )
+ {
+ tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_INNER_LOCATION( location ) );
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
+ }
+ tet_printf( "\nTest Loop %u \n", i );
+ }
+
+ tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
+
+ dummyControl.Unparent();
+}
+
+int UtcDaliAnimatedImageVisualLoopCount(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
+
+ {
+ // request AnimatedImageVisual with a property map
+ // Test with no (0) loop count
+ VisualFactory factory = VisualFactory::Get();
+ Visual::Base animatedImageVisual = factory.CreateVisual(
+ Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
+ .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
+ .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
+ .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
+
+ DummyControl dummyControl = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
+ dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
+ TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
+
+ // Test with no (1) loop count. Request AnimatedImageVisual with a property map
+ animatedImageVisual = factory.CreateVisual(
+ Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
+ .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
+ .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
+ .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
+
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
+
+ TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
+
+ // Test with no (100) loop count. Request AnimatedImageVisual with a property map
+ animatedImageVisual = factory.CreateVisual(
+ Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
+ .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
+ .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
+ .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
+
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
+
+ TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
+int UtcDaliAnimatedImageVisualPlayback(void)
+{
+ ToolkitTestApplication application;
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+
+ tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
+
+ {
+ // request AnimatedImageVisual with a property map
+ // Test with forever (-1) loop count
+ VisualFactory factory = VisualFactory::Get();
+ Visual::Base animatedImageVisual = factory.CreateVisual(
+ Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
+ .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
+ .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
+ .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
+
+ DummyControl dummyControl = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
+ dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
+ textureTrace.Enable(true);
+ Stage::GetCurrent().Add( dummyControl );
+ application.SendNotification();
+ application.Render(16);
+
+ tet_infoline( "Test that a timer has been created" );
+ DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
+
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
+
+ Property::Map attributes;
+ tet_infoline( "Test Pause action. Timer should stop after Pause action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
+
+ tet_infoline( "Test Play action. Timer should Restart after Play action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
+
+ tet_infoline( "Test Stop action. Timer should stop after Stop action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
+
+ tet_infoline( "Test Play action. Timer should Restart after Play action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
+
+ dummyControl.Unparent();
+ }
+
+ END_TEST;
+}
\ No newline at end of file
/*
- * 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.
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");
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)
{}
map.Insert( Toolkit::ImageVisual::Property::BATCH_SIZE, static_cast<int>(mBatchSize) );
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) );
}
void AnimatedImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
// 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
{
DoSetProperty( Toolkit::ImageVisual::Property::FRAME_DELAY, keyValue.second );
}
+ else if( keyValue.first == LOOP_COUNT_NAME )
+ {
+ DoSetProperty( Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second );
+ }
}
}
}
}
break;
}
+
+ case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
+ {
+ int loopCount;
+ if( value.Get( loopCount ) )
+ {
+ mLoopCount = loopCount;
+ }
+ break;
+ }
}
}
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);
}
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