Optimize VectorAnimationThread task control 59/315459/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 1 Aug 2024 06:58:42 +0000 (15:58 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 2 Aug 2024 01:20:59 +0000 (10:20 +0900)
Since we don't need to find & iterate whole tasks for
mWorkingTasks and mCompletedTasks, let we use more faster container,
instead of linear.

Change-Id: I34dc1d884b4853c681e55f89dd0ddd79ecce5b5c
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h

index a4992d9f55b97a2489db7bf0c81e70d048be3b19..a15e423e55c6dc11f500bf0440981faa1d8252c2 100644 (file)
@@ -253,10 +253,10 @@ void VectorAnimationThread::MoveTasksToCompleted(VectorAnimationTaskPtr task, bo
     });
     bool needRasterize = false;
 
-    auto workingTask = std::find(mWorkingTasks.begin(), mWorkingTasks.end(), task);
-    if(workingTask != mWorkingTasks.end())
+    VectorAnimationTaskSet::const_iterator workingIter = mWorkingTasks.find(task);
+    if(workingIter != mWorkingTasks.cend())
     {
-      mWorkingTasks.erase(workingTask);
+      mWorkingTasks.erase(workingIter);
     }
 
     // Check pending task
@@ -270,9 +270,10 @@ void VectorAnimationThread::MoveTasksToCompleted(VectorAnimationTaskPtr task, bo
 
     if(keepAnimation)
     {
-      if(mCompletedTasks.end() == std::find(mCompletedTasks.begin(), mCompletedTasks.end(), task))
+      VectorAnimationTaskSet::const_iterator completedIter = mCompletedTasks.lower_bound(task);
+      if(completedIter == mCompletedTasks.cend() || task < *completedIter)
       {
-        mCompletedTasks.push_back(task);
+        mCompletedTasks.insert(completedIter, task);
         needRasterize = true;
       }
     }
@@ -353,12 +354,13 @@ void VectorAnimationThread::Rasterize()
           if(nextFrameTime <= currentTime)
           {
             // If the task is not in the working list
-            if(std::find(mWorkingTasks.begin(), mWorkingTasks.end(), nextTask) == mWorkingTasks.end())
+            VectorAnimationTaskSet::const_iterator workingIter = mWorkingTasks.lower_bound(nextTask);
+            if(workingIter == mWorkingTasks.cend() || nextTask < *workingIter)
             {
               it = mAnimationTasks.erase(it);
 
               // Add it to the working list
-              mWorkingTasks.push_back(nextTask);
+              mWorkingTasks.insert(workingIter, nextTask);
               mAsyncTaskManager.AddTask(nextTask);
             }
             else
index ac5053b70d6f0b71a1209411e5358af815dd7aff..c3a0910c84156e54bf2b5070e19e47f8fc973c0d 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/common/set-wrapper.h>
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <dali/devel-api/threading/mutex.h>
 #include <dali/devel-api/threading/thread.h>
@@ -180,8 +181,10 @@ private:
 
 private:
   std::vector<VectorAnimationTaskPtr> mAnimationTasks; ///< Animation processing tasks, ordered by next frame time.
-  std::vector<VectorAnimationTaskPtr> mCompletedTasks; ///< Temperal storage for completed tasks.
-  std::vector<VectorAnimationTaskPtr> mWorkingTasks;
+
+  using VectorAnimationTaskSet = std::set<VectorAnimationTaskPtr>;
+  VectorAnimationTaskSet mCompletedTasks; ///< Temperal storage for completed tasks.
+  VectorAnimationTaskSet mWorkingTasks;   ///< Tasks which are currently being processed. Key is the task, value is the number of tasks running.
 
   std::vector<std::pair<VectorAnimationTaskPtr, bool>> mCompletedTasksQueue; ///< Queue of completed tasks from worker thread. pair of task, and rasterize required.
                                                                              ///< It will be moved at begin of Rasterize().