(Vector) Flush lottie update informations
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-animation-task.h
index 1e4ff4c..fdf1e2c 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_VECTOR_ANIMATION_TASK_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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/devel-api/adaptor-framework/event-thread-callback.h>
 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
 #include <dali/devel-api/threading/conditional-wait.h>
+#include <dali/public-api/adaptor-framework/async-task-manager.h>
+#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/property-array.h>
 #include <chrono>
 #include <memory>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
 
 namespace Dali
@@ -42,7 +45,7 @@ typedef IntrusivePtr<VectorAnimationTask> VectorAnimationTaskPtr;
 /**
  * The task of the vector animation.
  */
-class VectorAnimationTask : public RefObject, public ConnectionTracker
+class VectorAnimationTask : public AsyncTask, public ConnectionTracker
 {
 public:
   enum class ResourceStatus
@@ -54,7 +57,8 @@ public:
 
   using ResourceReadySignalType = Signal<void(ResourceStatus)>;
 
-  using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
+  using TimePoint           = std::chrono::time_point<std::chrono::steady_clock>;
+  using DynamicPropertyType = std::vector<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>;
 
   /**
    * Flags for re-sending data to the vector animation thread
@@ -68,7 +72,8 @@ public:
     RESEND_CURRENT_FRAME       = 1 << 4,
     RESEND_SIZE                = 1 << 5,
     RESEND_PLAY_STATE          = 1 << 6,
-    RESEND_NEED_RESOURCE_READY = 1 << 7
+    RESEND_NEED_RESOURCE_READY = 1 << 7,
+    RESEND_DYNAMIC_PROPERTY    = 1 << 8
   };
 
   /**
@@ -79,6 +84,7 @@ public:
     AnimationData()
     : resendFlag(0),
       playRange(),
+      dynamicProperties(),
       playState(),
       stopBehavior(DevelImageVisual::StopBehavior::CURRENT_FRAME),
       loopingMode(DevelImageVisual::LoopingMode::RESTART),
@@ -100,11 +106,13 @@ public:
       width        = rhs.width;
       height       = rhs.height;
       loopCount    = rhs.loopCount;
+      dynamicProperties.insert(dynamicProperties.end(), rhs.dynamicProperties.begin(), rhs.dynamicProperties.end());
       return *this;
     }
 
     uint32_t                             resendFlag;
     Property::Array                      playRange;
+    DynamicPropertyType                  dynamicProperties;
     DevelImageVisual::PlayState::Type    playState;
     DevelImageVisual::StopBehavior::Type stopBehavior;
     DevelImageVisual::LoopingMode::Type  loopingMode;
@@ -127,6 +135,17 @@ public:
   ~VectorAnimationTask() override;
 
   /**
+   * Process the task accodring to the type
+   */
+  void Process() override;
+
+  /**
+   * Whether the task is ready to process.
+   * @return True if the task is ready to process.
+   */
+  bool IsReady() override;
+
+  /**
    * @brief Finalizes the task.
    */
   void Finalize();
@@ -139,11 +158,18 @@ public:
   void SetRenderer(Renderer renderer);
 
   /**
-   * @brief Request to load the animation file.
+   * @brief Requests to load the animation file.
    *
    * @param[in] url The url of the vector animation file
+   * @param[in] synchronousLoading True if the url should be loaded synchronously
    */
-  void RequestLoad(const std::string& url);
+  void RequestLoad(const std::string& url, bool synchronousLoading);
+
+  /**
+   * @brief Queries whether loading is requested.
+   * @return True if loading is requested.
+   */
+  bool IsLoadRequested() const;
 
   /**
    * @brief Sets data to specify animation playback.
@@ -155,7 +181,7 @@ public:
    * @brief This callback is called after the animation is finished.
    * @param[in] callback The animation finished callback
    */
-  void SetAnimationFinishedCallback(EventThreadCallback* callback);
+  void SetAnimationFinishedCallback(CallbackBase* callback);
 
   /**
    * @brief Gets the playing range in frame number.
@@ -196,10 +222,9 @@ public:
 
   /**
    * @brief Rasterizes the current frame.
-   * @param[out] keepAnimation true if the animation is running, false otherwise.
    * @return true if the rasterization succeeded, false otherwise.
    */
-  bool Rasterize(bool& keepAnimation);
+  bool Rasterize();
 
   /**
    * @brief Calculates the time for the next frame rasterization.
@@ -213,13 +238,32 @@ public:
    */
   TimePoint GetNextFrameTime();
 
+  /**
+   * @brief Called when the rasterization is completed from the asyncTaskManager
+   * @param[in] task The completed task
+   */
+  void TaskCompleted(VectorAnimationTaskPtr task);
+
+  /**
+   * @brief Check the rasterization succeeded
+   * @return true if the rasterization succeeded, false otherwise.
+   */
+  bool IsRasterized();
+
+  /**
+   * @brief Check the animation is running
+   * @return true if the animation is running, false otherwise.
+   */
+  bool IsAnimating();
+
 private:
   /**
    * @brief Loads the animation file.
    *
+   * @param[in] synchronousLoading True if loading is requested synchronously
    * @return True if loading succeeded, false otherwise.
    */
-  bool Load();
+  bool Load(bool synchronousLoading);
 
   /**
    * @brief Play the vector animation.
@@ -313,12 +357,12 @@ private:
 
   std::string                          mUrl;
   VectorAnimationRenderer              mVectorRenderer;
-  AnimationData                        mAnimationData[2];
+  std::vector<AnimationData>           mAnimationData[2];
   VectorAnimationThread&               mVectorAnimationThread;
   ConditionalWait                      mConditionalWait;
   ResourceReadySignalType              mResourceReadySignal;
-  std::unique_ptr<EventThreadCallback> mAnimationFinishedTrigger;
-  std::unique_ptr<EventThreadCallback> mLoadCompletedTrigger;
+  std::unique_ptr<CallbackBase>        mAnimationFinishedCallback{};
+  std::unique_ptr<CallbackBase>        mLoadCompletedCallback{};
   PlayState                            mPlayState;
   DevelImageVisual::StopBehavior::Type mStopBehavior;
   DevelImageVisual::LoopingMode::Type  mLoopingMode;
@@ -342,6 +386,8 @@ private:
   bool                                 mDestroyTask;
   bool                                 mLoadRequest;
   bool                                 mLoadFailed;
+  bool                                 mRasterized;
+  bool                                 mKeepAnimation;
 };
 
 } // namespace Internal