(Vector) Support marker 95/220095/2
authorHeeyong Song <heeyong.song@samsung.com>
Fri, 13 Dec 2019 05:16:06 +0000 (14:16 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Mon, 16 Dec 2019 01:21:36 +0000 (10:21 +0900)
Change-Id: I0962a3c144d34374352c9759933448df07d00b8e

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.h [new file with mode: 0755]
automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp
dali-toolkit/devel-api/visuals/image-visual-properties-devel.h
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h

index b039c57..cf52774 100755 (executable)
@@ -18,6 +18,7 @@
 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
 #include <dali/public-api/object/base-object.h>
 #include <toolkit-application.h>
+#include <toolkit-vector-animation-renderer.h>
 
 namespace Dali
 {
@@ -94,7 +95,7 @@ public:
 
   uint32_t GetTotalFrameNumber() const
   {
-    return 5;
+    return VECTOR_ANIMATION_TOTAL_FRAME_NUMBER;
   }
 
   float GetFrameRate() const
@@ -108,6 +109,25 @@ public:
     height = 100;
   }
 
+  bool GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
+  {
+    if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_1 ) == 0 )
+    {
+      startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_1;
+      endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_1;
+    }
+    else if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_2 ) == 0 )
+    {
+      startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_2;
+      endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_2;
+    }
+    else
+    {
+      return false;
+    }
+    return true;
+  }
+
   Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
   {
     return mUploadCompletedSignal;
@@ -220,6 +240,11 @@ void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
 {
 }
 
+bool VectorAnimationRenderer::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
+{
+  return Internal::Adaptor::GetImplementation( *this ).GetMarkerInfo( marker, startFrame, endFrame );
+}
+
 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
 {
   return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.h
new file mode 100755 (executable)
index 0000000..670c5ca
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef DALI_TOOLKIT_TEST_VECTOR_ANIMATION_RENDERER_H
+#define DALI_TOOLKIT_TEST_VECTOR_ANIMATION_RENDERER_H
+
+/*
+ * Copyright (c) 2019 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 Test
+{
+
+#define VECTOR_ANIMATION_TOTAL_FRAME_NUMBER 5
+#define VECTOR_ANIMATION_MARKER_NAME_1 "marker1"
+#define VECTOR_ANIMATION_MARKER_NAME_2 "marker2"
+#define VECTOR_ANIMATION_MARKER_START_FRAME_1 0
+#define VECTOR_ANIMATION_MARKER_END_FRAME_1 2
+#define VECTOR_ANIMATION_MARKER_START_FRAME_2 2
+#define VECTOR_ANIMATION_MARKER_END_FRAME_2 3
+
+} // Test
+
+
+#endif // DALI_TOOLKIT_TEST_VECTOR_ANIMATION_RENDERER_H
index 9f4ac84..1fe89ea 100644 (file)
@@ -21,6 +21,7 @@
 #include <dali-toolkit-test-suite-utils.h>
 #include <toolkit-timer.h>
 #include <toolkit-event-thread-callback.h>
+#include <toolkit-vector-animation-renderer.h>
 #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>
@@ -688,6 +689,100 @@ int UtcDaliAnimatedVectorImageVisualPlayRange(void)
   END_TEST;
 }
 
+int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliAnimatedVectorImageVisualPlayRangeMarker" );
+
+  Property::Array array;
+  array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
+
+  Property::Map propertyMap;
+  propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
+             .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  )
+             .Add( DevelImageVisual::Property::PLAY_RANGE, array  );
+
+  Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+  DALI_TEST_CHECK( visual );
+
+  DummyControl actor = DummyControl::New( true );
+  DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+
+  Vector2 controlSize( 20.f, 30.f );
+  actor.SetSize( controlSize );
+
+  Stage::GetCurrent().Add( actor );
+
+  Property::Map attributes;
+  DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+  application.SendNotification();
+  application.Render();
+
+  // renderer is added to actor
+  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  Renderer renderer = actor.GetRendererAt( 0u );
+  DALI_TEST_CHECK( renderer );
+
+  Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+  Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
+
+  int resultStartFrame, resultEndFrame;
+  Property::Array* result = value->GetArray();
+  result->GetElementAt( 0 ).Get( resultStartFrame );
+  result->GetElementAt( 1 ).Get( resultEndFrame );
+
+  DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );
+  DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION );
+
+  // Set 2 markers
+  array.Clear();
+  array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
+  array.PushBack( VECTOR_ANIMATION_MARKER_NAME_2 );
+
+  attributes.Clear();
+  attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
+  DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+  application.SendNotification();
+  application.Render();
+
+  map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+  value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
+
+  result = value->GetArray();
+  result->GetElementAt( 0 ).Get( resultStartFrame );
+  result->GetElementAt( 1 ).Get( resultEndFrame );
+
+  DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );
+  DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION );
+
+  // Set invalid play range
+  array.Clear();
+  array.PushBack( 1 );
+  array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
+
+  attributes.Clear();
+  attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
+  DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+  application.SendNotification();
+  application.Render();
+
+  map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+  value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
+
+  result = value->GetArray();
+  result->GetElementAt( 0 ).Get( resultStartFrame );
+  result->GetElementAt( 1 ).Get( resultEndFrame );
+
+  DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );  // Should not be changed
+  DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
 {
   ToolkitTestApplication application;
index 1c54511..5419799 100644 (file)
@@ -86,11 +86,16 @@ enum Type
   /**
    * @brief The playing range the AnimatedVectorImageVisual will use.
    *
-   * Animation will play between the values specified. The array can only have two values, and more will be ignored.
+   * Animation will play between the values specified. The array can have two integer values.
+   * Or it can have one or two strings, which are markers. More will be ignored.
    * Both values should be between 0 and the total frame number, otherwise they will be ignored.
    * If the range provided is not in proper order ( minimum, maximum ), it will be reordered.
    *
-   * @details Name "playRange", Type Property::ARRAY of Property::INTEGER
+   * A marker has its start frame and end frame.
+   * Animation will play between the start frame and the end frame of the marker if one marker is specified.
+   * Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified.
+   *
+   * @details Name "playRange", Type Property::ARRAY of Property::INTEGER or Property::ARRAY of Property::STRING.
    * @note Default 0 and the total frame number.
    */
   PLAY_RANGE = ORIENTATION_CORRECTION + 4,
index 122d407..d4de346 100644 (file)
@@ -100,10 +100,9 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factor
   mImageVisualShaderFactory( shaderFactory ),
   mVisualSize(),
   mVisualScale( Vector2::ONE ),
+  mPlayRange(),
   mPlacementActor(),
   mLoopCount( LOOP_FOREVER ),
-  mStartFrame( 0 ),
-  mEndFrame( 0 ),
   mResendFlag( 0 ),
   mActionStatus( DevelAnimatedVectorImageVisual::Action::STOP ),
   mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ),
@@ -226,25 +225,8 @@ void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Prop
       Property::Array* array = value.GetArray();
       if( array )
       {
-        size_t count = array->Count();
-        if( count >= 2 )
-        {
-          int startFrame, endFrame;
-          int totalFrame = mVectorAnimationTask->GetTotalFrameNumber();
-          array->GetElementAt( 0 ).Get( startFrame );
-          array->GetElementAt( 1 ).Get( endFrame );
-
-          if( startFrame >= 0 && startFrame < totalFrame && endFrame >= 0 && endFrame < totalFrame )
-          {
-            mStartFrame = startFrame;
-            mEndFrame = endFrame;
-            mResendFlag |= RESEND_PLAY_RANGE;
-          }
-          else
-          {
-            DALI_LOG_ERROR( "Invalid play range [%d, %d / %d]\n", startFrame, endFrame, totalFrame );
-          }
-        }
+        mPlayRange = *array;
+        mResendFlag |= RESEND_PLAY_RANGE;
       }
       break;
     }
@@ -509,7 +491,7 @@ void AnimatedVectorImageVisual::SendAnimationData()
 
     if( mResendFlag & RESEND_PLAY_RANGE )
     {
-      mVectorAnimationTask->SetPlayRange( mStartFrame, mEndFrame );
+      mVectorAnimationTask->SetPlayRange( mPlayRange );
     }
 
     if( mResendFlag & RESEND_STOP_BEHAVIOR )
index 9143299..0ff2cdd 100644 (file)
@@ -206,10 +206,9 @@ private:
   PropertyNotification                         mSizeNotification;
   Vector2                                      mVisualSize;
   Vector2                                      mVisualScale;
+  Property::Array                              mPlayRange;
   WeakHandle< Actor >                          mPlacementActor;
   int32_t                                      mLoopCount;
-  uint32_t                                     mStartFrame;
-  uint32_t                                     mEndFrame;
   uint32_t                                     mResendFlag;
   DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
   DevelImageVisual::StopBehavior::Type         mStopBehavior;
index 8258fb7..213051f 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/object/property-array.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
@@ -201,10 +202,60 @@ void VectorAnimationTask::SetLoopCount( int32_t count )
   }
 }
 
-void VectorAnimationTask::SetPlayRange( uint32_t startFrame, uint32_t endFrame )
+void VectorAnimationTask::SetPlayRange( Property::Array& playRange )
 {
+  ConditionalWait::ScopedLock lock( mConditionalWait );
+
+  bool valid = false;
+  uint32_t startFrame = 0, endFrame = 0;
+  size_t count = playRange.Count();
+
+  if( count >= 2 )
+  {
+    int32_t start = 0, end = 0;
+    if( playRange.GetElementAt( 0 ).Get( start ) && playRange.GetElementAt( 1 ).Get( end ) )
+    {
+      startFrame = static_cast< uint32_t >( start );
+      endFrame = static_cast< uint32_t >( end );
+      valid = true;
+    }
+    else
+    {
+      std::string startMarker, endMarker;
+      if( playRange.GetElementAt( 0 ).Get( startMarker ) && playRange.GetElementAt( 1 ).Get( endMarker ) )
+      {
+        if( mVectorRenderer )
+        {
+          uint32_t frame;   // We don't use this later
+          if( mVectorRenderer.GetMarkerInfo( startMarker, startFrame, frame ) && mVectorRenderer.GetMarkerInfo( endMarker, frame, endFrame ) )
+          {
+            valid = true;
+          }
+        }
+      }
+    }
+  }
+  else if( count == 1 )
+  {
+    std::string marker;
+    if( playRange.GetElementAt( 0 ).Get( marker ) )
+    {
+      if( mVectorRenderer )
+      {
+        mVectorRenderer.GetMarkerInfo( marker, startFrame, endFrame );
+        valid = true;
+      }
+    }
+  }
+
+  if( !valid )
+  {
+    DALI_LOG_ERROR( "VectorAnimationTask::SetPlayRange: Invalid range [%p]\n", this );
+    return;
+  }
+
   // Make sure the range specified is between 0 and the total frame number
-  if( ( startFrame < mTotalFrame ) && ( endFrame < mTotalFrame ) )
+  if( startFrame >= 0 && startFrame < mTotalFrame && endFrame >= 0 && endFrame < mTotalFrame )
   {
     // If the range is not in order swap values
     if( startFrame > endFrame )
@@ -216,8 +267,6 @@ void VectorAnimationTask::SetPlayRange( uint32_t startFrame, uint32_t endFrame )
 
     if( startFrame != mStartFrame || endFrame != mEndFrame )
     {
-      ConditionalWait::ScopedLock lock( mConditionalWait );
-
       mStartFrame = startFrame;
       mEndFrame = endFrame;
 
@@ -240,6 +289,11 @@ void VectorAnimationTask::SetPlayRange( uint32_t startFrame, uint32_t endFrame )
       DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetPlayRange: [%d, %d] [%p]\n", mStartFrame, mEndFrame, this );
     }
   }
+  else
+  {
+    DALI_LOG_ERROR( "VectorAnimationTask::SetPlayRange: Invalid range (%d, %d) [%p]\n", startFrame, endFrame, this );
+    return;
+  }
 }
 
 void VectorAnimationTask::GetPlayRange( uint32_t& startFrame, uint32_t& endFrame )
index a16faea..f2e3042 100644 (file)
@@ -117,11 +117,10 @@ public:
 
   /**
    * @brief Set the playing range in frame number.
-   * @param[in] startFrame The frame number to specify minimum progress.
-   * @param[in] endFrame The frame number to specify maximum progress.
+   * @param[in] playRange The array to specify minimum and maximum progress.
    * The animation will play between those values.
    */
-  void SetPlayRange( uint32_t startFrame, uint32_t endFrame );
+  void SetPlayRange( Property::Array& playRange );
 
   /**
    * @brief Gets the playing range in frame number.