/*
- * 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 "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;
+}
\ 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(),
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
{
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;
+ }
}
}
{
// 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);