| OLD | NEW |
| 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" |
| 11 #include "cc/resources/resource.h" | 11 #include "cc/resources/resource.h" |
| 12 #include "third_party/skia/include/core/SkBitmapDevice.h" | |
| 13 | |
| 14 #if defined(OS_ANDROID) | |
| 15 #include "base/android/sys_utils.h" | |
| 16 #endif | |
| 17 | 12 |
| 18 namespace cc { | 13 namespace cc { |
| 19 namespace { | 14 namespace { |
| 20 | 15 |
| 21 const int kCheckForCompletedRasterTasksDelayMs = 6; | 16 const int kCheckForCompletedRasterTasksDelayMs = 6; |
| 22 | 17 |
| 23 const size_t kMaxScheduledRasterTasks = 48; | 18 const size_t kMaxScheduledRasterTasks = 48; |
| 24 | 19 |
| 25 typedef base::StackVector<internal::GraphNode*, kMaxScheduledRasterTasks> | 20 typedef base::StackVector<internal::WorkerPoolTask*, kMaxScheduledRasterTasks> |
| 26 NodeVector; | 21 WorkerPoolTaskVector; |
| 27 | |
| 28 void AddDependenciesToGraphNode(internal::GraphNode* node, | |
| 29 const NodeVector::ContainerType& dependencies) { | |
| 30 for (NodeVector::ContainerType::const_iterator it = dependencies.begin(); | |
| 31 it != dependencies.end(); | |
| 32 ++it) { | |
| 33 internal::GraphNode* dependency = *it; | |
| 34 | |
| 35 node->add_dependency(); | |
| 36 dependency->add_dependent(node); | |
| 37 } | |
| 38 } | |
| 39 | 22 |
| 40 // Only used as std::find_if predicate for DCHECKs. | 23 // Only used as std::find_if predicate for DCHECKs. |
| 41 bool WasCanceled(const internal::RasterWorkerPoolTask* task) { | 24 bool WasCanceled(const internal::RasterWorkerPoolTask* task) { |
| 42 return !task->HasFinishedRunning(); | 25 return !task->HasFinishedRunning(); |
| 43 } | 26 } |
| 44 | 27 |
| 45 } // namespace | 28 } // namespace |
| 46 | 29 |
| 47 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( | 30 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( |
| 48 ResourceProvider* resource_provider, | 31 ResourceProvider* resource_provider, |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 if (will_notify_client_that_no_tasks_are_pending) { | 462 if (will_notify_client_that_no_tasks_are_pending) { |
| 480 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 463 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); |
| 481 DCHECK(!HasPendingTasksRequiredForActivation()); | 464 DCHECK(!HasPendingTasksRequiredForActivation()); |
| 482 client()->DidFinishRunningTasks(); | 465 client()->DidFinishRunningTasks(); |
| 483 } | 466 } |
| 484 } | 467 } |
| 485 | 468 |
| 486 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { | 469 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { |
| 487 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); | 470 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); |
| 488 | 471 |
| 489 enum RasterTaskType { | 472 WorkerPoolTaskVector tasks; |
| 490 PREPAINT_TYPE = 0, | 473 WorkerPoolTaskVector tasks_required_for_activation; |
| 491 REQUIRED_FOR_ACTIVATION_TYPE = 1, | 474 |
| 492 NUM_TYPES = 2 | 475 unsigned priority = kRasterTaskPriorityBase; |
| 493 }; | 476 internal::TaskGraph graph; |
| 494 NodeVector tasks[NUM_TYPES]; | |
| 495 unsigned priority = 2u; // 0-1 reserved for RasterFinished tasks. | |
| 496 TaskGraph graph; | |
| 497 | 477 |
| 498 size_t bytes_pending_upload = bytes_pending_upload_; | 478 size_t bytes_pending_upload = bytes_pending_upload_; |
| 499 bool did_throttle_raster_tasks = false; | 479 bool did_throttle_raster_tasks = false; |
| 500 | 480 |
| 501 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); | 481 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); |
| 502 it != raster_tasks().end(); | 482 it != raster_tasks().end(); |
| 503 ++it) { | 483 ++it) { |
| 504 internal::RasterWorkerPoolTask* task = it->get(); | 484 internal::RasterWorkerPoolTask* task = it->get(); |
| 505 | 485 |
| 506 // |raster_task_states_| contains the state of all tasks that we have not | 486 // |raster_task_states_| contains the state of all tasks that we have not |
| (...skipping 19 matching lines...) Expand all Loading... |
| 526 } | 506 } |
| 527 | 507 |
| 528 // If raster has finished, just update |bytes_pending_upload|. | 508 // If raster has finished, just update |bytes_pending_upload|. |
| 529 if (state_it->second == UPLOADING) { | 509 if (state_it->second == UPLOADING) { |
| 530 DCHECK(task->HasCompleted()); | 510 DCHECK(task->HasCompleted()); |
| 531 bytes_pending_upload = new_bytes_pending_upload; | 511 bytes_pending_upload = new_bytes_pending_upload; |
| 532 continue; | 512 continue; |
| 533 } | 513 } |
| 534 | 514 |
| 535 // Throttle raster tasks based on kMaxScheduledRasterTasks. | 515 // Throttle raster tasks based on kMaxScheduledRasterTasks. |
| 536 size_t scheduled_raster_task_count = | 516 if (tasks.container().size() >= kMaxScheduledRasterTasks) { |
| 537 tasks[PREPAINT_TYPE].container().size() + | |
| 538 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | |
| 539 if (scheduled_raster_task_count >= kMaxScheduledRasterTasks) { | |
| 540 did_throttle_raster_tasks = true; | 517 did_throttle_raster_tasks = true; |
| 541 break; | 518 break; |
| 542 } | 519 } |
| 543 | 520 |
| 544 // Update |bytes_pending_upload| now that task has cleared all | 521 // Update |bytes_pending_upload| now that task has cleared all |
| 545 // throttling limits. | 522 // throttling limits. |
| 546 bytes_pending_upload = new_bytes_pending_upload; | 523 bytes_pending_upload = new_bytes_pending_upload; |
| 547 | 524 |
| 548 RasterTaskType type = IsRasterTaskRequiredForActivation(task) | |
| 549 ? REQUIRED_FOR_ACTIVATION_TYPE | |
| 550 : PREPAINT_TYPE; | |
| 551 | |
| 552 DCHECK(state_it->second == UNSCHEDULED || state_it->second == SCHEDULED); | 525 DCHECK(state_it->second == UNSCHEDULED || state_it->second == SCHEDULED); |
| 553 state_it->second = SCHEDULED; | 526 state_it->second = SCHEDULED; |
| 554 | 527 |
| 555 tasks[type].container().push_back(CreateGraphNodeForRasterTask( | 528 InsertNodeForRasterTask(&graph, task, task->dependencies(), priority++); |
| 556 task, task->dependencies(), priority++, &graph)); | 529 |
| 530 tasks.container().push_back(task); |
| 531 if (IsRasterTaskRequiredForActivation(task)) |
| 532 tasks_required_for_activation.container().push_back(task); |
| 557 } | 533 } |
| 558 | 534 |
| 559 scoped_refptr<internal::WorkerPoolTask> | 535 scoped_refptr<internal::WorkerPoolTask> |
| 560 new_raster_required_for_activation_finished_task; | 536 new_raster_required_for_activation_finished_task; |
| 561 | 537 |
| 562 size_t scheduled_raster_task_required_for_activation_count = | 538 size_t scheduled_raster_task_required_for_activation_count = |
| 563 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | 539 tasks_required_for_activation.container().size(); |
| 564 DCHECK_LE(scheduled_raster_task_required_for_activation_count, | 540 DCHECK_LE(scheduled_raster_task_required_for_activation_count, |
| 565 raster_tasks_required_for_activation_.size()); | 541 raster_tasks_required_for_activation_.size()); |
| 566 // Schedule OnRasterTasksRequiredForActivationFinished call only when | 542 // Schedule OnRasterTasksRequiredForActivationFinished call only when |
| 567 // notification is pending and throttling is not preventing all pending | 543 // notification is pending and throttling is not preventing all pending |
| 568 // tasks required for activation from being scheduled. | 544 // tasks required for activation from being scheduled. |
| 569 if (scheduled_raster_task_required_for_activation_count == | 545 if (scheduled_raster_task_required_for_activation_count == |
| 570 raster_tasks_required_for_activation_.size() && | 546 raster_tasks_required_for_activation_.size() && |
| 571 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { | 547 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { |
| 572 new_raster_required_for_activation_finished_task = | 548 new_raster_required_for_activation_finished_task = |
| 573 CreateRasterRequiredForActivationFinishedTask( | 549 CreateRasterRequiredForActivationFinishedTask( |
| 574 raster_tasks_required_for_activation_.size()); | 550 raster_tasks_required_for_activation_.size()); |
| 575 raster_required_for_activation_finished_task_pending_ = true; | 551 raster_required_for_activation_finished_task_pending_ = true; |
| 576 internal::GraphNode* raster_required_for_activation_finished_node = | 552 InsertNodeForTask(&graph, |
| 577 CreateGraphNodeForTask( | 553 new_raster_required_for_activation_finished_task.get(), |
| 578 new_raster_required_for_activation_finished_task.get(), | 554 kRasterRequiredForActivationFinishedTaskPriority, |
| 579 0u, // Priority 0 | 555 scheduled_raster_task_required_for_activation_count); |
| 580 &graph); | 556 for (WorkerPoolTaskVector::ContainerType::const_iterator it = |
| 581 AddDependenciesToGraphNode(raster_required_for_activation_finished_node, | 557 tasks_required_for_activation.container().begin(); |
| 582 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container()); | 558 it != tasks_required_for_activation.container().end(); |
| 559 ++it) { |
| 560 graph.edges.push_back(internal::TaskGraph::Edge( |
| 561 *it, new_raster_required_for_activation_finished_task.get())); |
| 562 } |
| 583 } | 563 } |
| 584 | 564 |
| 585 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; | 565 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; |
| 586 | 566 |
| 587 size_t scheduled_raster_task_count = | 567 size_t scheduled_raster_task_count = tasks.container().size(); |
| 588 tasks[PREPAINT_TYPE].container().size() + | |
| 589 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | |
| 590 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); | 568 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); |
| 591 // Schedule OnRasterTasksFinished call only when notification is pending | 569 // Schedule OnRasterTasksFinished call only when notification is pending |
| 592 // and throttling is not preventing all pending tasks from being scheduled. | 570 // and throttling is not preventing all pending tasks from being scheduled. |
| 593 if (!did_throttle_raster_tasks && | 571 if (!did_throttle_raster_tasks && |
| 594 should_notify_client_if_no_tasks_are_pending_) { | 572 should_notify_client_if_no_tasks_are_pending_) { |
| 595 new_raster_finished_task = CreateRasterFinishedTask(); | 573 new_raster_finished_task = CreateRasterFinishedTask(); |
| 596 raster_finished_task_pending_ = true; | 574 raster_finished_task_pending_ = true; |
| 597 internal::GraphNode* raster_finished_node = | 575 InsertNodeForTask(&graph, |
| 598 CreateGraphNodeForTask(new_raster_finished_task.get(), | 576 new_raster_finished_task.get(), |
| 599 1u, // Priority 1 | 577 kRasterFinishedTaskPriority, |
| 600 &graph); | 578 scheduled_raster_task_count); |
| 601 for (unsigned type = 0; type < NUM_TYPES; ++type) { | 579 for (WorkerPoolTaskVector::ContainerType::const_iterator it = |
| 602 AddDependenciesToGraphNode(raster_finished_node, tasks[type].container()); | 580 tasks.container().begin(); |
| 581 it != tasks.container().end(); |
| 582 ++it) { |
| 583 graph.edges.push_back( |
| 584 internal::TaskGraph::Edge(*it, new_raster_finished_task.get())); |
| 603 } | 585 } |
| 604 } | 586 } |
| 605 | 587 |
| 606 SetTaskGraph(&graph); | 588 SetTaskGraph(&graph); |
| 607 | 589 |
| 608 scheduled_raster_task_count_ = scheduled_raster_task_count; | 590 scheduled_raster_task_count_ = scheduled_raster_task_count; |
| 609 | 591 |
| 610 set_raster_finished_task(new_raster_finished_task); | 592 set_raster_finished_task(new_raster_finished_task); |
| 611 set_raster_required_for_activation_finished_task( | 593 set_raster_required_for_activation_finished_task( |
| 612 new_raster_required_for_activation_finished_task); | 594 new_raster_required_for_activation_finished_task); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 656 |
| 675 throttle_state->SetInteger("bytes_available_for_upload", | 657 throttle_state->SetInteger("bytes_available_for_upload", |
| 676 max_bytes_pending_upload_ - bytes_pending_upload_); | 658 max_bytes_pending_upload_ - bytes_pending_upload_); |
| 677 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 659 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
| 678 throttle_state->SetInteger("scheduled_raster_task_count", | 660 throttle_state->SetInteger("scheduled_raster_task_count", |
| 679 scheduled_raster_task_count_); | 661 scheduled_raster_task_count_); |
| 680 return throttle_state.PassAs<base::Value>(); | 662 return throttle_state.PassAs<base::Value>(); |
| 681 } | 663 } |
| 682 | 664 |
| 683 } // namespace cc | 665 } // namespace cc |
| OLD | NEW |