Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: cc/resources/pixel_buffer_raster_worker_pool.cc

Issue 523243002: cc: Generalize raster task notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean-ups Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/resources/pixel_buffer_raster_worker_pool.h" 5 #include "cc/resources/pixel_buffer_raster_worker_pool.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/containers/stack_container.h" 9 #include "base/containers/stack_container.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/debug/trace_event_argument.h" 11 #include "base/debug/trace_event_argument.h"
12 #include "base/strings/stringprintf.h"
12 #include "cc/debug/traced_value.h" 13 #include "cc/debug/traced_value.h"
13 #include "cc/resources/resource.h" 14 #include "cc/resources/resource.h"
14 #include "gpu/command_buffer/client/gles2_interface.h" 15 #include "gpu/command_buffer/client/gles2_interface.h"
15 16
16 namespace cc { 17 namespace cc {
17 namespace { 18 namespace {
18 19
19 const int kCheckForCompletedRasterTasksDelayMs = 6; 20 const int kCheckForCompletedRasterTasksDelayMs = 6;
20 21
21 const size_t kMaxScheduledRasterTasks = 48; 22 const size_t kMaxScheduledRasterTasks = 48;
22 23
23 typedef base::StackVector<RasterTask*, kMaxScheduledRasterTasks> 24 typedef base::StackVector<RasterTask*, kMaxScheduledRasterTasks>
24 RasterTaskVector; 25 RasterTaskVector;
25 26
26 } // namespace 27 } // namespace
27 28
29 void SetTaskCountsToZero(size_t* task_counts) {
reveman 2014/09/17 20:46:28 I think you can remove this and use std::fill inst
ernstm 2014/09/17 21:44:25 Done.
30 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set)
31 task_counts[task_set] = 0;
32 }
33
34 TaskSetCollection TaskCountsToTaskSets(const size_t* task_counts) {
reveman 2014/09/17 20:46:28 NonEmptyTaskSetsFromTaskCounts?
ernstm 2014/09/17 21:44:25 Done.
35 TaskSetCollection task_set_collection;
reveman 2014/09/17 20:46:28 task_sets?
ernstm 2014/09/17 21:44:25 Done.
36 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
37 if (task_counts[task_set] > 0)
reveman 2014/09/17 20:46:28 nit: s/task_counts[task_set] > 0/task_counts[task_
ernstm 2014/09/17 21:44:25 Done.
38 task_set_collection[task_set] = true;
39 }
40 return task_set_collection;
41 }
42
43 void AddTaskSetsToTaskCounts(size_t* task_counts,
44 const TaskSetCollection& task_sets) {
45 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
46 if (task_sets[task_set])
47 task_counts[task_set]++;
48 }
49 }
50
51 void RemoveTaskSetsFromTaskCounts(size_t* task_counts,
52 const TaskSetCollection& task_sets) {
53 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
54 if (task_sets[task_set])
55 task_counts[task_set]--;
56 }
57 }
reveman 2014/09/17 20:46:28 can you move the functions above to anonymous name
ernstm 2014/09/17 21:44:25 Done.
58
59 PixelBufferRasterWorkerPool::RasterTaskState::RasterTaskState(
60 RasterTask* task,
61 const TaskSetCollection& task_sets)
62 : type(UNSCHEDULED), task(task), task_sets(task_sets) {
63 }
64
28 // static 65 // static
29 scoped_ptr<RasterWorkerPool> PixelBufferRasterWorkerPool::Create( 66 scoped_ptr<RasterWorkerPool> PixelBufferRasterWorkerPool::Create(
30 base::SequencedTaskRunner* task_runner, 67 base::SequencedTaskRunner* task_runner,
31 TaskGraphRunner* task_graph_runner, 68 TaskGraphRunner* task_graph_runner,
32 ContextProvider* context_provider, 69 ContextProvider* context_provider,
33 ResourceProvider* resource_provider, 70 ResourceProvider* resource_provider,
34 size_t max_transfer_buffer_usage_bytes) { 71 size_t max_transfer_buffer_usage_bytes) {
35 return make_scoped_ptr<RasterWorkerPool>( 72 return make_scoped_ptr<RasterWorkerPool>(
36 new PixelBufferRasterWorkerPool(task_runner, 73 new PixelBufferRasterWorkerPool(task_runner,
37 task_graph_runner, 74 task_graph_runner,
38 context_provider, 75 context_provider,
39 resource_provider, 76 resource_provider,
40 max_transfer_buffer_usage_bytes)); 77 max_transfer_buffer_usage_bytes));
41 } 78 }
42 79
43 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( 80 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool(
44 base::SequencedTaskRunner* task_runner, 81 base::SequencedTaskRunner* task_runner,
45 TaskGraphRunner* task_graph_runner, 82 TaskGraphRunner* task_graph_runner,
46 ContextProvider* context_provider, 83 ContextProvider* context_provider,
47 ResourceProvider* resource_provider, 84 ResourceProvider* resource_provider,
48 size_t max_transfer_buffer_usage_bytes) 85 size_t max_transfer_buffer_usage_bytes)
49 : task_runner_(task_runner), 86 : task_runner_(task_runner),
50 task_graph_runner_(task_graph_runner), 87 task_graph_runner_(task_graph_runner),
51 namespace_token_(task_graph_runner->GetNamespaceToken()), 88 namespace_token_(task_graph_runner->GetNamespaceToken()),
52 context_provider_(context_provider), 89 context_provider_(context_provider),
53 resource_provider_(resource_provider), 90 resource_provider_(resource_provider),
54 shutdown_(false), 91 shutdown_(false),
55 scheduled_raster_task_count_(0u), 92 scheduled_raster_task_count_(0u),
56 raster_tasks_required_for_activation_count_(0u),
57 bytes_pending_upload_(0u), 93 bytes_pending_upload_(0u),
58 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), 94 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes),
59 has_performed_uploads_since_last_flush_(false), 95 has_performed_uploads_since_last_flush_(false),
60 should_notify_client_if_no_tasks_are_pending_(false),
61 should_notify_client_if_no_tasks_required_for_activation_are_pending_(
62 false),
63 raster_finished_task_pending_(false),
64 raster_required_for_activation_finished_task_pending_(false),
65 check_for_completed_raster_task_notifier_( 96 check_for_completed_raster_task_notifier_(
66 task_runner, 97 task_runner,
67 base::Bind(&PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks, 98 base::Bind(&PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks,
68 base::Unretained(this)), 99 base::Unretained(this)),
69 base::TimeDelta::FromMilliseconds( 100 base::TimeDelta::FromMilliseconds(
70 kCheckForCompletedRasterTasksDelayMs)), 101 kCheckForCompletedRasterTasksDelayMs)),
71 raster_finished_weak_ptr_factory_(this) { 102 raster_finished_weak_ptr_factory_(this) {
72 DCHECK(context_provider_); 103 DCHECK(context_provider_);
104 SetTaskCountsToZero(task_counts_);
73 } 105 }
74 106
75 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { 107 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() {
76 DCHECK_EQ(0u, raster_task_states_.size()); 108 DCHECK_EQ(0u, raster_task_states_.size());
77 DCHECK_EQ(0u, raster_tasks_with_pending_upload_.size()); 109 DCHECK_EQ(0u, raster_tasks_with_pending_upload_.size());
78 DCHECK_EQ(0u, completed_raster_tasks_.size()); 110 DCHECK_EQ(0u, completed_raster_tasks_.size());
79 DCHECK_EQ(0u, completed_image_decode_tasks_.size()); 111 DCHECK_EQ(0u, completed_image_decode_tasks_.size());
80 DCHECK_EQ(0u, raster_tasks_required_for_activation_count_); 112 DCHECK(TaskCountsToTaskSets(task_counts_).none());
81 } 113 }
82 114
83 Rasterizer* PixelBufferRasterWorkerPool::AsRasterizer() { return this; } 115 Rasterizer* PixelBufferRasterWorkerPool::AsRasterizer() { return this; }
84 116
85 void PixelBufferRasterWorkerPool::SetClient(RasterizerClient* client) { 117 void PixelBufferRasterWorkerPool::SetClient(RasterizerClient* client) {
86 client_ = client; 118 client_ = client;
87 } 119 }
88 120
89 void PixelBufferRasterWorkerPool::Shutdown() { 121 void PixelBufferRasterWorkerPool::Shutdown() {
90 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::Shutdown"); 122 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::Shutdown");
(...skipping 19 matching lines...) Expand all
110 completed_raster_tasks_.push_back(state.task); 142 completed_raster_tasks_.push_back(state.task);
111 state.type = RasterTaskState::COMPLETED; 143 state.type = RasterTaskState::COMPLETED;
112 } 144 }
113 } 145 }
114 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); 146 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size());
115 } 147 }
116 148
117 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { 149 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) {
118 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); 150 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks");
119 151
120 if (!should_notify_client_if_no_tasks_are_pending_) 152 if (should_notify_client_if_no_tasks_are_pending_.none())
121 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); 153 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this);
122 154
123 should_notify_client_if_no_tasks_are_pending_ = true; 155 should_notify_client_if_no_tasks_are_pending_.set();
124 should_notify_client_if_no_tasks_required_for_activation_are_pending_ = true; 156 SetTaskCountsToZero(task_counts_);
125
126 raster_tasks_required_for_activation_count_ = 0u;
127 157
128 // Update raster task state and remove items from old queue. 158 // Update raster task state and remove items from old queue.
129 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); 159 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin();
130 it != queue->items.end(); 160 it != queue->items.end();
131 ++it) { 161 ++it) {
132 const RasterTaskQueue::Item& item = *it; 162 const RasterTaskQueue::Item& item = *it;
133 RasterTask* task = item.task; 163 RasterTask* task = item.task;
134 164
135 // Remove any old items that are associated with this task. The result is 165 // Remove any old items that are associated with this task. The result is
136 // that the old queue is left with all items not present in this queue, 166 // that the old queue is left with all items not present in this queue,
137 // which we use below to determine what tasks need to be canceled. 167 // which we use below to determine what tasks need to be canceled.
138 RasterTaskQueue::Item::Vector::iterator old_it = 168 RasterTaskQueue::Item::Vector::iterator old_it =
139 std::find_if(raster_tasks_.items.begin(), 169 std::find_if(raster_tasks_.items.begin(),
140 raster_tasks_.items.end(), 170 raster_tasks_.items.end(),
141 RasterTaskQueue::Item::TaskComparator(task)); 171 RasterTaskQueue::Item::TaskComparator(task));
142 if (old_it != raster_tasks_.items.end()) { 172 if (old_it != raster_tasks_.items.end()) {
143 std::swap(*old_it, raster_tasks_.items.back()); 173 std::swap(*old_it, raster_tasks_.items.back());
144 raster_tasks_.items.pop_back(); 174 raster_tasks_.items.pop_back();
145 } 175 }
146 176
147 RasterTaskState::Vector::iterator state_it = 177 RasterTaskState::Vector::iterator state_it =
148 std::find_if(raster_task_states_.begin(), 178 std::find_if(raster_task_states_.begin(),
149 raster_task_states_.end(), 179 raster_task_states_.end(),
150 RasterTaskState::TaskComparator(task)); 180 RasterTaskState::TaskComparator(task));
151 if (state_it != raster_task_states_.end()) { 181 if (state_it != raster_task_states_.end()) {
152 RasterTaskState& state = *state_it; 182 RasterTaskState& state = *state_it;
153 183
154 state.required_for_activation = item.required_for_activation; 184 state.task_sets = item.task_sets;
155 // |raster_tasks_required_for_activation_count| accounts for all tasks 185 // |raster_tasks_required_for_activation_count| accounts for all tasks
156 // that need to complete before we can send a "ready to activate" signal. 186 // that need to complete before we can send a "ready to activate" signal.
157 // Tasks that have already completed should not be part of this count. 187 // Tasks that have already completed should not be part of this count.
158 if (state.type != RasterTaskState::COMPLETED) { 188 if (state.type != RasterTaskState::COMPLETED)
159 raster_tasks_required_for_activation_count_ += 189 AddTaskSetsToTaskCounts(task_counts_, item.task_sets);
160 item.required_for_activation; 190
161 }
162 continue; 191 continue;
163 } 192 }
164 193
165 DCHECK(!task->HasBeenScheduled()); 194 DCHECK(!task->HasBeenScheduled());
166 raster_task_states_.push_back( 195 raster_task_states_.push_back(RasterTaskState(task, item.task_sets));
167 RasterTaskState(task, item.required_for_activation)); 196 AddTaskSetsToTaskCounts(task_counts_, item.task_sets);
168 raster_tasks_required_for_activation_count_ += item.required_for_activation;
169 } 197 }
170 198
171 // Determine what tasks in old queue need to be canceled. 199 // Determine what tasks in old queue need to be canceled.
172 for (RasterTaskQueue::Item::Vector::const_iterator it = 200 for (RasterTaskQueue::Item::Vector::const_iterator it =
173 raster_tasks_.items.begin(); 201 raster_tasks_.items.begin();
174 it != raster_tasks_.items.end(); 202 it != raster_tasks_.items.end();
175 ++it) { 203 ++it) {
176 const RasterTaskQueue::Item& item = *it; 204 const RasterTaskQueue::Item& item = *it;
177 RasterTask* task = item.task; 205 RasterTask* task = item.task;
178 206
(...skipping 11 matching lines...) Expand all
190 // Unscheduled task can be canceled. 218 // Unscheduled task can be canceled.
191 if (state.type == RasterTaskState::UNSCHEDULED) { 219 if (state.type == RasterTaskState::UNSCHEDULED) {
192 DCHECK(!task->HasBeenScheduled()); 220 DCHECK(!task->HasBeenScheduled());
193 DCHECK(std::find(completed_raster_tasks_.begin(), 221 DCHECK(std::find(completed_raster_tasks_.begin(),
194 completed_raster_tasks_.end(), 222 completed_raster_tasks_.end(),
195 task) == completed_raster_tasks_.end()); 223 task) == completed_raster_tasks_.end());
196 completed_raster_tasks_.push_back(task); 224 completed_raster_tasks_.push_back(task);
197 state.type = RasterTaskState::COMPLETED; 225 state.type = RasterTaskState::COMPLETED;
198 } 226 }
199 227
200 // No longer required for activation. 228 // No longer in any task set.
201 state.required_for_activation = false; 229 state.task_sets.reset();
202 } 230 }
203 231
204 raster_tasks_.Swap(queue); 232 raster_tasks_.Swap(queue);
205 233
206 // Check for completed tasks when ScheduleTasks() is called as 234 // Check for completed tasks when ScheduleTasks() is called as
207 // priorities might have changed and this maximizes the number 235 // priorities might have changed and this maximizes the number
208 // of top priority tasks that are scheduled. 236 // of top priority tasks that are scheduled.
209 CheckForCompletedRasterizerTasks(); 237 CheckForCompletedRasterizerTasks();
210 CheckForCompletedUploads(); 238 CheckForCompletedUploads();
211 FlushUploads(); 239 FlushUploads();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 293 }
266 294
267 void PixelBufferRasterWorkerPool::ReleaseBufferForRaster(RasterTask* task) { 295 void PixelBufferRasterWorkerPool::ReleaseBufferForRaster(RasterTask* task) {
268 DCHECK(std::find_if(raster_task_states_.begin(), 296 DCHECK(std::find_if(raster_task_states_.begin(),
269 raster_task_states_.end(), 297 raster_task_states_.end(),
270 RasterTaskState::TaskComparator(task)) != 298 RasterTaskState::TaskComparator(task)) !=
271 raster_task_states_.end()); 299 raster_task_states_.end());
272 resource_provider_->ReleasePixelRasterBuffer(task->resource()->id()); 300 resource_provider_->ReleasePixelRasterBuffer(task->resource()->id());
273 } 301 }
274 302
275 void PixelBufferRasterWorkerPool::OnRasterFinished() { 303 void PixelBufferRasterWorkerPool::OnRasterFinished(TaskSet task_set) {
276 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::OnRasterFinished"); 304 TRACE_EVENT1("cc",
305 "PixelBufferRasterWorkerPool::OnRasterFinished",
306 "task_set",
307 task_set);
277 308
278 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as 309 // There's no need to call CheckForCompletedRasterTasks() if the client has
279 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to 310 // already been notified.
280 // perform another check in that case as we've already notified the client. 311 if (!should_notify_client_if_no_tasks_are_pending_[task_set])
281 if (!should_notify_client_if_no_tasks_are_pending_)
282 return; 312 return;
283 raster_finished_task_pending_ = false; 313 raster_finished_tasks_pending_[task_set] = false;
284
285 // Call CheckForCompletedRasterTasks() when we've finished running all
286 // raster tasks needed since last time ScheduleTasks() was called.
287 // This reduces latency between the time when all tasks have finished
288 // running and the time when the client is notified.
289 CheckForCompletedRasterTasks();
290 }
291
292 void PixelBufferRasterWorkerPool::OnRasterRequiredForActivationFinished() {
293 TRACE_EVENT0(
294 "cc",
295 "PixelBufferRasterWorkerPool::OnRasterRequiredForActivationFinished");
296
297 // Analogous to OnRasterTasksFinished(), there's no need to call
298 // CheckForCompletedRasterTasks() if the client has already been notified.
299 if (!should_notify_client_if_no_tasks_required_for_activation_are_pending_)
300 return;
301 raster_required_for_activation_finished_task_pending_ = false;
302 314
303 // This reduces latency between the time when all tasks required for 315 // This reduces latency between the time when all tasks required for
304 // activation have finished running and the time when the client is 316 // activation have finished running and the time when the client is
305 // notified. 317 // notified.
306 CheckForCompletedRasterTasks(); 318 CheckForCompletedRasterTasks();
307 } 319 }
308 320
309 void PixelBufferRasterWorkerPool::FlushUploads() { 321 void PixelBufferRasterWorkerPool::FlushUploads() {
310 if (!has_performed_uploads_since_last_flush_) 322 if (!has_performed_uploads_since_last_flush_)
311 return; 323 return;
(...skipping 19 matching lines...) Expand all
331 343
332 // Uploads complete in the order they are issued. 344 // Uploads complete in the order they are issued.
333 if (!resource_provider_->DidSetPixelsComplete(task->resource()->id())) 345 if (!resource_provider_->DidSetPixelsComplete(task->resource()->id()))
334 break; 346 break;
335 347
336 tasks_with_completed_uploads.push_back(task); 348 tasks_with_completed_uploads.push_back(task);
337 raster_tasks_with_pending_upload_.pop_front(); 349 raster_tasks_with_pending_upload_.pop_front();
338 } 350 }
339 351
340 DCHECK(client_); 352 DCHECK(client_);
353 TaskSetCollection tasks_that_should_be_forced_to_complete =
354 client_->TasksThatShouldBeForcedToComplete();
341 bool should_force_some_uploads_to_complete = 355 bool should_force_some_uploads_to_complete =
342 shutdown_ || client_->ShouldForceTasksRequiredForActivationToComplete(); 356 shutdown_ || tasks_that_should_be_forced_to_complete.any();
343 357
344 if (should_force_some_uploads_to_complete) { 358 if (should_force_some_uploads_to_complete) {
345 RasterTask::Vector tasks_with_uploads_to_force; 359 RasterTask::Vector tasks_with_uploads_to_force;
346 RasterTaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); 360 RasterTaskDeque::iterator it = raster_tasks_with_pending_upload_.begin();
347 while (it != raster_tasks_with_pending_upload_.end()) { 361 while (it != raster_tasks_with_pending_upload_.end()) {
348 RasterTask* task = it->get(); 362 RasterTask* task = it->get();
349 RasterTaskState::Vector::const_iterator state_it = 363 RasterTaskState::Vector::const_iterator state_it =
350 std::find_if(raster_task_states_.begin(), 364 std::find_if(raster_task_states_.begin(),
351 raster_task_states_.end(), 365 raster_task_states_.end(),
352 RasterTaskState::TaskComparator(task)); 366 RasterTaskState::TaskComparator(task));
353 DCHECK(state_it != raster_task_states_.end()); 367 DCHECK(state_it != raster_task_states_.end());
354 const RasterTaskState& state = *state_it; 368 const RasterTaskState& state = *state_it;
355 369
356 // Force all uploads required for activation to complete. 370 // Force all uploads to complete for which the client requests to do so.
357 // During shutdown, force all pending uploads to complete. 371 // During shutdown, force all pending uploads to complete.
358 if (shutdown_ || state.required_for_activation) { 372 if (shutdown_ ||
373 (state.task_sets & tasks_that_should_be_forced_to_complete).any()) {
359 tasks_with_uploads_to_force.push_back(task); 374 tasks_with_uploads_to_force.push_back(task);
360 tasks_with_completed_uploads.push_back(task); 375 tasks_with_completed_uploads.push_back(task);
361 it = raster_tasks_with_pending_upload_.erase(it); 376 it = raster_tasks_with_pending_upload_.erase(it);
362 continue; 377 continue;
363 } 378 }
364 379
365 ++it; 380 ++it;
366 } 381 }
367 382
368 // Force uploads in reverse order. Since forcing can cause a wait on 383 // Force uploads in reverse order. Since forcing can cause a wait on
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // Async set pixels commands are not necessarily processed in-sequence with 416 // Async set pixels commands are not necessarily processed in-sequence with
402 // drawing commands. Read lock fences are required to ensure that async 417 // drawing commands. Read lock fences are required to ensure that async
403 // commands don't access the resource while used for drawing. 418 // commands don't access the resource while used for drawing.
404 resource_provider_->EnableReadLockFences(task->resource()->id()); 419 resource_provider_->EnableReadLockFences(task->resource()->id());
405 420
406 DCHECK(std::find(completed_raster_tasks_.begin(), 421 DCHECK(std::find(completed_raster_tasks_.begin(),
407 completed_raster_tasks_.end(), 422 completed_raster_tasks_.end(),
408 task) == completed_raster_tasks_.end()); 423 task) == completed_raster_tasks_.end());
409 completed_raster_tasks_.push_back(task); 424 completed_raster_tasks_.push_back(task);
410 state.type = RasterTaskState::COMPLETED; 425 state.type = RasterTaskState::COMPLETED;
411 DCHECK_LE(static_cast<size_t>(state.required_for_activation), 426 // Triggers if the current task belongs to a set that should be empty.
412 raster_tasks_required_for_activation_count_); 427 DCHECK((state.task_sets & ~TaskCountsToTaskSets(task_counts_)).none());
413 raster_tasks_required_for_activation_count_ -= 428 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets);
414 state.required_for_activation;
415 } 429 }
416 } 430 }
417 431
418 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { 432 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() {
419 TRACE_EVENT0("cc", 433 TRACE_EVENT0("cc",
420 "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); 434 "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks");
421 435
422 // Since this function can be called directly, cancel any pending checks. 436 // Since this function can be called directly, cancel any pending checks.
423 check_for_completed_raster_task_notifier_.Cancel(); 437 check_for_completed_raster_task_notifier_.Cancel();
424 438
425 DCHECK(should_notify_client_if_no_tasks_are_pending_); 439 DCHECK(should_notify_client_if_no_tasks_are_pending_.any());
426 440
427 CheckForCompletedRasterizerTasks(); 441 CheckForCompletedRasterizerTasks();
428 CheckForCompletedUploads(); 442 CheckForCompletedUploads();
429 FlushUploads(); 443 FlushUploads();
430 444
431 // Determine what client notifications to generate. 445 // Determine what client notifications to generate.
432 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = 446 TaskSetCollection will_notify_client_that_no_tasks_are_pending =
433 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && 447 should_notify_client_if_no_tasks_are_pending_ &
434 !raster_required_for_activation_finished_task_pending_ && 448 ~raster_finished_tasks_pending_ & ~PendingTasks();
435 !HasPendingTasksRequiredForActivation());
436 bool will_notify_client_that_no_tasks_are_pending =
437 (should_notify_client_if_no_tasks_are_pending_ &&
438 !raster_required_for_activation_finished_task_pending_ &&
439 !raster_finished_task_pending_ && !HasPendingTasks());
440 449
441 // Adjust the need to generate notifications before scheduling more tasks. 450 // Adjust the need to generate notifications before scheduling more tasks.
442 should_notify_client_if_no_tasks_required_for_activation_are_pending_ &=
443 !will_notify_client_that_no_tasks_required_for_activation_are_pending;
444 should_notify_client_if_no_tasks_are_pending_ &= 451 should_notify_client_if_no_tasks_are_pending_ &=
445 !will_notify_client_that_no_tasks_are_pending; 452 ~will_notify_client_that_no_tasks_are_pending;
446 453
447 scheduled_raster_task_count_ = 0; 454 scheduled_raster_task_count_ = 0;
448 if (PendingRasterTaskCount()) 455 if (PendingRasterTaskCount())
449 ScheduleMoreTasks(); 456 ScheduleMoreTasks();
450 457
451 TRACE_EVENT_ASYNC_STEP_INTO1( 458 TRACE_EVENT_ASYNC_STEP_INTO1(
452 "cc", "ScheduledTasks", this, StateName(), "state", StateAsValue()); 459 "cc", "ScheduledTasks", this, StateName(), "state", StateAsValue());
453 460
454 // Schedule another check for completed raster tasks while there are 461 // Schedule another check for completed raster tasks while there are
455 // pending raster tasks or pending uploads. 462 // pending raster tasks or pending uploads.
456 if (HasPendingTasks()) 463 if (PendingTasks().any())
457 check_for_completed_raster_task_notifier_.Schedule(); 464 check_for_completed_raster_task_notifier_.Schedule();
458 465
466 if (should_notify_client_if_no_tasks_are_pending_.none())
467 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
468
459 // Generate client notifications. 469 // Generate client notifications.
460 if (will_notify_client_that_no_tasks_required_for_activation_are_pending) { 470 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
461 DCHECK(!HasPendingTasksRequiredForActivation()); 471 if (will_notify_client_that_no_tasks_are_pending[task_set]) {
462 client_->DidFinishRunningTasksRequiredForActivation(); 472 DCHECK(!PendingTasks()[task_set]);
463 } 473 client_->DidFinishRunningTasks(task_set);
464 if (will_notify_client_that_no_tasks_are_pending) { 474 }
465 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
466 DCHECK(!HasPendingTasksRequiredForActivation());
467 client_->DidFinishRunningTasks();
468 } 475 }
469 } 476 }
470 477
471 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { 478 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() {
472 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); 479 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks");
473 480
474 RasterTaskVector tasks; 481 RasterTaskVector tasks;
475 RasterTaskVector tasks_required_for_activation; 482 RasterTaskVector tasks_in_set[kNumberOfTaskSets];
476 483
477 unsigned priority = kRasterTaskPriorityBase; 484 unsigned priority = kRasterTaskPriorityBase;
478 485
479 graph_.Reset(); 486 graph_.Reset();
480 487
481 size_t bytes_pending_upload = bytes_pending_upload_; 488 size_t bytes_pending_upload = bytes_pending_upload_;
482 bool did_throttle_raster_tasks = false; 489 TaskSetCollection did_throttle_raster_tasks;
483 bool did_throttle_raster_tasks_required_for_activation = false;
484 490
485 for (RasterTaskQueue::Item::Vector::const_iterator it = 491 for (RasterTaskQueue::Item::Vector::const_iterator it =
486 raster_tasks_.items.begin(); 492 raster_tasks_.items.begin();
487 it != raster_tasks_.items.end(); 493 it != raster_tasks_.items.end();
488 ++it) { 494 ++it) {
489 const RasterTaskQueue::Item& item = *it; 495 const RasterTaskQueue::Item& item = *it;
490 RasterTask* task = item.task; 496 RasterTask* task = item.task;
491 497
492 // |raster_task_states_| contains the state of all tasks that we have not 498 // |raster_task_states_| contains the state of all tasks that we have not
493 // yet run reply callbacks for. 499 // yet run reply callbacks for.
(...skipping 14 matching lines...) Expand all
508 continue; 514 continue;
509 } 515 }
510 516
511 // All raster tasks need to be throttled by bytes of pending uploads, 517 // All raster tasks need to be throttled by bytes of pending uploads,
512 // but if it's the only task allow it to complete no matter what its size, 518 // but if it's the only task allow it to complete no matter what its size,
513 // to prevent starvation of the task queue. 519 // to prevent starvation of the task queue.
514 size_t new_bytes_pending_upload = bytes_pending_upload; 520 size_t new_bytes_pending_upload = bytes_pending_upload;
515 new_bytes_pending_upload += task->resource()->bytes(); 521 new_bytes_pending_upload += task->resource()->bytes();
516 if (new_bytes_pending_upload > max_bytes_pending_upload_ && 522 if (new_bytes_pending_upload > max_bytes_pending_upload_ &&
517 bytes_pending_upload) { 523 bytes_pending_upload) {
518 did_throttle_raster_tasks = true; 524 did_throttle_raster_tasks |= item.task_sets;
519 if (item.required_for_activation)
520 did_throttle_raster_tasks_required_for_activation = true;
521 continue; 525 continue;
522 } 526 }
523 527
524 // If raster has finished, just update |bytes_pending_upload|. 528 // If raster has finished, just update |bytes_pending_upload|.
525 if (state.type == RasterTaskState::UPLOADING) { 529 if (state.type == RasterTaskState::UPLOADING) {
526 DCHECK(!task->HasCompleted()); 530 DCHECK(!task->HasCompleted());
527 bytes_pending_upload = new_bytes_pending_upload; 531 bytes_pending_upload = new_bytes_pending_upload;
528 continue; 532 continue;
529 } 533 }
530 534
531 // Throttle raster tasks based on kMaxScheduledRasterTasks. 535 // Throttle raster tasks based on kMaxScheduledRasterTasks.
532 if (tasks.container().size() >= kMaxScheduledRasterTasks) { 536 if (tasks.container().size() >= kMaxScheduledRasterTasks) {
533 did_throttle_raster_tasks = true; 537 did_throttle_raster_tasks |= item.task_sets;
534 if (item.required_for_activation)
535 did_throttle_raster_tasks_required_for_activation = true;
536 continue; 538 continue;
537 } 539 }
538 540
539 // Update |bytes_pending_upload| now that task has cleared all 541 // Update |bytes_pending_upload| now that task has cleared all
540 // throttling limits. 542 // throttling limits.
541 bytes_pending_upload = new_bytes_pending_upload; 543 bytes_pending_upload = new_bytes_pending_upload;
542 544
543 DCHECK(state.type == RasterTaskState::UNSCHEDULED || 545 DCHECK(state.type == RasterTaskState::UNSCHEDULED ||
544 state.type == RasterTaskState::SCHEDULED); 546 state.type == RasterTaskState::SCHEDULED);
545 state.type = RasterTaskState::SCHEDULED; 547 state.type = RasterTaskState::SCHEDULED;
546 548
547 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); 549 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++);
548 550
549 tasks.container().push_back(task); 551 tasks.container().push_back(task);
550 if (item.required_for_activation) 552 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
551 tasks_required_for_activation.container().push_back(task); 553 if (item.task_sets[task_set])
554 tasks_in_set[task_set].container().push_back(task);
555 }
552 } 556 }
553 557
554 // Cancel existing OnRasterFinished callbacks. 558 // Cancel existing OnRasterFinished callbacks.
555 raster_finished_weak_ptr_factory_.InvalidateWeakPtrs(); 559 raster_finished_weak_ptr_factory_.InvalidateWeakPtrs();
556 560
557 scoped_refptr<RasterizerTask> 561 scoped_refptr<RasterizerTask> new_raster_finished_tasks[kNumberOfTaskSets];
558 new_raster_required_for_activation_finished_task; 562 size_t scheduled_task_counts[kNumberOfTaskSets] = {0};
559 563
560 size_t scheduled_raster_task_required_for_activation_count = 564 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
561 tasks_required_for_activation.container().size(); 565 scheduled_task_counts[task_set] = tasks_in_set[task_set].container().size();
562 DCHECK_LE(scheduled_raster_task_required_for_activation_count, 566 DCHECK_LE(scheduled_task_counts[task_set], task_counts_[task_set]);
563 raster_tasks_required_for_activation_count_); 567 // Schedule OnRasterTasksRequiredForActivationFinished call only when
564 // Schedule OnRasterTasksRequiredForActivationFinished call only when 568 // notification is pending and throttling is not preventing all pending
565 // notification is pending and throttling is not preventing all pending 569 // tasks required for activation from being scheduled.
566 // tasks required for activation from being scheduled. 570 if (!did_throttle_raster_tasks[task_set] &&
567 if (!did_throttle_raster_tasks_required_for_activation && 571 should_notify_client_if_no_tasks_are_pending_[task_set]) {
568 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { 572 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask(
569 new_raster_required_for_activation_finished_task = CreateRasterFinishedTask( 573 task_runner_.get(),
570 task_runner_.get(), 574 base::Bind(&PixelBufferRasterWorkerPool::OnRasterFinished,
571 base::Bind( 575 raster_finished_weak_ptr_factory_.GetWeakPtr(),
572 &PixelBufferRasterWorkerPool::OnRasterRequiredForActivationFinished, 576 task_set));
573 raster_finished_weak_ptr_factory_.GetWeakPtr())); 577 raster_finished_tasks_pending_[task_set] = true;
574 raster_required_for_activation_finished_task_pending_ = true; 578 InsertNodeForTask(&graph_,
575 InsertNodeForTask(&graph_, 579 new_raster_finished_tasks[task_set].get(),
576 new_raster_required_for_activation_finished_task.get(), 580 kRasterFinishedTaskPriority,
577 kRasterRequiredForActivationFinishedTaskPriority, 581 scheduled_task_counts[task_set]);
578 scheduled_raster_task_required_for_activation_count); 582 for (RasterTaskVector::ContainerType::const_iterator it =
579 for (RasterTaskVector::ContainerType::const_iterator it = 583 tasks_in_set[task_set].container().begin();
580 tasks_required_for_activation.container().begin(); 584 it != tasks_in_set[task_set].container().end();
581 it != tasks_required_for_activation.container().end(); 585 ++it) {
582 ++it) { 586 graph_.edges.push_back(
583 graph_.edges.push_back(TaskGraph::Edge( 587 TaskGraph::Edge(*it, new_raster_finished_tasks[task_set].get()));
584 *it, new_raster_required_for_activation_finished_task.get())); 588 }
585 } 589 }
586 } 590 }
587 591
588 scoped_refptr<RasterizerTask> new_raster_finished_task;
589
590 size_t scheduled_raster_task_count = tasks.container().size(); 592 size_t scheduled_raster_task_count = tasks.container().size();
591 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); 593 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount());
592 // Schedule OnRasterTasksFinished call only when notification is pending
593 // and throttling is not preventing all pending tasks from being scheduled.
594 if (!did_throttle_raster_tasks &&
595 should_notify_client_if_no_tasks_are_pending_) {
596 new_raster_finished_task = CreateRasterFinishedTask(
597 task_runner_.get(),
598 base::Bind(&PixelBufferRasterWorkerPool::OnRasterFinished,
599 raster_finished_weak_ptr_factory_.GetWeakPtr()));
600 raster_finished_task_pending_ = true;
601 InsertNodeForTask(&graph_,
602 new_raster_finished_task.get(),
603 kRasterFinishedTaskPriority,
604 scheduled_raster_task_count);
605 for (RasterTaskVector::ContainerType::const_iterator it =
606 tasks.container().begin();
607 it != tasks.container().end();
608 ++it) {
609 graph_.edges.push_back(
610 TaskGraph::Edge(*it, new_raster_finished_task.get()));
611 }
612 }
613 594
614 ScheduleTasksOnOriginThread(this, &graph_); 595 ScheduleTasksOnOriginThread(this, &graph_);
615 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); 596 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_);
616 597
617 scheduled_raster_task_count_ = scheduled_raster_task_count; 598 scheduled_raster_task_count_ = scheduled_raster_task_count;
618 599
619 raster_finished_task_ = new_raster_finished_task; 600 std::copy(new_raster_finished_tasks,
620 raster_required_for_activation_finished_task_ = 601 new_raster_finished_tasks + kNumberOfTaskSets,
621 new_raster_required_for_activation_finished_task; 602 raster_finished_tasks_);
622 } 603 }
623 604
624 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { 605 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const {
625 unsigned num_completed_raster_tasks = 606 unsigned num_completed_raster_tasks =
626 raster_tasks_with_pending_upload_.size() + completed_raster_tasks_.size(); 607 raster_tasks_with_pending_upload_.size() + completed_raster_tasks_.size();
627 DCHECK_GE(raster_task_states_.size(), num_completed_raster_tasks); 608 DCHECK_GE(raster_task_states_.size(), num_completed_raster_tasks);
628 return raster_task_states_.size() - num_completed_raster_tasks; 609 return raster_task_states_.size() - num_completed_raster_tasks;
629 } 610 }
630 611
631 bool PixelBufferRasterWorkerPool::HasPendingTasks() const { 612 TaskSetCollection PixelBufferRasterWorkerPool::PendingTasks() const {
632 return PendingRasterTaskCount() || !raster_tasks_with_pending_upload_.empty(); 613 return TaskCountsToTaskSets(task_counts_);
633 }
634
635 bool PixelBufferRasterWorkerPool::HasPendingTasksRequiredForActivation() const {
636 return !!raster_tasks_required_for_activation_count_;
637 } 614 }
638 615
639 const char* PixelBufferRasterWorkerPool::StateName() const { 616 const char* PixelBufferRasterWorkerPool::StateName() const {
640 if (scheduled_raster_task_count_) 617 if (scheduled_raster_task_count_)
641 return "rasterizing"; 618 return "rasterizing";
642 if (PendingRasterTaskCount()) 619 if (PendingRasterTaskCount())
643 return "throttled"; 620 return "throttled";
644 if (!raster_tasks_with_pending_upload_.empty()) 621 if (!raster_tasks_with_pending_upload_.empty())
645 return "waiting_for_uploads"; 622 return "waiting_for_uploads";
646 623
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (item_it != raster_tasks_.items.end()) { 669 if (item_it != raster_tasks_.items.end()) {
693 state.type = RasterTaskState::UNSCHEDULED; 670 state.type = RasterTaskState::UNSCHEDULED;
694 continue; 671 continue;
695 } 672 }
696 673
697 DCHECK(std::find(completed_raster_tasks_.begin(), 674 DCHECK(std::find(completed_raster_tasks_.begin(),
698 completed_raster_tasks_.end(), 675 completed_raster_tasks_.end(),
699 raster_task) == completed_raster_tasks_.end()); 676 raster_task) == completed_raster_tasks_.end());
700 completed_raster_tasks_.push_back(raster_task); 677 completed_raster_tasks_.push_back(raster_task);
701 state.type = RasterTaskState::COMPLETED; 678 state.type = RasterTaskState::COMPLETED;
702 DCHECK_LE(static_cast<size_t>(state.required_for_activation), 679 // Triggers if the current task belongs to a set that should be empty.
703 raster_tasks_required_for_activation_count_); 680 DCHECK((state.task_sets & ~TaskCountsToTaskSets(task_counts_)).none());
704 raster_tasks_required_for_activation_count_ -= 681 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets);
705 state.required_for_activation;
706 continue; 682 continue;
707 } 683 }
708 684
709 resource_provider_->BeginSetPixels(raster_task->resource()->id()); 685 resource_provider_->BeginSetPixels(raster_task->resource()->id());
710 has_performed_uploads_since_last_flush_ = true; 686 has_performed_uploads_since_last_flush_ = true;
711 687
712 bytes_pending_upload_ += raster_task->resource()->bytes(); 688 bytes_pending_upload_ += raster_task->resource()->bytes();
713 raster_tasks_with_pending_upload_.push_back(raster_task); 689 raster_tasks_with_pending_upload_.push_back(raster_task);
714 state.type = RasterTaskState::UPLOADING; 690 state.type = RasterTaskState::UPLOADING;
715 } 691 }
716 completed_tasks_.clear(); 692 completed_tasks_.clear();
717 } 693 }
718 694
719 scoped_refptr<base::debug::ConvertableToTraceFormat> 695 scoped_refptr<base::debug::ConvertableToTraceFormat>
720 PixelBufferRasterWorkerPool::StateAsValue() const { 696 PixelBufferRasterWorkerPool::StateAsValue() const {
721 scoped_refptr<base::debug::TracedValue> state = 697 scoped_refptr<base::debug::TracedValue> state =
722 new base::debug::TracedValue(); 698 new base::debug::TracedValue();
723 state->SetInteger("completed_count", completed_raster_tasks_.size()); 699 state->SetInteger("completed_count", completed_raster_tasks_.size());
724 state->SetInteger("pending_count", raster_task_states_.size()); 700 state->BeginArray("pending_count");
701 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set)
702 state->AppendInteger(task_counts_[task_set]);
703 state->EndArray();
725 state->SetInteger("pending_upload_count", 704 state->SetInteger("pending_upload_count",
726 raster_tasks_with_pending_upload_.size()); 705 raster_tasks_with_pending_upload_.size());
727 state->SetInteger("pending_required_for_activation_count",
728 raster_tasks_required_for_activation_count_);
729 state->BeginDictionary("throttle_state"); 706 state->BeginDictionary("throttle_state");
730 ThrottleStateAsValueInto(state.get()); 707 ThrottleStateAsValueInto(state.get());
731 state->EndDictionary(); 708 state->EndDictionary();
732 return state; 709 return state;
733 } 710 }
734 711
735 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto( 712 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto(
736 base::debug::TracedValue* throttle_state) const { 713 base::debug::TracedValue* throttle_state) const {
737 throttle_state->SetInteger("bytes_available_for_upload", 714 throttle_state->SetInteger("bytes_available_for_upload",
738 max_bytes_pending_upload_ - bytes_pending_upload_); 715 max_bytes_pending_upload_ - bytes_pending_upload_);
739 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); 716 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_);
740 throttle_state->SetInteger("scheduled_raster_task_count", 717 throttle_state->SetInteger("scheduled_raster_task_count",
741 scheduled_raster_task_count_); 718 scheduled_raster_task_count_);
742 } 719 }
743 720
744 } // namespace cc 721 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698