[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-animation-thread.h
index a5108d5..8b820cc 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -19,6 +19,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/threading/conditional-wait.h>
+#include <dali/devel-api/threading/mutex.h>
 #include <dali/devel-api/threading/thread.h>
 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
 #include <dali/integration-api/adaptor-framework/trace-factory-interface.h>
@@ -76,10 +77,11 @@ public:
    * @brief Add an event trigger callback.
    *
    * @param callback The callback to add
+   * @param argument The argument to pass to the callback
    * @note Ownership of the callback is NOT passed onto this class.
    * @note The callback will be excuted in the main thread.
    */
-  void AddEventTriggerCallback(CallbackBase* callback);
+  void AddEventTriggerCallback(CallbackBase* callback, uint32_t argument);
 
   /**
    * @brief Remove event trigger callbacks what we added before.
@@ -88,6 +90,11 @@ public:
    */
   void RemoveEventTriggerCallbacks(CallbackBase* callback);
 
+  /**
+   * @brief Request to event callback from rasterize thread. This is called when we want to ensure rendering next frame.
+   */
+  void RequestForceRenderOnce();
+
 protected:
   /**
    * @brief The entry function of the animation thread.
@@ -108,7 +115,7 @@ private:
   /**
    * @brief Gets next event callback to process.
    */
-  CallbackBase* GetNextEventCallback();
+  std::pair<CallbackBase*, uint32_t> GetNextEventCallback();
 
   /**
    * @brief The thread to sleep until the next frame time.
@@ -147,8 +154,9 @@ private:
     std::chrono::time_point<std::chrono::steady_clock> mSleepTimePoint;
     const Dali::LogFactoryInterface&                   mLogFactory;
     const Dali::TraceFactoryInterface&                 mTraceFactory;
-    bool                                               mNeedToSleep;
-    bool                                               mDestroyThread;
+
+    bool mNeedToSleep : 1;
+    bool mDestroyThread : 1;
   };
 
 private:
@@ -159,19 +167,22 @@ private:
   VectorAnimationThread& operator=(const VectorAnimationThread& thread) = delete;
 
 private:
-  std::vector<VectorAnimationTaskPtr>  mAnimationTasks;
-  std::vector<VectorAnimationTaskPtr>  mCompletedTasks;
-  std::vector<VectorAnimationTaskPtr>  mWorkingTasks;
-  std::vector<CallbackBase*>           mTriggerEventCallbacks{}; // Callbacks are not owned
-  SleepThread                          mSleepThread;
-  ConditionalWait                      mConditionalWait;
-  std::unique_ptr<EventThreadCallback> mEventTrigger{};
-  bool                                 mNeedToSleep;
-  bool                                 mDestroyThread;
-  bool                                 mEventTriggered{false};
-  const Dali::LogFactoryInterface&     mLogFactory;
-  const Dali::TraceFactoryInterface&   mTraceFactory;
-  Dali::AsyncTaskManager               mAsyncTaskManager;
+  std::vector<VectorAnimationTaskPtr>             mAnimationTasks;
+  std::vector<VectorAnimationTaskPtr>             mCompletedTasks;
+  std::vector<VectorAnimationTaskPtr>             mWorkingTasks;
+  std::vector<std::pair<CallbackBase*, uint32_t>> mTriggerEventCallbacks{}; // Callbacks are not owned
+  SleepThread                                     mSleepThread;
+  ConditionalWait                                 mConditionalWait;
+  Mutex                                           mEventTriggerMutex;
+  std::unique_ptr<EventThreadCallback>            mEventTrigger{};
+  const Dali::LogFactoryInterface&                mLogFactory;
+  const Dali::TraceFactoryInterface&              mTraceFactory;
+  Dali::AsyncTaskManager                          mAsyncTaskManager;
+
+  bool mNeedToSleep : 1;
+  bool mDestroyThread : 1;
+  bool mEventTriggered : 1;
+  bool mForceRenderOnce : 1;
 };
 
 } // namespace Internal