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 enum RasterTaskType { |
vmpstr
2014/02/06 19:44:37
Just out of curiosity, what type is a tile in the
reveman
2014/02/06 20:51:52
Yes, not the best name for that enum value. I got
| |
490 PREPAINT_TYPE = 0, | 473 PREPAINT_TYPE = 0, |
491 REQUIRED_FOR_ACTIVATION_TYPE = 1, | 474 REQUIRED_FOR_ACTIVATION_TYPE = 1, |
492 NUM_TYPES = 2 | 475 NUM_TYPES = 2 |
493 }; | 476 }; |
494 NodeVector tasks[NUM_TYPES]; | 477 WorkerPoolTaskVector tasks[NUM_TYPES]; |
478 | |
495 unsigned priority = 2u; // 0-1 reserved for RasterFinished tasks. | 479 unsigned priority = 2u; // 0-1 reserved for RasterFinished tasks. |
496 TaskGraph graph; | 480 internal::TaskGraph graph; |
497 | 481 |
498 size_t bytes_pending_upload = bytes_pending_upload_; | 482 size_t bytes_pending_upload = bytes_pending_upload_; |
499 bool did_throttle_raster_tasks = false; | 483 bool did_throttle_raster_tasks = false; |
500 | 484 |
501 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); | 485 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); |
502 it != raster_tasks().end(); | 486 it != raster_tasks().end(); |
503 ++it) { | 487 ++it) { |
504 internal::RasterWorkerPoolTask* task = it->get(); | 488 internal::RasterWorkerPoolTask* task = it->get(); |
505 | 489 |
506 // |raster_task_states_| contains the state of all tasks that we have not | 490 // |raster_task_states_| contains the state of all tasks that we have not |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 // throttling limits. | 529 // throttling limits. |
546 bytes_pending_upload = new_bytes_pending_upload; | 530 bytes_pending_upload = new_bytes_pending_upload; |
547 | 531 |
548 RasterTaskType type = IsRasterTaskRequiredForActivation(task) | 532 RasterTaskType type = IsRasterTaskRequiredForActivation(task) |
549 ? REQUIRED_FOR_ACTIVATION_TYPE | 533 ? REQUIRED_FOR_ACTIVATION_TYPE |
550 : PREPAINT_TYPE; | 534 : PREPAINT_TYPE; |
551 | 535 |
552 DCHECK(state_it->second == UNSCHEDULED || state_it->second == SCHEDULED); | 536 DCHECK(state_it->second == UNSCHEDULED || state_it->second == SCHEDULED); |
553 state_it->second = SCHEDULED; | 537 state_it->second = SCHEDULED; |
554 | 538 |
555 tasks[type].container().push_back(CreateGraphNodeForRasterTask( | 539 InsertNodeForRasterTask(&graph, task, task->dependencies(), priority++); |
556 task, task->dependencies(), priority++, &graph)); | 540 |
541 tasks[type].container().push_back(task); | |
557 } | 542 } |
558 | 543 |
559 scoped_refptr<internal::WorkerPoolTask> | 544 scoped_refptr<internal::WorkerPoolTask> |
560 new_raster_required_for_activation_finished_task; | 545 new_raster_required_for_activation_finished_task; |
561 | 546 |
562 size_t scheduled_raster_task_required_for_activation_count = | 547 size_t scheduled_raster_task_required_for_activation_count = |
563 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | 548 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); |
564 DCHECK_LE(scheduled_raster_task_required_for_activation_count, | 549 DCHECK_LE(scheduled_raster_task_required_for_activation_count, |
565 raster_tasks_required_for_activation_.size()); | 550 raster_tasks_required_for_activation_.size()); |
566 // Schedule OnRasterTasksRequiredForActivationFinished call only when | 551 // Schedule OnRasterTasksRequiredForActivationFinished call only when |
567 // notification is pending and throttling is not preventing all pending | 552 // notification is pending and throttling is not preventing all pending |
568 // tasks required for activation from being scheduled. | 553 // tasks required for activation from being scheduled. |
569 if (scheduled_raster_task_required_for_activation_count == | 554 if (scheduled_raster_task_required_for_activation_count == |
570 raster_tasks_required_for_activation_.size() && | 555 raster_tasks_required_for_activation_.size() && |
571 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { | 556 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { |
572 new_raster_required_for_activation_finished_task = | 557 new_raster_required_for_activation_finished_task = |
573 CreateRasterRequiredForActivationFinishedTask( | 558 CreateRasterRequiredForActivationFinishedTask( |
574 raster_tasks_required_for_activation_.size()); | 559 raster_tasks_required_for_activation_.size()); |
575 raster_required_for_activation_finished_task_pending_ = true; | 560 raster_required_for_activation_finished_task_pending_ = true; |
576 internal::GraphNode* raster_required_for_activation_finished_node = | 561 InsertNodeForTask(&graph, |
577 CreateGraphNodeForTask( | 562 new_raster_required_for_activation_finished_task.get(), |
578 new_raster_required_for_activation_finished_task.get(), | 563 0u, // Priority 0 |
579 0u, // Priority 0 | 564 scheduled_raster_task_required_for_activation_count); |
580 &graph); | 565 for (WorkerPoolTaskVector::ContainerType::const_iterator it = |
581 AddDependenciesToGraphNode(raster_required_for_activation_finished_node, | 566 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().begin(); |
582 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container()); | 567 it != tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().end(); |
568 ++it) { | |
569 graph.edges.push_back(internal::TaskGraph::Edge( | |
570 *it, new_raster_required_for_activation_finished_task.get())); | |
571 } | |
583 } | 572 } |
584 | 573 |
585 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; | 574 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; |
586 | 575 |
587 size_t scheduled_raster_task_count = | 576 size_t scheduled_raster_task_count = |
588 tasks[PREPAINT_TYPE].container().size() + | 577 tasks[PREPAINT_TYPE].container().size() + |
589 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | 578 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); |
590 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); | 579 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); |
591 // Schedule OnRasterTasksFinished call only when notification is pending | 580 // Schedule OnRasterTasksFinished call only when notification is pending |
592 // and throttling is not preventing all pending tasks from being scheduled. | 581 // and throttling is not preventing all pending tasks from being scheduled. |
593 if (!did_throttle_raster_tasks && | 582 if (!did_throttle_raster_tasks && |
594 should_notify_client_if_no_tasks_are_pending_) { | 583 should_notify_client_if_no_tasks_are_pending_) { |
595 new_raster_finished_task = CreateRasterFinishedTask(); | 584 new_raster_finished_task = CreateRasterFinishedTask(); |
596 raster_finished_task_pending_ = true; | 585 raster_finished_task_pending_ = true; |
597 internal::GraphNode* raster_finished_node = | 586 InsertNodeForTask(&graph, |
598 CreateGraphNodeForTask(new_raster_finished_task.get(), | 587 new_raster_finished_task.get(), |
599 1u, // Priority 1 | 588 1u, // Priority 1 |
600 &graph); | 589 scheduled_raster_task_count); |
601 for (unsigned type = 0; type < NUM_TYPES; ++type) { | 590 for (WorkerPoolTaskVector::ContainerType::const_iterator it = |
602 AddDependenciesToGraphNode(raster_finished_node, tasks[type].container()); | 591 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().begin(); |
592 it != tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().end(); | |
593 ++it) { | |
594 graph.edges.push_back( | |
595 internal::TaskGraph::Edge(*it, new_raster_finished_task.get())); | |
596 } | |
597 for (WorkerPoolTaskVector::ContainerType::const_iterator it = | |
598 tasks[PREPAINT_TYPE].container().begin(); | |
599 it != tasks[PREPAINT_TYPE].container().end(); | |
600 ++it) { | |
601 graph.edges.push_back( | |
602 internal::TaskGraph::Edge(*it, new_raster_finished_task.get())); | |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 SetTaskGraph(&graph); | 606 SetTaskGraph(&graph); |
607 | 607 |
608 scheduled_raster_task_count_ = scheduled_raster_task_count; | 608 scheduled_raster_task_count_ = scheduled_raster_task_count; |
609 | 609 |
610 set_raster_finished_task(new_raster_finished_task); | 610 set_raster_finished_task(new_raster_finished_task); |
611 set_raster_required_for_activation_finished_task( | 611 set_raster_required_for_activation_finished_task( |
612 new_raster_required_for_activation_finished_task); | 612 new_raster_required_for_activation_finished_task); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 | 674 |
675 throttle_state->SetInteger("bytes_available_for_upload", | 675 throttle_state->SetInteger("bytes_available_for_upload", |
676 max_bytes_pending_upload_ - bytes_pending_upload_); | 676 max_bytes_pending_upload_ - bytes_pending_upload_); |
677 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 677 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
678 throttle_state->SetInteger("scheduled_raster_task_count", | 678 throttle_state->SetInteger("scheduled_raster_task_count", |
679 scheduled_raster_task_count_); | 679 scheduled_raster_task_count_); |
680 return throttle_state.PassAs<base::Value>(); | 680 return throttle_state.PassAs<base::Value>(); |
681 } | 681 } |
682 | 682 |
683 } // namespace cc | 683 } // namespace cc |
OLD | NEW |