OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/tiles/tile_task_manager.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/trace_event/trace_event.h" |
| 9 |
| 10 namespace cc { |
| 11 |
| 12 TileTaskManager::TileTaskManager() {} |
| 13 |
| 14 TileTaskManager::~TileTaskManager() {} |
| 15 |
| 16 // static |
| 17 std::unique_ptr<TileTaskManagerImpl> TileTaskManagerImpl::Create( |
| 18 std::unique_ptr<RasterBufferProvider> raster_buffer_provider, |
| 19 TaskGraphRunner* task_graph_runner) { |
| 20 return base::WrapUnique<TileTaskManagerImpl>(new TileTaskManagerImpl( |
| 21 std::move(raster_buffer_provider), task_graph_runner)); |
| 22 } |
| 23 |
| 24 TileTaskManagerImpl::TileTaskManagerImpl( |
| 25 std::unique_ptr<RasterBufferProvider> raster_buffer_provider, |
| 26 TaskGraphRunner* task_graph_runner) |
| 27 : raster_buffer_provider_(std::move(raster_buffer_provider)), |
| 28 task_graph_runner_(task_graph_runner), |
| 29 namespace_token_(task_graph_runner->GetNamespaceToken()) {} |
| 30 |
| 31 TileTaskManagerImpl::~TileTaskManagerImpl() { |
| 32 DCHECK_EQ(0u, completed_tasks_.size()); |
| 33 } |
| 34 |
| 35 void TileTaskManagerImpl::ScheduleTasks(TaskGraph* graph) { |
| 36 TRACE_EVENT0("cc", "TileTaskManagerImpl::ScheduleTasks"); |
| 37 |
| 38 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); |
| 39 it != graph->nodes.end(); ++it) { |
| 40 TaskGraph::Node& node = *it; |
| 41 TileTask* task = static_cast<TileTask*>(node.task); |
| 42 |
| 43 if (!task->HasBeenScheduled()) { |
| 44 task->WillSchedule(); |
| 45 task->ScheduleOnOriginThread(raster_buffer_provider_.get()); |
| 46 task->DidSchedule(); |
| 47 } |
| 48 } |
| 49 |
| 50 raster_buffer_provider_->OrderingBarrier(); |
| 51 |
| 52 task_graph_runner_->ScheduleTasks(namespace_token_, graph); |
| 53 } |
| 54 |
| 55 void TileTaskManagerImpl::CheckForCompletedTasks() { |
| 56 TRACE_EVENT0("cc", "TileTaskManagerImpl::CheckForCompletedTasks"); |
| 57 |
| 58 task_graph_runner_->CollectCompletedTasks(namespace_token_, |
| 59 &completed_tasks_); |
| 60 for (Task::Vector::const_iterator it = completed_tasks_.begin(); |
| 61 it != completed_tasks_.end(); ++it) { |
| 62 TileTask* task = static_cast<TileTask*>(it->get()); |
| 63 |
| 64 task->WillComplete(); |
| 65 task->CompleteOnOriginThread(raster_buffer_provider_.get()); |
| 66 task->DidComplete(); |
| 67 } |
| 68 completed_tasks_.clear(); |
| 69 } |
| 70 |
| 71 void TileTaskManagerImpl::Shutdown() { |
| 72 TRACE_EVENT0("cc", "TileTaskManagerImpl::Shutdown"); |
| 73 |
| 74 // Cancel non-scheduled tasks and wait for running tasks to finish. |
| 75 TaskGraph empty; |
| 76 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); |
| 77 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); |
| 78 |
| 79 raster_buffer_provider_->Shutdown(); |
| 80 } |
| 81 |
| 82 RasterBufferProvider* TileTaskManagerImpl::GetRasterBufferProvider() const { |
| 83 return raster_buffer_provider_.get(); |
| 84 } |
| 85 |
| 86 } // namespace cc |
OLD | NEW |