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

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: rebase 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) {
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) {
35 TaskSetCollection task_set_collection;
36 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
37 if (task_counts[task_set] > 0)
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 }
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_EVENT2("cc",
305 "PixelBufferRasterWorkerPool::OnRasterFinished",
306 "task_set",
307 task_set,
308 "should_notify_client_if_no_tasks_are_pending_[task_set]",
309 should_notify_client_if_no_tasks_are_pending_[task_set]);
277 310
278 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as 311 // There's no need to call CheckForCompletedRasterTasks() if the client has
279 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to 312 // already been notified.
280 // perform another check in that case as we've already notified the client. 313 if (!should_notify_client_if_no_tasks_are_pending_[task_set])
281 if (!should_notify_client_if_no_tasks_are_pending_)
282 return; 314 return;
283 raster_finished_task_pending_ = false; 315 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_EVENT1(
294 "cc",
295 "PixelBufferRasterWorkerPool::OnRasterRequiredForActivationFinished",
296 "should_notify_client_if_no_tasks_required_for_activation_are_pending",
297 should_notify_client_if_no_tasks_required_for_activation_are_pending_);
298
299 // Analogous to OnRasterTasksFinished(), there's no need to call
300 // CheckForCompletedRasterTasks() if the client has already been notified.
301 if (!should_notify_client_if_no_tasks_required_for_activation_are_pending_)
302 return;
303 raster_required_for_activation_finished_task_pending_ = false;
304 316
305 // This reduces latency between the time when all tasks required for 317 // This reduces latency between the time when all tasks required for
306 // activation have finished running and the time when the client is 318 // activation have finished running and the time when the client is
307 // notified. 319 // notified.
308 CheckForCompletedRasterTasks(); 320 CheckForCompletedRasterTasks();
309 } 321 }
310 322
311 void PixelBufferRasterWorkerPool::FlushUploads() { 323 void PixelBufferRasterWorkerPool::FlushUploads() {
312 if (!has_performed_uploads_since_last_flush_) 324 if (!has_performed_uploads_since_last_flush_)
313 return; 325 return;
(...skipping 19 matching lines...) Expand all
333 345
334 // Uploads complete in the order they are issued. 346 // Uploads complete in the order they are issued.
335 if (!resource_provider_->DidSetPixelsComplete(task->resource()->id())) 347 if (!resource_provider_->DidSetPixelsComplete(task->resource()->id()))
336 break; 348 break;
337 349
338 tasks_with_completed_uploads.push_back(task); 350 tasks_with_completed_uploads.push_back(task);
339 raster_tasks_with_pending_upload_.pop_front(); 351 raster_tasks_with_pending_upload_.pop_front();
340 } 352 }
341 353
342 DCHECK(client_); 354 DCHECK(client_);
355 TaskSetCollection tasks_that_should_be_forced_to_complete =
356 client_->TasksThatShouldBeForcedToComplete();
343 bool should_force_some_uploads_to_complete = 357 bool should_force_some_uploads_to_complete =
344 shutdown_ || client_->ShouldForceTasksRequiredForActivationToComplete(); 358 shutdown_ || tasks_that_should_be_forced_to_complete.any();
345 359
346 if (should_force_some_uploads_to_complete) { 360 if (should_force_some_uploads_to_complete) {
347 RasterTask::Vector tasks_with_uploads_to_force; 361 RasterTask::Vector tasks_with_uploads_to_force;
348 RasterTaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); 362 RasterTaskDeque::iterator it = raster_tasks_with_pending_upload_.begin();
349 while (it != raster_tasks_with_pending_upload_.end()) { 363 while (it != raster_tasks_with_pending_upload_.end()) {
350 RasterTask* task = it->get(); 364 RasterTask* task = it->get();
351 RasterTaskState::Vector::const_iterator state_it = 365 RasterTaskState::Vector::const_iterator state_it =
352 std::find_if(raster_task_states_.begin(), 366 std::find_if(raster_task_states_.begin(),
353 raster_task_states_.end(), 367 raster_task_states_.end(),
354 RasterTaskState::TaskComparator(task)); 368 RasterTaskState::TaskComparator(task));
355 DCHECK(state_it != raster_task_states_.end()); 369 DCHECK(state_it != raster_task_states_.end());
356 const RasterTaskState& state = *state_it; 370 const RasterTaskState& state = *state_it;
357 371
358 // Force all uploads required for activation to complete. 372 // Force all uploads to complete for which the client requests to do so.
359 // During shutdown, force all pending uploads to complete. 373 // During shutdown, force all pending uploads to complete.
360 if (shutdown_ || state.required_for_activation) { 374 if (shutdown_ ||
375 (state.task_sets & tasks_that_should_be_forced_to_complete).any()) {
361 tasks_with_uploads_to_force.push_back(task); 376 tasks_with_uploads_to_force.push_back(task);
362 tasks_with_completed_uploads.push_back(task); 377 tasks_with_completed_uploads.push_back(task);
363 it = raster_tasks_with_pending_upload_.erase(it); 378 it = raster_tasks_with_pending_upload_.erase(it);
364 continue; 379 continue;
365 } 380 }
366 381
367 ++it; 382 ++it;
368 } 383 }
369 384
370 // Force uploads in reverse order. Since forcing can cause a wait on 385 // Force uploads in reverse order. Since forcing can cause a wait on
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // Async set pixels commands are not necessarily processed in-sequence with 418 // Async set pixels commands are not necessarily processed in-sequence with
404 // drawing commands. Read lock fences are required to ensure that async 419 // drawing commands. Read lock fences are required to ensure that async
405 // commands don't access the resource while used for drawing. 420 // commands don't access the resource while used for drawing.
406 resource_provider_->EnableReadLockFences(task->resource()->id()); 421 resource_provider_->EnableReadLockFences(task->resource()->id());
407 422
408 DCHECK(std::find(completed_raster_tasks_.begin(), 423 DCHECK(std::find(completed_raster_tasks_.begin(),
409 completed_raster_tasks_.end(), 424 completed_raster_tasks_.end(),
410 task) == completed_raster_tasks_.end()); 425 task) == completed_raster_tasks_.end());
411 completed_raster_tasks_.push_back(task); 426 completed_raster_tasks_.push_back(task);
412 state.type = RasterTaskState::COMPLETED; 427 state.type = RasterTaskState::COMPLETED;
413 DCHECK_LE(static_cast<size_t>(state.required_for_activation), 428 // Triggers if the current task belongs to a set that should be empty.
414 raster_tasks_required_for_activation_count_); 429 DCHECK((state.task_sets & ~TaskCountsToTaskSets(task_counts_)).none());
415 raster_tasks_required_for_activation_count_ -= 430 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets);
416 state.required_for_activation;
417 } 431 }
418 } 432 }
419 433
420 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { 434 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() {
421 TRACE_EVENT0("cc", 435 TRACE_EVENT0("cc",
422 "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); 436 "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks");
423 437
424 // Since this function can be called directly, cancel any pending checks. 438 // Since this function can be called directly, cancel any pending checks.
425 check_for_completed_raster_task_notifier_.Cancel(); 439 check_for_completed_raster_task_notifier_.Cancel();
426 440
427 DCHECK(should_notify_client_if_no_tasks_are_pending_); 441 DCHECK(should_notify_client_if_no_tasks_are_pending_.any());
428 442
429 CheckForCompletedRasterizerTasks(); 443 CheckForCompletedRasterizerTasks();
430 CheckForCompletedUploads(); 444 CheckForCompletedUploads();
431 FlushUploads(); 445 FlushUploads();
432 446
433 // Determine what client notifications to generate. 447 // Determine what client notifications to generate.
434 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = 448 TaskSetCollection will_notify_client_that_no_tasks_are_pending =
435 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && 449 should_notify_client_if_no_tasks_are_pending_ &
436 !raster_required_for_activation_finished_task_pending_ && 450 ~raster_finished_tasks_pending_ & ~PendingTasks();
437 !HasPendingTasksRequiredForActivation());
438 bool will_notify_client_that_no_tasks_are_pending =
439 (should_notify_client_if_no_tasks_are_pending_ &&
440 !raster_required_for_activation_finished_task_pending_ &&
441 !raster_finished_task_pending_ && !HasPendingTasks());
442 451
443 // Adjust the need to generate notifications before scheduling more tasks. 452 // Adjust the need to generate notifications before scheduling more tasks.
444 should_notify_client_if_no_tasks_required_for_activation_are_pending_ &=
445 !will_notify_client_that_no_tasks_required_for_activation_are_pending;
446 should_notify_client_if_no_tasks_are_pending_ &= 453 should_notify_client_if_no_tasks_are_pending_ &=
447 !will_notify_client_that_no_tasks_are_pending; 454 ~will_notify_client_that_no_tasks_are_pending;
448 455
449 scheduled_raster_task_count_ = 0; 456 scheduled_raster_task_count_ = 0;
450 if (PendingRasterTaskCount()) 457 if (PendingRasterTaskCount())
451 ScheduleMoreTasks(); 458 ScheduleMoreTasks();
452 459
453 TRACE_EVENT_ASYNC_STEP_INTO1( 460 TRACE_EVENT_ASYNC_STEP_INTO1(
454 "cc", "ScheduledTasks", this, StateName(), "state", StateAsValue()); 461 "cc", "ScheduledTasks", this, StateName(), "state", StateAsValue());
455 462
456 // Schedule another check for completed raster tasks while there are 463 // Schedule another check for completed raster tasks while there are
457 // pending raster tasks or pending uploads. 464 // pending raster tasks or pending uploads.
458 if (HasPendingTasks()) 465 if (PendingTasks().any())
459 check_for_completed_raster_task_notifier_.Schedule(); 466 check_for_completed_raster_task_notifier_.Schedule();
460 467
468 if (should_notify_client_if_no_tasks_are_pending_.none())
469 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
470
461 // Generate client notifications. 471 // Generate client notifications.
462 if (will_notify_client_that_no_tasks_required_for_activation_are_pending) { 472 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
463 DCHECK(!HasPendingTasksRequiredForActivation()); 473 if (will_notify_client_that_no_tasks_are_pending[task_set]) {
464 client_->DidFinishRunningTasksRequiredForActivation(); 474 DCHECK(!PendingTasks()[task_set]);
465 } 475 client_->DidFinishRunningTasks(task_set);
466 if (will_notify_client_that_no_tasks_are_pending) { 476 }
467 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
468 DCHECK(!HasPendingTasksRequiredForActivation());
469 client_->DidFinishRunningTasks();
470 } 477 }
471 } 478 }
472 479
473 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { 480 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() {
474 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); 481 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks");
475 482
476 RasterTaskVector tasks; 483 RasterTaskVector tasks;
477 RasterTaskVector tasks_required_for_activation; 484 RasterTaskVector tasks_in_set[kNumberOfTaskSets];
478 485
479 unsigned priority = kRasterTaskPriorityBase; 486 unsigned priority = kRasterTaskPriorityBase;
480 487
481 graph_.Reset(); 488 graph_.Reset();
482 489
483 size_t bytes_pending_upload = bytes_pending_upload_; 490 size_t bytes_pending_upload = bytes_pending_upload_;
484 bool did_throttle_raster_tasks = false; 491 TaskSetCollection did_throttle_raster_tasks;
485 bool did_throttle_raster_tasks_required_for_activation = false;
486 492
487 for (RasterTaskQueue::Item::Vector::const_iterator it = 493 for (RasterTaskQueue::Item::Vector::const_iterator it =
488 raster_tasks_.items.begin(); 494 raster_tasks_.items.begin();
489 it != raster_tasks_.items.end(); 495 it != raster_tasks_.items.end();
490 ++it) { 496 ++it) {
491 const RasterTaskQueue::Item& item = *it; 497 const RasterTaskQueue::Item& item = *it;
492 RasterTask* task = item.task; 498 RasterTask* task = item.task;
493 499
494 // |raster_task_states_| contains the state of all tasks that we have not 500 // |raster_task_states_| contains the state of all tasks that we have not
495 // yet run reply callbacks for. 501 // yet run reply callbacks for.
(...skipping 14 matching lines...) Expand all
510 continue; 516 continue;
511 } 517 }
512 518
513 // All raster tasks need to be throttled by bytes of pending uploads, 519 // All raster tasks need to be throttled by bytes of pending uploads,
514 // but if it's the only task allow it to complete no matter what its size, 520 // but if it's the only task allow it to complete no matter what its size,
515 // to prevent starvation of the task queue. 521 // to prevent starvation of the task queue.
516 size_t new_bytes_pending_upload = bytes_pending_upload; 522 size_t new_bytes_pending_upload = bytes_pending_upload;
517 new_bytes_pending_upload += task->resource()->bytes(); 523 new_bytes_pending_upload += task->resource()->bytes();
518 if (new_bytes_pending_upload > max_bytes_pending_upload_ && 524 if (new_bytes_pending_upload > max_bytes_pending_upload_ &&
519 bytes_pending_upload) { 525 bytes_pending_upload) {
520 did_throttle_raster_tasks = true; 526 did_throttle_raster_tasks |= item.task_sets;
521 if (item.required_for_activation)
522 did_throttle_raster_tasks_required_for_activation = true;
523 continue; 527 continue;
524 } 528 }
525 529
526 // If raster has finished, just update |bytes_pending_upload|. 530 // If raster has finished, just update |bytes_pending_upload|.
527 if (state.type == RasterTaskState::UPLOADING) { 531 if (state.type == RasterTaskState::UPLOADING) {
528 DCHECK(!task->HasCompleted()); 532 DCHECK(!task->HasCompleted());
529 bytes_pending_upload = new_bytes_pending_upload; 533 bytes_pending_upload = new_bytes_pending_upload;
530 continue; 534 continue;
531 } 535 }
532 536
533 // Throttle raster tasks based on kMaxScheduledRasterTasks. 537 // Throttle raster tasks based on kMaxScheduledRasterTasks.
534 if (tasks.container().size() >= kMaxScheduledRasterTasks) { 538 if (tasks.container().size() >= kMaxScheduledRasterTasks) {
535 did_throttle_raster_tasks = true; 539 did_throttle_raster_tasks |= item.task_sets;
536 if (item.required_for_activation)
537 did_throttle_raster_tasks_required_for_activation = true;
538 continue; 540 continue;
539 } 541 }
540 542
541 // Update |bytes_pending_upload| now that task has cleared all 543 // Update |bytes_pending_upload| now that task has cleared all
542 // throttling limits. 544 // throttling limits.
543 bytes_pending_upload = new_bytes_pending_upload; 545 bytes_pending_upload = new_bytes_pending_upload;
544 546
545 DCHECK(state.type == RasterTaskState::UNSCHEDULED || 547 DCHECK(state.type == RasterTaskState::UNSCHEDULED ||
546 state.type == RasterTaskState::SCHEDULED); 548 state.type == RasterTaskState::SCHEDULED);
547 state.type = RasterTaskState::SCHEDULED; 549 state.type = RasterTaskState::SCHEDULED;
548 550
549 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); 551 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++);
550 552
551 tasks.container().push_back(task); 553 tasks.container().push_back(task);
552 if (item.required_for_activation) 554 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
553 tasks_required_for_activation.container().push_back(task); 555 if (item.task_sets[task_set])
556 tasks_in_set[task_set].container().push_back(task);
557 }
554 } 558 }
555 559
556 // Cancel existing OnRasterFinished callbacks. 560 // Cancel existing OnRasterFinished callbacks.
557 raster_finished_weak_ptr_factory_.InvalidateWeakPtrs(); 561 raster_finished_weak_ptr_factory_.InvalidateWeakPtrs();
558 562
559 scoped_refptr<RasterizerTask> 563 scoped_refptr<RasterizerTask> new_raster_finished_tasks[kNumberOfTaskSets];
560 new_raster_required_for_activation_finished_task; 564 size_t scheduled_task_counts[kNumberOfTaskSets] = {0};
561 565
562 size_t scheduled_raster_task_required_for_activation_count = 566 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
563 tasks_required_for_activation.container().size(); 567 scheduled_task_counts[task_set] = tasks_in_set[task_set].container().size();
564 DCHECK_LE(scheduled_raster_task_required_for_activation_count, 568 DCHECK_LE(scheduled_task_counts[task_set], task_counts_[task_set]);
565 raster_tasks_required_for_activation_count_); 569 // Schedule OnRasterTasksRequiredForActivationFinished call only when
566 // Schedule OnRasterTasksRequiredForActivationFinished call only when 570 // notification is pending and throttling is not preventing all pending
567 // notification is pending and throttling is not preventing all pending 571 // tasks required for activation from being scheduled.
568 // tasks required for activation from being scheduled. 572 if (!did_throttle_raster_tasks[task_set] &&
569 if (!did_throttle_raster_tasks_required_for_activation && 573 should_notify_client_if_no_tasks_are_pending_[task_set]) {
570 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { 574 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask(
571 new_raster_required_for_activation_finished_task = CreateRasterFinishedTask( 575 task_runner_.get(),
572 task_runner_.get(), 576 base::Bind(&PixelBufferRasterWorkerPool::OnRasterFinished,
573 base::Bind( 577 raster_finished_weak_ptr_factory_.GetWeakPtr(),
574 &PixelBufferRasterWorkerPool::OnRasterRequiredForActivationFinished, 578 task_set));
575 raster_finished_weak_ptr_factory_.GetWeakPtr())); 579 raster_finished_tasks_pending_[task_set] = true;
576 raster_required_for_activation_finished_task_pending_ = true; 580 InsertNodeForTask(&graph_,
577 InsertNodeForTask(&graph_, 581 new_raster_finished_tasks[task_set].get(),
578 new_raster_required_for_activation_finished_task.get(), 582 kRasterFinishedTaskPriority,
579 kRasterRequiredForActivationFinishedTaskPriority, 583 scheduled_task_counts[task_set]);
580 scheduled_raster_task_required_for_activation_count); 584 for (RasterTaskVector::ContainerType::const_iterator it =
581 for (RasterTaskVector::ContainerType::const_iterator it = 585 tasks_in_set[task_set].container().begin();
582 tasks_required_for_activation.container().begin(); 586 it != tasks_in_set[task_set].container().end();
583 it != tasks_required_for_activation.container().end(); 587 ++it) {
584 ++it) { 588 graph_.edges.push_back(
585 graph_.edges.push_back(TaskGraph::Edge( 589 TaskGraph::Edge(*it, new_raster_finished_tasks[task_set].get()));
586 *it, new_raster_required_for_activation_finished_task.get())); 590 }
587 } 591 }
588 } 592 }
589 593
590 scoped_refptr<RasterizerTask> new_raster_finished_task;
591
592 size_t scheduled_raster_task_count = tasks.container().size(); 594 size_t scheduled_raster_task_count = tasks.container().size();
593 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); 595 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount());
594 // Schedule OnRasterTasksFinished call only when notification is pending
595 // and throttling is not preventing all pending tasks from being scheduled.
596 if (!did_throttle_raster_tasks &&
597 should_notify_client_if_no_tasks_are_pending_) {
598 new_raster_finished_task = CreateRasterFinishedTask(
599 task_runner_.get(),
600 base::Bind(&PixelBufferRasterWorkerPool::OnRasterFinished,
601 raster_finished_weak_ptr_factory_.GetWeakPtr()));
602 raster_finished_task_pending_ = true;
603 InsertNodeForTask(&graph_,
604 new_raster_finished_task.get(),
605 kRasterFinishedTaskPriority,
606 scheduled_raster_task_count);
607 for (RasterTaskVector::ContainerType::const_iterator it =
608 tasks.container().begin();
609 it != tasks.container().end();
610 ++it) {
611 graph_.edges.push_back(
612 TaskGraph::Edge(*it, new_raster_finished_task.get()));
613 }
614 }
615 596
616 ScheduleTasksOnOriginThread(this, &graph_); 597 ScheduleTasksOnOriginThread(this, &graph_);
617 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); 598 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_);
618 599
619 scheduled_raster_task_count_ = scheduled_raster_task_count; 600 scheduled_raster_task_count_ = scheduled_raster_task_count;
620 601
621 raster_finished_task_ = new_raster_finished_task; 602 std::copy(new_raster_finished_tasks,
622 raster_required_for_activation_finished_task_ = 603 new_raster_finished_tasks + kNumberOfTaskSets,
623 new_raster_required_for_activation_finished_task; 604 raster_finished_tasks_);
624 } 605 }
625 606
626 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { 607 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const {
627 unsigned num_completed_raster_tasks = 608 unsigned num_completed_raster_tasks =
628 raster_tasks_with_pending_upload_.size() + completed_raster_tasks_.size(); 609 raster_tasks_with_pending_upload_.size() + completed_raster_tasks_.size();
629 DCHECK_GE(raster_task_states_.size(), num_completed_raster_tasks); 610 DCHECK_GE(raster_task_states_.size(), num_completed_raster_tasks);
630 return raster_task_states_.size() - num_completed_raster_tasks; 611 return raster_task_states_.size() - num_completed_raster_tasks;
631 } 612 }
632 613
633 bool PixelBufferRasterWorkerPool::HasPendingTasks() const { 614 TaskSetCollection PixelBufferRasterWorkerPool::PendingTasks() const {
634 return PendingRasterTaskCount() || !raster_tasks_with_pending_upload_.empty(); 615 return TaskCountsToTaskSets(task_counts_);
635 }
636
637 bool PixelBufferRasterWorkerPool::HasPendingTasksRequiredForActivation() const {
638 return !!raster_tasks_required_for_activation_count_;
639 } 616 }
640 617
641 const char* PixelBufferRasterWorkerPool::StateName() const { 618 const char* PixelBufferRasterWorkerPool::StateName() const {
642 if (scheduled_raster_task_count_) 619 if (scheduled_raster_task_count_)
643 return "rasterizing"; 620 return "rasterizing";
644 if (PendingRasterTaskCount()) 621 if (PendingRasterTaskCount())
645 return "throttled"; 622 return "throttled";
646 if (!raster_tasks_with_pending_upload_.empty()) 623 if (!raster_tasks_with_pending_upload_.empty())
647 return "waiting_for_uploads"; 624 return "waiting_for_uploads";
648 625
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 if (item_it != raster_tasks_.items.end()) { 671 if (item_it != raster_tasks_.items.end()) {
695 state.type = RasterTaskState::UNSCHEDULED; 672 state.type = RasterTaskState::UNSCHEDULED;
696 continue; 673 continue;
697 } 674 }
698 675
699 DCHECK(std::find(completed_raster_tasks_.begin(), 676 DCHECK(std::find(completed_raster_tasks_.begin(),
700 completed_raster_tasks_.end(), 677 completed_raster_tasks_.end(),
701 raster_task) == completed_raster_tasks_.end()); 678 raster_task) == completed_raster_tasks_.end());
702 completed_raster_tasks_.push_back(raster_task); 679 completed_raster_tasks_.push_back(raster_task);
703 state.type = RasterTaskState::COMPLETED; 680 state.type = RasterTaskState::COMPLETED;
704 DCHECK_LE(static_cast<size_t>(state.required_for_activation), 681 // Triggers if the current task belongs to a set that should be empty.
705 raster_tasks_required_for_activation_count_); 682 DCHECK((state.task_sets & ~TaskCountsToTaskSets(task_counts_)).none());
706 raster_tasks_required_for_activation_count_ -= 683 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets);
707 state.required_for_activation;
708 continue; 684 continue;
709 } 685 }
710 686
711 resource_provider_->BeginSetPixels(raster_task->resource()->id()); 687 resource_provider_->BeginSetPixels(raster_task->resource()->id());
712 has_performed_uploads_since_last_flush_ = true; 688 has_performed_uploads_since_last_flush_ = true;
713 689
714 bytes_pending_upload_ += raster_task->resource()->bytes(); 690 bytes_pending_upload_ += raster_task->resource()->bytes();
715 raster_tasks_with_pending_upload_.push_back(raster_task); 691 raster_tasks_with_pending_upload_.push_back(raster_task);
716 state.type = RasterTaskState::UPLOADING; 692 state.type = RasterTaskState::UPLOADING;
717 } 693 }
718 completed_tasks_.clear(); 694 completed_tasks_.clear();
719 } 695 }
720 696
721 scoped_refptr<base::debug::ConvertableToTraceFormat> 697 scoped_refptr<base::debug::ConvertableToTraceFormat>
722 PixelBufferRasterWorkerPool::StateAsValue() const { 698 PixelBufferRasterWorkerPool::StateAsValue() const {
723 scoped_refptr<base::debug::TracedValue> state = 699 scoped_refptr<base::debug::TracedValue> state =
724 new base::debug::TracedValue(); 700 new base::debug::TracedValue();
725 state->SetInteger("completed_count", completed_raster_tasks_.size()); 701 state->SetInteger("completed_count", completed_raster_tasks_.size());
726 state->SetInteger("pending_count", raster_task_states_.size()); 702 state->BeginArray("pending_count");
703 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set)
704 state->AppendInteger(task_counts_[task_set]);
705 state->EndArray();
727 state->SetInteger("pending_upload_count", 706 state->SetInteger("pending_upload_count",
728 raster_tasks_with_pending_upload_.size()); 707 raster_tasks_with_pending_upload_.size());
729 state->SetInteger("pending_required_for_activation_count",
730 raster_tasks_required_for_activation_count_);
731 state->BeginDictionary("throttle_state"); 708 state->BeginDictionary("throttle_state");
732 ThrottleStateAsValueInto(state.get()); 709 ThrottleStateAsValueInto(state.get());
733 state->EndDictionary(); 710 state->EndDictionary();
734 return state; 711 return state;
735 } 712 }
736 713
737 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto( 714 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto(
738 base::debug::TracedValue* throttle_state) const { 715 base::debug::TracedValue* throttle_state) const {
739 throttle_state->SetInteger("bytes_available_for_upload", 716 throttle_state->SetInteger("bytes_available_for_upload",
740 max_bytes_pending_upload_ - bytes_pending_upload_); 717 max_bytes_pending_upload_ - bytes_pending_upload_);
741 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); 718 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_);
742 throttle_state->SetInteger("scheduled_raster_task_count", 719 throttle_state->SetInteger("scheduled_raster_task_count",
743 scheduled_raster_task_count_); 720 scheduled_raster_task_count_);
744 } 721 }
745 722
746 } // namespace cc 723 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698