Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / cc / resources / gpu_tile_task_worker_pool.cc
blob86157308f4f289164754576019785d23aa8c3a09
1 // Copyright 2014 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.
5 #include "cc/resources/gpu_tile_task_worker_pool.h"
7 #include <algorithm>
9 #include "base/debug/trace_event.h"
10 #include "cc/resources/raster_buffer.h"
11 #include "cc/resources/raster_source.h"
12 #include "cc/resources/resource.h"
13 #include "cc/resources/scoped_gpu_raster.h"
14 #include "gpu/command_buffer/client/gles2_interface.h"
15 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
16 #include "third_party/skia/include/core/SkPictureRecorder.h"
17 #include "third_party/skia/include/core/SkSurface.h"
18 #include "third_party/skia/include/gpu/GrContext.h"
20 namespace cc {
21 namespace {
23 class RasterBufferImpl : public RasterBuffer {
24 public:
25 RasterBufferImpl() {}
27 // Overridden from RasterBuffer:
28 void Playback(const RasterSource* raster_source,
29 const gfx::Rect& rect,
30 float scale) override {
31 // Don't do anything.
34 private:
35 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl);
38 } // namespace
39 // static
40 scoped_ptr<TileTaskWorkerPool> GpuTileTaskWorkerPool::Create(
41 base::SequencedTaskRunner* task_runner,
42 TaskGraphRunner* task_graph_runner) {
43 return make_scoped_ptr<TileTaskWorkerPool>(
44 new GpuTileTaskWorkerPool(task_runner, task_graph_runner));
47 // TODO(hendrikw): This class should be removed. See crbug.com/444938.
48 GpuTileTaskWorkerPool::GpuTileTaskWorkerPool(
49 base::SequencedTaskRunner* task_runner,
50 TaskGraphRunner* task_graph_runner)
51 : task_runner_(task_runner),
52 task_graph_runner_(task_graph_runner),
53 namespace_token_(task_graph_runner_->GetNamespaceToken()),
54 task_set_finished_weak_ptr_factory_(this),
55 weak_ptr_factory_(this) {
58 GpuTileTaskWorkerPool::~GpuTileTaskWorkerPool() {
59 DCHECK_EQ(0u, completed_tasks_.size());
62 TileTaskRunner* GpuTileTaskWorkerPool::AsTileTaskRunner() {
63 return this;
66 void GpuTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) {
67 client_ = client;
70 void GpuTileTaskWorkerPool::Shutdown() {
71 TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::Shutdown");
73 TaskGraph empty;
74 task_graph_runner_->ScheduleTasks(namespace_token_, &empty);
75 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_);
78 void GpuTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) {
79 TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::ScheduleTasks");
81 // Mark all task sets as pending.
82 tasks_pending_.set();
84 unsigned priority = kTileTaskPriorityBase;
86 graph_.Reset();
88 // Cancel existing OnTaskSetFinished callbacks.
89 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs();
91 scoped_refptr<TileTask> new_task_set_finished_tasks[kNumberOfTaskSets];
93 size_t task_count[kNumberOfTaskSets] = {0};
95 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
96 new_task_set_finished_tasks[task_set] = CreateTaskSetFinishedTask(
97 task_runner_.get(),
98 base::Bind(&GpuTileTaskWorkerPool::OnTaskSetFinished,
99 task_set_finished_weak_ptr_factory_.GetWeakPtr(), task_set));
102 for (TileTaskQueue::Item::Vector::const_iterator it = queue->items.begin();
103 it != queue->items.end(); ++it) {
104 const TileTaskQueue::Item& item = *it;
105 RasterTask* task = item.task;
106 DCHECK(!task->HasCompleted());
108 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
109 if (!item.task_sets[task_set])
110 continue;
112 ++task_count[task_set];
114 graph_.edges.push_back(
115 TaskGraph::Edge(task, new_task_set_finished_tasks[task_set].get()));
118 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++);
121 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
122 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(),
123 kTaskSetFinishedTaskPriority, task_count[task_set]);
126 ScheduleTasksOnOriginThread(this, &graph_);
127 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_);
129 std::copy(new_task_set_finished_tasks,
130 new_task_set_finished_tasks + kNumberOfTaskSets,
131 task_set_finished_tasks_);
134 void GpuTileTaskWorkerPool::CheckForCompletedTasks() {
135 TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::CheckForCompletedTasks");
137 task_graph_runner_->CollectCompletedTasks(namespace_token_,
138 &completed_tasks_);
139 CompleteTasks(completed_tasks_);
140 completed_tasks_.clear();
143 void GpuTileTaskWorkerPool::CompleteTasks(const Task::Vector& tasks) {
144 for (auto& task : tasks) {
145 RasterTask* raster_task = static_cast<RasterTask*>(task.get());
147 raster_task->WillComplete();
148 raster_task->CompleteOnOriginThread(this);
149 raster_task->DidComplete();
151 raster_task->RunReplyOnOriginThread();
153 completed_tasks_.clear();
156 scoped_ptr<RasterBuffer> GpuTileTaskWorkerPool::AcquireBufferForRaster(
157 const Resource* resource) {
158 return make_scoped_ptr<RasterBuffer>(new RasterBufferImpl());
161 void GpuTileTaskWorkerPool::ReleaseBufferForRaster(
162 scoped_ptr<RasterBuffer> buffer) {
163 // Nothing to do here. RasterBufferImpl destructor cleans up after itself.
166 void GpuTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) {
167 TRACE_EVENT1("cc", "GpuTileTaskWorkerPool::OnTaskSetFinished", "task_set",
168 task_set);
170 DCHECK(tasks_pending_[task_set]);
171 tasks_pending_[task_set] = false;
172 client_->DidFinishRunningTileTasks(task_set);
175 } // namespace cc