Chromium Code Reviews| Index: cc/raster/synchronous_task_graph_runner.cc |
| diff --git a/cc/raster/synchronous_task_graph_runner.cc b/cc/raster/synchronous_task_graph_runner.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..17a511087216fde1d2fda90dda9baf52282e93ef |
| --- /dev/null |
| +++ b/cc/raster/synchronous_task_graph_runner.cc |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/raster/synchronous_task_graph_runner.h" |
| + |
| +#include "base/threading/simple_thread.h" |
| +#include "base/threading/thread_restrictions.h" |
| +#include "base/trace_event/trace_event.h" |
| + |
| +namespace cc { |
| + |
| +SynchronousTaskGraphRunner::SynchronousTaskGraphRunner() {} |
| + |
| +SynchronousTaskGraphRunner::~SynchronousTaskGraphRunner() { |
| + DCHECK(!work_queue_.HasReadyToRunTasks()); |
| +} |
| + |
| +void SynchronousTaskGraphRunner::ScheduleTasks(NamespaceToken token, |
| + TaskGraph* graph) { |
| + TRACE_EVENT2("cc", "SynchronousTaskGraphRunner::ScheduleTasks", "num_nodes", |
| + graph->nodes.size(), "num_edges", graph->edges.size()); |
| + |
| + DCHECK(token.IsValid()); |
| + DCHECK(!DependencyMismatch(graph)); |
| + |
| + work_queue_.ScheduleTasks(token, graph); |
| +} |
| + |
| +void SynchronousTaskGraphRunner::WaitForTasksToFinishRunning( |
| + NamespaceToken token) { |
| + TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::WaitForTasksToFinishRunning"); |
| + |
| + DCHECK(token.IsValid()); |
| + auto* task_namespace = work_queue_.GetNamespaceForToken(token); |
| + |
| + if (!task_namespace) |
| + return; |
| + |
| + while ( |
| + !TaskGraphWorkQueue::HasFinishedRunningTasksInNamespace(task_namespace)) |
|
reveman
2015/11/19 16:05:46
heh, cl format is not always making the best choic
ericrk
2015/11/23 18:43:37
yup... heh
|
| + RunTask(); |
| +} |
| + |
| +void SynchronousTaskGraphRunner::CollectCompletedTasks( |
| + NamespaceToken token, |
| + Task::Vector* completed_tasks) { |
| + TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::CollectCompletedTasks"); |
| + |
| + DCHECK(token.IsValid()); |
| + work_queue_.CollectCompletedTasks(token, completed_tasks); |
| +} |
| + |
| +void SynchronousTaskGraphRunner::RunUntilIdle() { |
| + while (work_queue_.HasReadyToRunTasks()) |
| + RunTask(); |
| +} |
| + |
| +void SynchronousTaskGraphRunner::RunTask() { |
| + TRACE_EVENT0("toplevel", "SynchronousTaskGraphRunner::RunTask"); |
| + |
| + auto prioritized_task = work_queue_.GetNextTaskToRun(); |
| + |
| + Task* task = prioritized_task.task; |
| + task->WillRun(); |
| + task->RunOnWorkerThread(); |
| + task->DidRun(); |
| + |
| + work_queue_.CompleteTask(prioritized_task); |
| +} |
| + |
| +} // namespace cc |