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

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

Issue 99873007: cc: Simplify raster task completion notification logic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « cc/resources/pixel_buffer_raster_worker_pool.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/containers/stack_container.h" 7 #include "base/containers/stack_container.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "cc/debug/traced_value.h" 10 #include "cc/debug/traced_value.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 task->WillComplete(); 244 task->WillComplete();
245 task->CompleteOnOriginThread(); 245 task->CompleteOnOriginThread();
246 task->DidComplete(); 246 task->DidComplete();
247 247
248 completed_tasks.pop_front(); 248 completed_tasks.pop_front();
249 } 249 }
250 } 250 }
251 251
252 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { 252 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() {
253 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as 253 if (CheckForCompletedRasterTasks() != ALL_TASKS_COMPLETED)
254 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to
255 // perform another check in that case as we've already notified the client.
256 if (!should_notify_client_if_no_tasks_are_pending_)
257 return; 254 return;
258 255
259 // Call CheckForCompletedRasterTasks() when we've finished running all 256 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
260 // raster tasks needed since last time ScheduleTasks() was called. 257 DCHECK(!HasPendingTasksRequiredForActivation());
261 // This reduces latency between the time when all tasks have finished 258 client()->DidFinishRunningTasks();
reveman 2013/12/14 04:31:01 Hm, what happens if CheckForCompletedRasterTasks()
Sami 2013/12/17 16:27:38 This shouldn't be any different than before, i.e.,
reveman 2013/12/17 20:46:25 The problem was that you removed the client callba
Sami 2013/12/18 12:05:06 Ah, now I see. I didn't realize pending uploads we
262 // running and the time when the client is notified.
263 CheckForCompletedRasterTasks();
264 } 259 }
265 260
266 void PixelBufferRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { 261 void PixelBufferRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() {
267 // Analogous to OnRasterTasksFinished(), there's no need to call 262 TaskQueueCompletionStatus completion_status = CheckForCompletedRasterTasks();
268 // CheckForCompletedRasterTasks() if the client has already been notified. 263 if (completion_status != TASKS_REQUIRED_FOR_ACTIVATION_COMPLETED &&
269 if (!should_notify_client_if_no_tasks_required_for_activation_are_pending_) 264 completion_status != ALL_TASKS_COMPLETED)
270 return; 265 return;
271 266
272 // This reduces latency between the time when all tasks required for 267 DCHECK(std::find_if(raster_tasks_required_for_activation().begin(),
273 // activation have finished running and the time when the client is 268 raster_tasks_required_for_activation().end(),
274 // notified. 269 WasCanceled) ==
275 CheckForCompletedRasterTasks(); 270 raster_tasks_required_for_activation().end());
271 client()->DidFinishRunningTasksRequiredForActivation();
276 } 272 }
277 273
278 void PixelBufferRasterWorkerPool::FlushUploads() { 274 void PixelBufferRasterWorkerPool::FlushUploads() {
279 if (!has_performed_uploads_since_last_flush_) 275 if (!has_performed_uploads_since_last_flush_)
280 return; 276 return;
281 277
282 resource_provider()->ShallowFlushIfSupported(); 278 resource_provider()->ShallowFlushIfSupported();
283 has_performed_uploads_since_last_flush_ = false; 279 has_performed_uploads_since_last_flush_ = false;
284 } 280 }
285 281
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 350
355 tasks_with_completed_uploads.pop_front(); 351 tasks_with_completed_uploads.pop_front();
356 } 352 }
357 } 353 }
358 354
359 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { 355 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() {
360 if (check_for_completed_raster_tasks_pending_) 356 if (check_for_completed_raster_tasks_pending_)
361 return; 357 return;
362 358
363 check_for_completed_raster_tasks_callback_.Reset( 359 check_for_completed_raster_tasks_callback_.Reset(
364 base::Bind(&PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks, 360 base::Bind(base::IgnoreResult(
361 &PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks),
365 base::Unretained(this))); 362 base::Unretained(this)));
366 base::MessageLoopProxy::current()->PostDelayedTask( 363 base::MessageLoopProxy::current()->PostDelayedTask(
367 FROM_HERE, 364 FROM_HERE,
368 check_for_completed_raster_tasks_callback_.callback(), 365 check_for_completed_raster_tasks_callback_.callback(),
369 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs)); 366 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs));
370 check_for_completed_raster_tasks_pending_ = true; 367 check_for_completed_raster_tasks_pending_ = true;
371 } 368 }
372 369
373 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { 370 PixelBufferRasterWorkerPool::TaskQueueCompletionStatus
371 PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() {
374 TRACE_EVENT0( 372 TRACE_EVENT0(
375 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); 373 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks");
376 374
377 DCHECK(should_notify_client_if_no_tasks_are_pending_); 375 DCHECK(should_notify_client_if_no_tasks_are_pending_);
378 376
379 check_for_completed_raster_tasks_callback_.Cancel(); 377 check_for_completed_raster_tasks_callback_.Cancel();
380 check_for_completed_raster_tasks_pending_ = false; 378 check_for_completed_raster_tasks_pending_ = false;
381 379
382 RasterWorkerPool::CheckForCompletedTasks(); 380 RasterWorkerPool::CheckForCompletedTasks();
383 CheckForCompletedUploads(); 381 CheckForCompletedUploads();
384 FlushUploads(); 382 FlushUploads();
385 383
386 // Determine what client notifications to generate. 384 TaskQueueCompletionStatus completion_status = TASKS_PENDING;
387 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = 385 if (!HasPendingTasks())
388 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && 386 completion_status = ALL_TASKS_COMPLETED;
389 !HasPendingTasksRequiredForActivation()); 387 else if (!HasPendingTasksRequiredForActivation())
390 bool will_notify_client_that_no_tasks_are_pending = 388 completion_status = TASKS_REQUIRED_FOR_ACTIVATION_COMPLETED;
391 (should_notify_client_if_no_tasks_are_pending_ &&
392 !HasPendingTasks());
393
394 // Adjust the need to generate notifications before scheduling more tasks.
395 should_notify_client_if_no_tasks_required_for_activation_are_pending_ &=
396 !will_notify_client_that_no_tasks_required_for_activation_are_pending;
397 should_notify_client_if_no_tasks_are_pending_ &=
398 !will_notify_client_that_no_tasks_are_pending;
399 389
400 scheduled_raster_task_count_ = 0; 390 scheduled_raster_task_count_ = 0;
401 if (PendingRasterTaskCount()) 391 if (PendingRasterTaskCount())
402 ScheduleMoreTasks(); 392 ScheduleMoreTasks();
403 393
404 TRACE_EVENT_ASYNC_STEP_INTO1( 394 TRACE_EVENT_ASYNC_STEP_INTO1(
405 "cc", "ScheduledTasks", this, StateName(), 395 "cc", "ScheduledTasks", this, StateName(),
406 "state", TracedValue::FromValue(StateAsValue().release())); 396 "state", TracedValue::FromValue(StateAsValue().release()));
407 397
408 // Schedule another check for completed raster tasks while there are 398 // Schedule another check for completed raster tasks while there are
409 // pending raster tasks or pending uploads. 399 // pending raster tasks or pending uploads.
410 if (HasPendingTasks()) 400 if (HasPendingTasks())
411 ScheduleCheckForCompletedRasterTasks(); 401 ScheduleCheckForCompletedRasterTasks();
412 402 return completion_status;
413 // Generate client notifications.
414 if (will_notify_client_that_no_tasks_required_for_activation_are_pending) {
415 DCHECK(std::find_if(raster_tasks_required_for_activation().begin(),
416 raster_tasks_required_for_activation().end(),
417 WasCanceled) ==
418 raster_tasks_required_for_activation().end());
419 client()->DidFinishRunningTasksRequiredForActivation();
420 }
421 if (will_notify_client_that_no_tasks_are_pending) {
422 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
423 DCHECK(!HasPendingTasksRequiredForActivation());
424 client()->DidFinishRunningTasks();
425 }
426 } 403 }
427 404
428 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { 405 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() {
429 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); 406 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks");
430 407
431 enum RasterTaskType { 408 enum RasterTaskType {
432 PREPAINT_TYPE = 0, 409 PREPAINT_TYPE = 0,
433 REQUIRED_FOR_ACTIVATION_TYPE = 1, 410 REQUIRED_FOR_ACTIVATION_TYPE = 1,
434 NUM_TYPES = 2 411 NUM_TYPES = 2
435 }; 412 };
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 645
669 throttle_state->SetInteger("bytes_available_for_upload", 646 throttle_state->SetInteger("bytes_available_for_upload",
670 max_bytes_pending_upload_ - bytes_pending_upload_); 647 max_bytes_pending_upload_ - bytes_pending_upload_);
671 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); 648 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_);
672 throttle_state->SetInteger("scheduled_raster_task_count", 649 throttle_state->SetInteger("scheduled_raster_task_count",
673 scheduled_raster_task_count_); 650 scheduled_raster_task_count_);
674 return throttle_state.PassAs<base::Value>(); 651 return throttle_state.PassAs<base::Value>();
675 } 652 }
676 653
677 } // namespace cc 654 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/pixel_buffer_raster_worker_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698