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" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { | 519 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { |
520 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); | 520 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); |
521 | 521 |
522 WorkerPoolTaskVector tasks; | 522 WorkerPoolTaskVector tasks; |
523 WorkerPoolTaskVector tasks_required_for_activation; | 523 WorkerPoolTaskVector tasks_required_for_activation; |
524 | 524 |
525 unsigned priority = kRasterTaskPriorityBase; | 525 unsigned priority = kRasterTaskPriorityBase; |
526 internal::TaskGraph graph; | 526 |
| 527 graph_.Reset(); |
527 | 528 |
528 size_t bytes_pending_upload = bytes_pending_upload_; | 529 size_t bytes_pending_upload = bytes_pending_upload_; |
529 bool did_throttle_raster_tasks = false; | 530 bool did_throttle_raster_tasks = false; |
530 | 531 |
531 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); | 532 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); |
532 it != raster_tasks().end(); | 533 it != raster_tasks().end(); |
533 ++it) { | 534 ++it) { |
534 internal::RasterWorkerPoolTask* task = it->get(); | 535 internal::RasterWorkerPoolTask* task = it->get(); |
535 | 536 |
536 // |raster_task_states_| contains the state of all tasks that we have not | 537 // |raster_task_states_| contains the state of all tasks that we have not |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 break; | 569 break; |
569 } | 570 } |
570 | 571 |
571 // Update |bytes_pending_upload| now that task has cleared all | 572 // Update |bytes_pending_upload| now that task has cleared all |
572 // throttling limits. | 573 // throttling limits. |
573 bytes_pending_upload = new_bytes_pending_upload; | 574 bytes_pending_upload = new_bytes_pending_upload; |
574 | 575 |
575 DCHECK(state_it->second == UNSCHEDULED || state_it->second == SCHEDULED); | 576 DCHECK(state_it->second == UNSCHEDULED || state_it->second == SCHEDULED); |
576 state_it->second = SCHEDULED; | 577 state_it->second = SCHEDULED; |
577 | 578 |
578 InsertNodeForRasterTask(&graph, task, task->dependencies(), priority++); | 579 InsertNodeForRasterTask(&graph_, task, task->dependencies(), priority++); |
579 | 580 |
580 tasks.container().push_back(task); | 581 tasks.container().push_back(task); |
581 if (IsRasterTaskRequiredForActivation(task)) | 582 if (IsRasterTaskRequiredForActivation(task)) |
582 tasks_required_for_activation.container().push_back(task); | 583 tasks_required_for_activation.container().push_back(task); |
583 } | 584 } |
584 | 585 |
585 scoped_refptr<internal::WorkerPoolTask> | 586 scoped_refptr<internal::WorkerPoolTask> |
586 new_raster_required_for_activation_finished_task; | 587 new_raster_required_for_activation_finished_task; |
587 | 588 |
588 size_t scheduled_raster_task_required_for_activation_count = | 589 size_t scheduled_raster_task_required_for_activation_count = |
589 tasks_required_for_activation.container().size(); | 590 tasks_required_for_activation.container().size(); |
590 DCHECK_LE(scheduled_raster_task_required_for_activation_count, | 591 DCHECK_LE(scheduled_raster_task_required_for_activation_count, |
591 raster_tasks_required_for_activation_.size()); | 592 raster_tasks_required_for_activation_.size()); |
592 // Schedule OnRasterTasksRequiredForActivationFinished call only when | 593 // Schedule OnRasterTasksRequiredForActivationFinished call only when |
593 // notification is pending and throttling is not preventing all pending | 594 // notification is pending and throttling is not preventing all pending |
594 // tasks required for activation from being scheduled. | 595 // tasks required for activation from being scheduled. |
595 if (scheduled_raster_task_required_for_activation_count == | 596 if (scheduled_raster_task_required_for_activation_count == |
596 raster_tasks_required_for_activation_.size() && | 597 raster_tasks_required_for_activation_.size() && |
597 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { | 598 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { |
598 new_raster_required_for_activation_finished_task = | 599 new_raster_required_for_activation_finished_task = |
599 CreateRasterRequiredForActivationFinishedTask( | 600 CreateRasterRequiredForActivationFinishedTask( |
600 raster_tasks_required_for_activation_.size()); | 601 raster_tasks_required_for_activation_.size()); |
601 raster_required_for_activation_finished_task_pending_ = true; | 602 raster_required_for_activation_finished_task_pending_ = true; |
602 InsertNodeForTask(&graph, | 603 InsertNodeForTask(&graph_, |
603 new_raster_required_for_activation_finished_task.get(), | 604 new_raster_required_for_activation_finished_task.get(), |
604 kRasterRequiredForActivationFinishedTaskPriority, | 605 kRasterRequiredForActivationFinishedTaskPriority, |
605 scheduled_raster_task_required_for_activation_count); | 606 scheduled_raster_task_required_for_activation_count); |
606 for (WorkerPoolTaskVector::ContainerType::const_iterator it = | 607 for (WorkerPoolTaskVector::ContainerType::const_iterator it = |
607 tasks_required_for_activation.container().begin(); | 608 tasks_required_for_activation.container().begin(); |
608 it != tasks_required_for_activation.container().end(); | 609 it != tasks_required_for_activation.container().end(); |
609 ++it) { | 610 ++it) { |
610 graph.edges.push_back(internal::TaskGraph::Edge( | 611 graph_.edges.push_back(internal::TaskGraph::Edge( |
611 *it, new_raster_required_for_activation_finished_task.get())); | 612 *it, new_raster_required_for_activation_finished_task.get())); |
612 } | 613 } |
613 } | 614 } |
614 | 615 |
615 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; | 616 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; |
616 | 617 |
617 size_t scheduled_raster_task_count = tasks.container().size(); | 618 size_t scheduled_raster_task_count = tasks.container().size(); |
618 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); | 619 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); |
619 // Schedule OnRasterTasksFinished call only when notification is pending | 620 // Schedule OnRasterTasksFinished call only when notification is pending |
620 // and throttling is not preventing all pending tasks from being scheduled. | 621 // and throttling is not preventing all pending tasks from being scheduled. |
621 if (!did_throttle_raster_tasks && | 622 if (!did_throttle_raster_tasks && |
622 should_notify_client_if_no_tasks_are_pending_) { | 623 should_notify_client_if_no_tasks_are_pending_) { |
623 new_raster_finished_task = CreateRasterFinishedTask(); | 624 new_raster_finished_task = CreateRasterFinishedTask(); |
624 raster_finished_task_pending_ = true; | 625 raster_finished_task_pending_ = true; |
625 InsertNodeForTask(&graph, | 626 InsertNodeForTask(&graph_, |
626 new_raster_finished_task.get(), | 627 new_raster_finished_task.get(), |
627 kRasterFinishedTaskPriority, | 628 kRasterFinishedTaskPriority, |
628 scheduled_raster_task_count); | 629 scheduled_raster_task_count); |
629 for (WorkerPoolTaskVector::ContainerType::const_iterator it = | 630 for (WorkerPoolTaskVector::ContainerType::const_iterator it = |
630 tasks.container().begin(); | 631 tasks.container().begin(); |
631 it != tasks.container().end(); | 632 it != tasks.container().end(); |
632 ++it) { | 633 ++it) { |
633 graph.edges.push_back( | 634 graph_.edges.push_back( |
634 internal::TaskGraph::Edge(*it, new_raster_finished_task.get())); | 635 internal::TaskGraph::Edge(*it, new_raster_finished_task.get())); |
635 } | 636 } |
636 } | 637 } |
637 | 638 |
638 SetTaskGraph(&graph); | 639 SetTaskGraph(&graph_); |
639 | 640 |
640 scheduled_raster_task_count_ = scheduled_raster_task_count; | 641 scheduled_raster_task_count_ = scheduled_raster_task_count; |
641 | 642 |
642 set_raster_finished_task(new_raster_finished_task); | 643 set_raster_finished_task(new_raster_finished_task); |
643 set_raster_required_for_activation_finished_task( | 644 set_raster_required_for_activation_finished_task( |
644 new_raster_required_for_activation_finished_task); | 645 new_raster_required_for_activation_finished_task); |
645 } | 646 } |
646 | 647 |
647 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { | 648 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { |
648 unsigned num_completed_raster_tasks = | 649 unsigned num_completed_raster_tasks = |
(...skipping 15 matching lines...) Expand all Loading... |
664 return "rasterizing"; | 665 return "rasterizing"; |
665 if (PendingRasterTaskCount()) | 666 if (PendingRasterTaskCount()) |
666 return "throttled"; | 667 return "throttled"; |
667 if (!raster_tasks_with_pending_upload_.empty()) | 668 if (!raster_tasks_with_pending_upload_.empty()) |
668 return "waiting_for_uploads"; | 669 return "waiting_for_uploads"; |
669 | 670 |
670 return "finishing"; | 671 return "finishing"; |
671 } | 672 } |
672 | 673 |
673 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { | 674 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { |
674 internal::Task::Vector completed_tasks; | 675 CollectCompletedWorkerPoolTasks(&completed_tasks_); |
675 CollectCompletedWorkerPoolTasks(&completed_tasks); | 676 for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); |
676 | 677 it != completed_tasks_.end(); |
677 for (internal::Task::Vector::const_iterator it = completed_tasks.begin(); | |
678 it != completed_tasks.end(); | |
679 ++it) { | 678 ++it) { |
680 internal::WorkerPoolTask* task = | 679 internal::WorkerPoolTask* task = |
681 static_cast<internal::WorkerPoolTask*>(it->get()); | 680 static_cast<internal::WorkerPoolTask*>(it->get()); |
682 | 681 |
683 task->WillComplete(); | 682 task->WillComplete(); |
684 task->CompleteOnOriginThread(this); | 683 task->CompleteOnOriginThread(this); |
685 task->DidComplete(); | 684 task->DidComplete(); |
686 } | 685 } |
| 686 completed_tasks_.clear(); |
687 } | 687 } |
688 | 688 |
689 scoped_ptr<base::Value> PixelBufferRasterWorkerPool::StateAsValue() const { | 689 scoped_ptr<base::Value> PixelBufferRasterWorkerPool::StateAsValue() const { |
690 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); | 690 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); |
691 | 691 |
692 state->SetInteger("completed_count", completed_raster_tasks_.size()); | 692 state->SetInteger("completed_count", completed_raster_tasks_.size()); |
693 state->SetInteger("pending_count", raster_task_states_.size()); | 693 state->SetInteger("pending_count", raster_task_states_.size()); |
694 state->SetInteger("pending_upload_count", | 694 state->SetInteger("pending_upload_count", |
695 raster_tasks_with_pending_upload_.size()); | 695 raster_tasks_with_pending_upload_.size()); |
696 state->SetInteger("required_for_activation_count", | 696 state->SetInteger("required_for_activation_count", |
697 raster_tasks_required_for_activation_.size()); | 697 raster_tasks_required_for_activation_.size()); |
698 state->Set("scheduled_state", ScheduledStateAsValue().release()); | 698 state->Set("scheduled_state", ScheduledStateAsValue().release()); |
699 state->Set("throttle_state", ThrottleStateAsValue().release()); | 699 state->Set("throttle_state", ThrottleStateAsValue().release()); |
700 return state.PassAs<base::Value>(); | 700 return state.PassAs<base::Value>(); |
701 } | 701 } |
702 | 702 |
703 scoped_ptr<base::Value> PixelBufferRasterWorkerPool::ThrottleStateAsValue() | 703 scoped_ptr<base::Value> PixelBufferRasterWorkerPool::ThrottleStateAsValue() |
704 const { | 704 const { |
705 scoped_ptr<base::DictionaryValue> throttle_state(new base::DictionaryValue); | 705 scoped_ptr<base::DictionaryValue> throttle_state(new base::DictionaryValue); |
706 | 706 |
707 throttle_state->SetInteger("bytes_available_for_upload", | 707 throttle_state->SetInteger("bytes_available_for_upload", |
708 max_bytes_pending_upload_ - bytes_pending_upload_); | 708 max_bytes_pending_upload_ - bytes_pending_upload_); |
709 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 709 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
710 throttle_state->SetInteger("scheduled_raster_task_count", | 710 throttle_state->SetInteger("scheduled_raster_task_count", |
711 scheduled_raster_task_count_); | 711 scheduled_raster_task_count_); |
712 return throttle_state.PassAs<base::Value>(); | 712 return throttle_state.PassAs<base::Value>(); |
713 } | 713 } |
714 | 714 |
715 } // namespace cc | 715 } // namespace cc |
OLD | NEW |