Added playback (i.e. Play, Pause, Stop) support for the animated GIF. 10/165510/9
authorUmar <m.umar@partner.samsung.com>
Fri, 29 Dec 2017 20:29:11 +0000 (20:29 +0000)
committerUmar <m.umar@partner.samsung.com>
Mon, 8 Jan 2018 18:05:37 +0000 (18:05 +0000)
Change-Id: I21ba8d2d707fd563977126877f0c74bb73734adc

automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp
dali-toolkit/devel-api/file.list
dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h [new file with mode: 0644]
dali-toolkit/devel-api/visuals/image-visual-actions-devel.h
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.h

index 2804868b0474d71877e87dcea93eb07105ce8512..0e06386af8ea3391d15dcd279430dfdc8bb608c3 100644 (file)
@@ -24,6 +24,7 @@
 #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;
@@ -647,5 +648,79 @@ int UtcDaliAnimatedImageVisualLoopCount(void)
     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
index 812668b998c47ff24bbb596d3f442b55419632a7..03b3b6e1a18ada2d7268f66302c4da747e72b6b2 100644 (file)
@@ -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 (file)
index 0000000..b654a69
--- /dev/null
@@ -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
index f76e772dffb5d9d1eaad0ba74883bc384dd2a880..78a1451612a16f8cd96584cccda2fc7b72f8dffd 100644 (file)
@@ -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
index d37863e310dce10756aa38e82707013d16f9ef7a..d9c4cd43bcb1d6273eda850b164c3556da391227 100755 (executable)
@@ -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
index e92c5ef8ed5d033318d5df76aca7935555f90fe3..0db91546f7d2c1b223d3badf0d23149ba68e7fb4 100644 (file)
@@ -30,6 +30,7 @@
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
 #include <dali-toolkit/internal/visuals/visual-url.h>
 #include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
+#include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
 
 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;
 };