From: Umar Date: Fri, 29 Dec 2017 20:29:11 +0000 (+0000) Subject: Added playback (i.e. Play, Pause, Stop) support for the animated GIF. X-Git-Tag: dali_1.3.7~7 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=4755bc6d25adef606b8f29f1145ffd866a0fbfe9 Added playback (i.e. Play, Pause, Stop) support for the animated GIF. Change-Id: I21ba8d2d707fd563977126877f0c74bb73734adc --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp index 2804868..0e06386 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "dummy-control.h" using namespace Dali; @@ -648,4 +649,78 @@ int UtcDaliAnimatedImageVisualLoopCount(void) } 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(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 diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index 812668b..03b3b6e 100644 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -92,6 +92,7 @@ devel_api_visual_factory_header_files = \ devel_api_visuals_header_files = \ $(devel_api_src_dir)/visuals/animated-gradient-visual-properties-devel.h \ + $(devel_api_src_dir)/visuals/animated-image-visual-actions-devel.h \ $(devel_api_src_dir)/visuals/color-visual-properties-devel.h \ $(devel_api_src_dir)/visuals/image-visual-properties-devel.h \ $(devel_api_src_dir)/visuals/image-visual-actions-devel.h \ diff --git a/dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h b/dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h new file mode 100644 index 0000000..b654a69 --- /dev/null +++ b/dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h @@ -0,0 +1,53 @@ +#ifndef DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_IMAGE_VISUAL_ACTIONS_DEVEL_H +#define DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_IMAGE_VISUAL_ACTIONS_DEVEL_H + +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Dali +{ + +namespace Toolkit +{ + +namespace DevelAnimatedImageVisual +{ + +/** + * @brief Actions that the animated image visual can perform. These actions are called through the Visual::Base::DoAction API. + */ +namespace Action +{ +/** + * @brief The available actions for this visual + */ +enum Type +{ + PLAY, ///< Play the animated GIF. This is also Default playback mode. + PAUSE, ///< Pause the animated GIF. + STOP ///< Stop the animated GIF. +}; + +} // namespace Action + +} // namespace DevelAnimatedImageVisual + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_IMAGE_VISUAL_ACTIONS_DEVEL_H diff --git a/dali-toolkit/devel-api/visuals/image-visual-actions-devel.h b/dali-toolkit/devel-api/visuals/image-visual-actions-devel.h index f76e772..78a1451 100644 --- a/dali-toolkit/devel-api/visuals/image-visual-actions-devel.h +++ b/dali-toolkit/devel-api/visuals/image-visual-actions-devel.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_DEVEL_API_VISUALS_IMAGE_VISUAL_ACTIONS_DEVEL_H /* - * 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. @@ -37,7 +37,7 @@ namespace Action */ enum Type { - RELOAD = 0, ///< Force reloading of the image, all visuals using this image will get the latest one. + RELOAD = 0 ///< Force reloading of the image, all visuals using this image will get the latest one. }; } // namespace Actions 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 d37863e..d9c4cd4 100755 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -179,6 +179,7 @@ AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache ) mImageSize(), mWrapModeU( WrapMode::DEFAULT ), mWrapModeV( WrapMode::DEFAULT ), + mActionStatus( DevelAnimatedImageVisual::Action::PLAY ), mStartFirstFrame(false) {} @@ -242,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 @@ -561,6 +594,10 @@ 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 @@ -593,12 +630,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 diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h index e92c5ef..0db9154 100644 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace Dali { @@ -130,6 +131,11 @@ public: // from Visual */ virtual void DoCreateInstancePropertyMap( Property::Map& map ) const; + /** + * @copydoc Visual::Base::OnDoAction + */ + virtual void OnDoAction( const Dali::Property::Index actionName, const Dali::Property::Value& attributes ) override; + protected: /** @@ -252,6 +258,7 @@ private: Dali::WrapMode::Type mWrapModeU:3; Dali::WrapMode::Type mWrapModeV:3; + DevelAnimatedImageVisual::Action::Type mActionStatus:2; bool mStartFirstFrame:1; };