OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/raster/synchronous_task_graph_runner.h" | 5 #include "cc/raster/synchronous_task_graph_runner.h" |
6 | 6 |
7 #include <algorithm> | |
8 #include <utility> | |
9 | |
10 #include "base/threading/simple_thread.h" | 7 #include "base/threading/simple_thread.h" |
11 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
12 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
13 | 10 |
14 namespace cc { | 11 namespace cc { |
15 | 12 |
16 SynchronousTaskGraphRunner::SynchronousTaskGraphRunner() {} | 13 SynchronousTaskGraphRunner::SynchronousTaskGraphRunner() {} |
17 | 14 |
18 SynchronousTaskGraphRunner::~SynchronousTaskGraphRunner() { | 15 SynchronousTaskGraphRunner::~SynchronousTaskGraphRunner() { |
19 DCHECK(!work_queue_.HasReadyToRunTasks()); | 16 DCHECK(!work_queue_.HasReadyToRunTasks()); |
(...skipping 17 matching lines...) Expand all Loading... |
37 void SynchronousTaskGraphRunner::WaitForTasksToFinishRunning( | 34 void SynchronousTaskGraphRunner::WaitForTasksToFinishRunning( |
38 NamespaceToken token) { | 35 NamespaceToken token) { |
39 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::WaitForTasksToFinishRunning"); | 36 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::WaitForTasksToFinishRunning"); |
40 | 37 |
41 DCHECK(token.IsValid()); | 38 DCHECK(token.IsValid()); |
42 auto* task_namespace = work_queue_.GetNamespaceForToken(token); | 39 auto* task_namespace = work_queue_.GetNamespaceForToken(token); |
43 | 40 |
44 if (!task_namespace) | 41 if (!task_namespace) |
45 return; | 42 return; |
46 | 43 |
47 while (!work_queue_.HasFinishedRunningTasksInNamespace(task_namespace)) { | 44 while ( |
48 bool succeeded = RunTask(); | 45 !TaskGraphWorkQueue::HasFinishedRunningTasksInNamespace(task_namespace)) { |
49 DCHECK(succeeded); | 46 RunTask(); |
50 } | 47 } |
51 } | 48 } |
52 | 49 |
53 void SynchronousTaskGraphRunner::CollectCompletedTasks( | 50 void SynchronousTaskGraphRunner::CollectCompletedTasks( |
54 NamespaceToken token, | 51 NamespaceToken token, |
55 Task::Vector* completed_tasks) { | 52 Task::Vector* completed_tasks) { |
56 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::CollectCompletedTasks"); | 53 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::CollectCompletedTasks"); |
57 | 54 |
58 DCHECK(token.IsValid()); | 55 DCHECK(token.IsValid()); |
59 work_queue_.CollectCompletedTasks(token, completed_tasks); | 56 work_queue_.CollectCompletedTasks(token, completed_tasks); |
60 } | 57 } |
61 | 58 |
62 void SynchronousTaskGraphRunner::RunUntilIdle() { | 59 void SynchronousTaskGraphRunner::RunUntilIdle() { |
63 while (RunTask()) { | 60 while (work_queue_.HasReadyToRunTasks()) |
64 } | 61 RunTask(); |
65 } | 62 } |
66 | 63 |
67 bool SynchronousTaskGraphRunner::RunTask() { | 64 void SynchronousTaskGraphRunner::RunTask() { |
68 TRACE_EVENT0("toplevel", "SynchronousTaskGraphRunner::RunTask"); | 65 TRACE_EVENT0("toplevel", "SynchronousTaskGraphRunner::RunTask"); |
69 | 66 |
70 // Find the first category with any tasks to run. This task graph runner | 67 auto prioritized_task = work_queue_.GetNextTaskToRun(); |
71 // treats categories as an additional priority. | |
72 const auto& ready_to_run_namespaces = work_queue_.ready_to_run_namespaces(); | |
73 auto found = std::find_if( | |
74 ready_to_run_namespaces.cbegin(), ready_to_run_namespaces.cend(), | |
75 [](const std::pair<uint16_t, TaskGraphWorkQueue::TaskNamespace::Vector>& | |
76 pair) { return !pair.second.empty(); }); | |
77 | |
78 if (found == ready_to_run_namespaces.cend()) { | |
79 return false; | |
80 } | |
81 | |
82 const uint16_t category = found->first; | |
83 auto prioritized_task = work_queue_.GetNextTaskToRun(category); | |
84 | 68 |
85 Task* task = prioritized_task.task; | 69 Task* task = prioritized_task.task; |
86 task->WillRun(); | 70 task->WillRun(); |
87 task->RunOnWorkerThread(); | 71 task->RunOnWorkerThread(); |
88 task->DidRun(); | 72 task->DidRun(); |
89 | 73 |
90 work_queue_.CompleteTask(prioritized_task); | 74 work_queue_.CompleteTask(prioritized_task); |
91 | |
92 return true; | |
93 } | 75 } |
94 | 76 |
95 } // namespace cc | 77 } // namespace cc |
OLD | NEW |