Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/tiles/tile_manager.h" | 5 #include "cc/tiles/tile_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 state->SetInteger("completed_count", | 296 state->SetInteger("completed_count", |
| 297 base::saturated_cast<int>(stats.completed_count)); | 297 base::saturated_cast<int>(stats.completed_count)); |
| 298 state->SetInteger("canceled_count", | 298 state->SetInteger("canceled_count", |
| 299 base::saturated_cast<int>(stats.canceled_count)); | 299 base::saturated_cast<int>(stats.canceled_count)); |
| 300 return std::move(state); | 300 return std::move(state); |
| 301 } | 301 } |
| 302 | 302 |
| 303 TileManager::TileManager(TileManagerClient* client, | 303 TileManager::TileManager(TileManagerClient* client, |
| 304 scoped_refptr<base::SequencedTaskRunner> task_runner, | 304 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 305 size_t scheduled_raster_task_limit, | 305 size_t scheduled_raster_task_limit, |
| 306 bool use_partial_raster) | 306 bool use_partial_raster, |
| 307 int max_preraster_distance_in_screen_pixels) | |
| 307 : client_(client), | 308 : client_(client), |
| 308 task_runner_(std::move(task_runner)), | 309 task_runner_(std::move(task_runner)), |
| 309 resource_pool_(nullptr), | 310 resource_pool_(nullptr), |
| 310 tile_task_manager_(nullptr), | 311 tile_task_manager_(nullptr), |
| 311 scheduled_raster_task_limit_(scheduled_raster_task_limit), | 312 scheduled_raster_task_limit_(scheduled_raster_task_limit), |
| 312 use_partial_raster_(use_partial_raster), | 313 use_partial_raster_(use_partial_raster), |
| 313 use_gpu_rasterization_(false), | 314 use_gpu_rasterization_(false), |
| 314 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), | 315 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), |
| 315 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 316 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 316 did_oom_on_last_assign_(false), | 317 did_oom_on_last_assign_(false), |
| 317 more_tiles_need_prepare_check_notifier_( | 318 more_tiles_need_prepare_check_notifier_( |
| 318 task_runner_.get(), | 319 task_runner_.get(), |
| 319 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, | 320 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, |
| 320 base::Unretained(this))), | 321 base::Unretained(this))), |
| 321 signals_check_notifier_(task_runner_.get(), | 322 signals_check_notifier_(task_runner_.get(), |
| 322 base::Bind(&TileManager::CheckAndIssueSignals, | 323 base::Bind(&TileManager::CheckAndIssueSignals, |
| 323 base::Unretained(this))), | 324 base::Unretained(this))), |
| 324 has_scheduled_tile_tasks_(false), | 325 has_scheduled_tile_tasks_(false), |
| 325 prepare_tiles_count_(0u), | 326 prepare_tiles_count_(0u), |
| 326 next_tile_id_(0u), | 327 next_tile_id_(0u), |
| 328 max_preraster_distance_in_screen_pixels_( | |
| 329 max_preraster_distance_in_screen_pixels), | |
| 327 task_set_finished_weak_ptr_factory_(this) {} | 330 task_set_finished_weak_ptr_factory_(this) {} |
| 328 | 331 |
| 329 TileManager::~TileManager() { | 332 TileManager::~TileManager() { |
| 330 FinishTasksAndCleanUp(); | 333 FinishTasksAndCleanUp(); |
| 331 } | 334 } |
| 332 | 335 |
| 333 void TileManager::FinishTasksAndCleanUp() { | 336 void TileManager::FinishTasksAndCleanUp() { |
| 334 if (!tile_task_manager_) | 337 if (!tile_task_manager_) |
| 335 return; | 338 return; |
| 336 | 339 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 347 tile_task_manager_->CheckForCompletedTasks(); | 350 tile_task_manager_->CheckForCompletedTasks(); |
| 348 | 351 |
| 349 FreeResourcesForReleasedTiles(); | 352 FreeResourcesForReleasedTiles(); |
| 350 CleanUpReleasedTiles(); | 353 CleanUpReleasedTiles(); |
| 351 | 354 |
| 352 tile_task_manager_ = nullptr; | 355 tile_task_manager_ = nullptr; |
| 353 resource_pool_ = nullptr; | 356 resource_pool_ = nullptr; |
| 354 more_tiles_need_prepare_check_notifier_.Cancel(); | 357 more_tiles_need_prepare_check_notifier_.Cancel(); |
| 355 signals_check_notifier_.Cancel(); | 358 signals_check_notifier_.Cancel(); |
| 356 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 359 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 360 | |
| 361 for (auto& draw_image_pair : locked_images_) | |
| 362 image_decode_controller_->UnrefImage(draw_image_pair.first); | |
| 363 locked_images_.clear(); | |
| 357 } | 364 } |
| 358 | 365 |
| 359 void TileManager::SetResources(ResourcePool* resource_pool, | 366 void TileManager::SetResources(ResourcePool* resource_pool, |
| 360 ImageDecodeController* image_decode_controller, | 367 ImageDecodeController* image_decode_controller, |
| 361 TileTaskManager* tile_task_manager, | 368 TileTaskManager* tile_task_manager, |
| 362 size_t scheduled_raster_task_limit, | 369 size_t scheduled_raster_task_limit, |
| 363 bool use_gpu_rasterization) { | 370 bool use_gpu_rasterization) { |
| 364 DCHECK(!tile_task_manager_); | 371 DCHECK(!tile_task_manager_); |
| 365 DCHECK(tile_task_manager); | 372 DCHECK(tile_task_manager); |
| 366 | 373 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 // We need to call CheckForCompletedTasks() once in-between each call | 464 // We need to call CheckForCompletedTasks() once in-between each call |
| 458 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 465 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 459 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 466 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 460 tile_task_manager_->CheckForCompletedTasks(); | 467 tile_task_manager_->CheckForCompletedTasks(); |
| 461 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 468 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 462 } | 469 } |
| 463 | 470 |
| 464 FreeResourcesForReleasedTiles(); | 471 FreeResourcesForReleasedTiles(); |
| 465 CleanUpReleasedTiles(); | 472 CleanUpReleasedTiles(); |
| 466 | 473 |
| 467 std::vector<PrioritizedTile> tiles_that_need_to_be_rasterized = | 474 PrioritizedWorkToSchedule prioritized_work = AssignGpuMemoryToTiles(); |
| 468 AssignGpuMemoryToTiles(); | |
| 469 | 475 |
| 470 // Inform the client that will likely require a draw if the highest priority | 476 // Inform the client that will likely require a draw if the highest priority |
| 471 // tile that will be rasterized is required for draw. | 477 // tile that will be rasterized is required for draw. |
| 472 client_->SetIsLikelyToRequireADraw( | 478 client_->SetIsLikelyToRequireADraw( |
| 473 !tiles_that_need_to_be_rasterized.empty() && | 479 !prioritized_work.tiles_to_raster.empty() && |
| 474 tiles_that_need_to_be_rasterized.front().tile()->required_for_draw()); | 480 prioritized_work.tiles_to_raster.front().tile()->required_for_draw()); |
| 475 | 481 |
| 476 // Schedule tile tasks. | 482 // Schedule tile tasks. |
| 477 ScheduleTasks(tiles_that_need_to_be_rasterized); | 483 ScheduleTasks(prioritized_work); |
| 478 | 484 |
| 479 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, | 485 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, |
| 480 "state", BasicStateAsValue()); | 486 "state", BasicStateAsValue()); |
| 481 return true; | 487 return true; |
| 482 } | 488 } |
| 483 | 489 |
| 484 void TileManager::Flush() { | 490 void TileManager::Flush() { |
| 485 TRACE_EVENT0("cc", "TileManager::Flush"); | 491 TRACE_EVENT0("cc", "TileManager::Flush"); |
| 486 | 492 |
| 487 if (!tile_task_manager_) { | 493 if (!tile_task_manager_) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 case ALLOW_PREPAINT_ONLY: | 578 case ALLOW_PREPAINT_ONLY: |
| 573 return priority.priority_bin > TilePriority::SOON; | 579 return priority.priority_bin > TilePriority::SOON; |
| 574 case ALLOW_ANYTHING: | 580 case ALLOW_ANYTHING: |
| 575 return priority.distance_to_visible == | 581 return priority.distance_to_visible == |
| 576 std::numeric_limits<float>::infinity(); | 582 std::numeric_limits<float>::infinity(); |
| 577 } | 583 } |
| 578 NOTREACHED(); | 584 NOTREACHED(); |
| 579 return true; | 585 return true; |
| 580 } | 586 } |
| 581 | 587 |
| 582 std::vector<PrioritizedTile> TileManager::AssignGpuMemoryToTiles() { | 588 TileManager::PrioritizedWorkToSchedule TileManager::AssignGpuMemoryToTiles() { |
| 583 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); | 589 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 584 | 590 |
| 585 DCHECK(resource_pool_); | 591 DCHECK(resource_pool_); |
| 586 DCHECK(tile_task_manager_); | 592 DCHECK(tile_task_manager_); |
| 587 | 593 |
| 588 // Maintain the list of released resources that can potentially be re-used | 594 // Maintain the list of released resources that can potentially be re-used |
| 589 // or deleted. If this operation becomes expensive too, only do this after | 595 // or deleted. If this operation becomes expensive too, only do this after |
| 590 // some resource(s) was returned. Note that in that case, one also need to | 596 // some resource(s) was returned. Note that in that case, one also need to |
| 591 // invalidate when releasing some resource from the pool. | 597 // invalidate when releasing some resource from the pool. |
| 592 resource_pool_->CheckBusyResources(); | 598 resource_pool_->CheckBusyResources(); |
| 593 | 599 |
| 594 // Now give memory out to the tiles until we're out, and build | 600 // Now give memory out to the tiles until we're out, and build |
| 595 // the needs-to-be-rasterized queue. | 601 // the needs-to-be-rasterized queue. |
| 596 unsigned schedule_priority = 1u; | 602 unsigned schedule_priority = 1u; |
| 597 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true; | 603 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true; |
| 598 bool had_enough_memory_to_schedule_tiles_needed_now = true; | 604 bool had_enough_memory_to_schedule_tiles_needed_now = true; |
| 599 | 605 |
| 600 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, | 606 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, |
| 601 global_state_.num_resources_limit); | 607 global_state_.num_resources_limit); |
| 602 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, | 608 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, |
| 603 global_state_.num_resources_limit); | 609 global_state_.num_resources_limit); |
| 604 MemoryUsage memory_usage(resource_pool_->memory_usage_bytes(), | 610 MemoryUsage memory_usage(resource_pool_->memory_usage_bytes(), |
| 605 resource_pool_->resource_count()); | 611 resource_pool_->resource_count()); |
| 606 | 612 |
| 607 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( | 613 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 608 client_->BuildRasterQueue(global_state_.tree_priority, | 614 client_->BuildRasterQueue(global_state_.tree_priority, |
| 609 RasterTilePriorityQueue::Type::ALL)); | 615 RasterTilePriorityQueue::Type::ALL)); |
| 610 std::unique_ptr<EvictionTilePriorityQueue> eviction_priority_queue; | 616 std::unique_ptr<EvictionTilePriorityQueue> eviction_priority_queue; |
| 611 std::vector<PrioritizedTile> tiles_that_need_to_be_rasterized; | 617 PrioritizedWorkToSchedule work_to_schedule; |
| 612 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | 618 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { |
| 613 const PrioritizedTile& prioritized_tile = raster_priority_queue->Top(); | 619 const PrioritizedTile& prioritized_tile = raster_priority_queue->Top(); |
| 614 Tile* tile = prioritized_tile.tile(); | 620 Tile* tile = prioritized_tile.tile(); |
| 615 TilePriority priority = prioritized_tile.priority(); | 621 TilePriority priority = prioritized_tile.priority(); |
| 616 | 622 |
| 617 if (TilePriorityViolatesMemoryPolicy(priority)) { | 623 if (TilePriorityViolatesMemoryPolicy(priority)) { |
| 618 TRACE_EVENT_INSTANT0( | 624 TRACE_EVENT_INSTANT0( |
| 619 "cc", "TileManager::AssignGpuMemory tile violates memory policy", | 625 "cc", "TileManager::AssignGpuMemory tile violates memory policy", |
| 620 TRACE_EVENT_SCOPE_THREAD); | 626 TRACE_EVENT_SCOPE_THREAD); |
| 621 break; | 627 break; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 634 if (is_solid_color) { | 640 if (is_solid_color) { |
| 635 tile->draw_info().set_solid_color(color); | 641 tile->draw_info().set_solid_color(color); |
| 636 tile->draw_info().set_was_ever_ready_to_draw(); | 642 tile->draw_info().set_was_ever_ready_to_draw(); |
| 637 if (!tile_is_needed_now) | 643 if (!tile_is_needed_now) |
| 638 tile->draw_info().set_was_a_prepaint_tile(); | 644 tile->draw_info().set_was_a_prepaint_tile(); |
| 639 client_->NotifyTileStateChanged(tile); | 645 client_->NotifyTileStateChanged(tile); |
| 640 continue; | 646 continue; |
| 641 } | 647 } |
| 642 } | 648 } |
| 643 | 649 |
| 650 // Prepaint tiles that are far away are only processed for images. | |
| 651 if (!tile->required_for_activation() && !tile->required_for_draw() && | |
|
ericrk
2016/05/24 23:42:34
Just to make sure - low resolution tiles are not r
vmpstr
2016/06/07 20:43:55
Yeah, LOW_RESOLUTION tiles are neither required fo
| |
| 652 priority.distance_to_visible > | |
| 653 max_preraster_distance_in_screen_pixels_) { | |
| 654 work_to_schedule.tiles_to_process_for_images.push_back(prioritized_tile); | |
| 655 continue; | |
| 656 } | |
| 657 | |
| 644 // We won't be able to schedule this tile, so break out early. | 658 // We won't be able to schedule this tile, so break out early. |
| 645 if (tiles_that_need_to_be_rasterized.size() >= | 659 if (work_to_schedule.tiles_to_raster.size() >= |
| 646 scheduled_raster_task_limit_) { | 660 scheduled_raster_task_limit_) { |
| 647 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 661 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 648 break; | 662 break; |
| 649 } | 663 } |
| 650 | 664 |
| 651 tile->scheduled_priority_ = schedule_priority++; | 665 tile->scheduled_priority_ = schedule_priority++; |
| 652 | 666 |
| 653 DCHECK(tile->draw_info().mode() == TileDrawInfo::OOM_MODE || | 667 DCHECK(tile->draw_info().mode() == TileDrawInfo::OOM_MODE || |
| 654 !tile->draw_info().IsReadyToDraw()); | 668 !tile->draw_info().IsReadyToDraw()); |
| 655 | 669 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 680 // If we couldn't fit the tile into our current memory limit, then we're | 694 // If we couldn't fit the tile into our current memory limit, then we're |
| 681 // done. | 695 // done. |
| 682 if (!memory_usage_is_within_limit) { | 696 if (!memory_usage_is_within_limit) { |
| 683 if (tile_is_needed_now) | 697 if (tile_is_needed_now) |
| 684 had_enough_memory_to_schedule_tiles_needed_now = false; | 698 had_enough_memory_to_schedule_tiles_needed_now = false; |
| 685 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 699 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 686 break; | 700 break; |
| 687 } | 701 } |
| 688 | 702 |
| 689 memory_usage += memory_required_by_tile_to_be_scheduled; | 703 memory_usage += memory_required_by_tile_to_be_scheduled; |
| 690 tiles_that_need_to_be_rasterized.push_back(prioritized_tile); | 704 work_to_schedule.tiles_to_raster.push_back(prioritized_tile); |
| 691 | 705 |
| 692 // Since we scheduled the tile, set whether it was a prepaint or not | 706 // Since we scheduled the tile, set whether it was a prepaint or not |
| 693 // assuming that the tile will successfully finish running. We don't have | 707 // assuming that the tile will successfully finish running. We don't have |
| 694 // priority information at the time the tile completes, so it should be done | 708 // priority information at the time the tile completes, so it should be done |
| 695 // here. | 709 // here. |
| 696 if (!tile_is_needed_now) | 710 if (!tile_is_needed_now) |
| 697 tile->draw_info().set_was_a_prepaint_tile(); | 711 tile->draw_info().set_was_a_prepaint_tile(); |
| 698 } | 712 } |
| 699 | 713 |
| 700 // Note that we should try and further reduce memory in case the above loop | 714 // Note that we should try and further reduce memory in case the above loop |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 712 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); | 726 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); |
| 713 DCHECK_GE(memory_stats_from_last_assign_.total_bytes_used, 0); | 727 DCHECK_GE(memory_stats_from_last_assign_.total_bytes_used, 0); |
| 714 memory_stats_from_last_assign_.had_enough_memory = | 728 memory_stats_from_last_assign_.had_enough_memory = |
| 715 had_enough_memory_to_schedule_tiles_needed_now; | 729 had_enough_memory_to_schedule_tiles_needed_now; |
| 716 | 730 |
| 717 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", | 731 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", |
| 718 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 732 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
| 719 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 733 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
| 720 "had_enough_memory_to_schedule_tiles_needed_now", | 734 "had_enough_memory_to_schedule_tiles_needed_now", |
| 721 had_enough_memory_to_schedule_tiles_needed_now); | 735 had_enough_memory_to_schedule_tiles_needed_now); |
| 722 return tiles_that_need_to_be_rasterized; | 736 return work_to_schedule; |
| 723 } | 737 } |
| 724 | 738 |
| 725 void TileManager::FreeResourcesForTile(Tile* tile) { | 739 void TileManager::FreeResourcesForTile(Tile* tile) { |
| 726 TileDrawInfo& draw_info = tile->draw_info(); | 740 TileDrawInfo& draw_info = tile->draw_info(); |
| 727 if (draw_info.resource_) { | 741 if (draw_info.resource_) { |
| 728 resource_pool_->ReleaseResource(draw_info.resource_, tile->id()); | 742 resource_pool_->ReleaseResource(draw_info.resource_, tile->id()); |
| 729 draw_info.resource_ = nullptr; | 743 draw_info.resource_ = nullptr; |
| 730 } | 744 } |
| 731 } | 745 } |
| 732 | 746 |
| 733 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( | 747 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( |
| 734 Tile* tile) { | 748 Tile* tile) { |
| 735 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); | 749 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); |
| 736 FreeResourcesForTile(tile); | 750 FreeResourcesForTile(tile); |
| 737 if (was_ready_to_draw) | 751 if (was_ready_to_draw) |
| 738 client_->NotifyTileStateChanged(tile); | 752 client_->NotifyTileStateChanged(tile); |
| 739 } | 753 } |
| 740 | 754 |
| 741 void TileManager::ScheduleTasks( | 755 void TileManager::ScheduleTasks( |
| 742 const std::vector<PrioritizedTile>& tiles_that_need_to_be_rasterized) { | 756 const PrioritizedWorkToSchedule& work_to_schedule) { |
| 757 const std::vector<PrioritizedTile>& tiles_that_need_to_be_rasterized = | |
| 758 work_to_schedule.tiles_to_raster; | |
| 743 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", "count", | 759 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", "count", |
| 744 tiles_that_need_to_be_rasterized.size()); | 760 tiles_that_need_to_be_rasterized.size()); |
| 745 | 761 |
| 746 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); | 762 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); |
| 747 | 763 |
| 748 if (!has_scheduled_tile_tasks_) { | 764 if (!has_scheduled_tile_tasks_) { |
| 749 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 765 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
| 750 } | 766 } |
| 751 | 767 |
| 752 // Cancel existing OnTaskSetFinished callbacks. | 768 // Cancel existing OnTaskSetFinished callbacks. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 // A tile should use a foreground task cateogry if it is either blocking | 821 // A tile should use a foreground task cateogry if it is either blocking |
| 806 // future compositing (required for draw or required for activation), or if | 822 // future compositing (required for draw or required for activation), or if |
| 807 // it has a priority bin of NOW for another reason (low resolution tiles). | 823 // it has a priority bin of NOW for another reason (low resolution tiles). |
| 808 bool use_foreground_category = | 824 bool use_foreground_category = |
| 809 tile->required_for_draw() || tile->required_for_activation() || | 825 tile->required_for_draw() || tile->required_for_activation() || |
| 810 prioritized_tile.priority().priority_bin == TilePriority::NOW; | 826 prioritized_tile.priority().priority_bin == TilePriority::NOW; |
| 811 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++, | 827 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++, |
| 812 use_foreground_category); | 828 use_foreground_category); |
| 813 } | 829 } |
| 814 | 830 |
| 831 const std::vector<PrioritizedTile>& tiles_to_process_for_images = | |
| 832 work_to_schedule.tiles_to_process_for_images; | |
| 833 std::vector<std::pair<DrawImage, scoped_refptr<TileTask>>> new_locked_images; | |
| 834 for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { | |
| 835 Tile* tile = prioritized_tile.tile(); | |
| 836 | |
| 837 std::vector<DrawImage> images; | |
| 838 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | |
| 839 tile->enclosing_layer_rect(), tile->contents_scale(), &images); | |
| 840 ImageDecodeController::TracingInfo tracing_info( | |
| 841 prepare_tiles_count_, prioritized_tile.priority().priority_bin); | |
| 842 for (DrawImage& draw_image : images) { | |
| 843 scoped_refptr<TileTask> task; | |
| 844 bool need_to_unref_when_finished = | |
| 845 image_decode_controller_->GetTaskForImageAndRef(draw_image, | |
| 846 tracing_info, &task); | |
| 847 // We only care about images that need to be locked (ie they need to be | |
| 848 // unreffed later). | |
| 849 if (!need_to_unref_when_finished) | |
| 850 continue; | |
| 851 new_locked_images.emplace_back(draw_image, task); | |
| 852 | |
| 853 // If there's no actual task associated with this image, then we're done. | |
| 854 if (!task) | |
| 855 continue; | |
| 856 | |
| 857 auto decode_it = std::find_if(graph_.nodes.begin(), graph_.nodes.end(), | |
| 858 [&task](const TaskGraph::Node& node) { | |
| 859 return node.task == task.get(); | |
| 860 }); | |
| 861 // If this task is already in the graph, then we don't have to insert it. | |
| 862 if (decode_it != graph_.nodes.end()) | |
| 863 continue; | |
| 864 | |
| 865 InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); | |
| 866 all_count++; | |
| 867 graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); | |
| 868 } | |
| 869 } | |
| 870 | |
| 871 for (auto& draw_image_pair : locked_images_) | |
| 872 image_decode_controller_->UnrefImage(draw_image_pair.first); | |
| 873 // The old locked images have to stay around until past the ScheduleTasks call | |
| 874 // below, so we do a swap instead of a move. | |
| 875 locked_images_.swap(new_locked_images); | |
| 876 | |
| 815 // Insert nodes for our task completion tasks. We enqueue these using | 877 // Insert nodes for our task completion tasks. We enqueue these using |
| 816 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and | 878 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and |
| 817 // we'd like to run these tasks as soon as possible. | 879 // we'd like to run these tasks as soon as possible. |
| 818 InsertNodeForTask(&graph_, required_for_activation_done_task.get(), | 880 InsertNodeForTask(&graph_, required_for_activation_done_task.get(), |
| 819 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, | 881 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, |
| 820 kRequiredForActivationDoneTaskPriority, | 882 kRequiredForActivationDoneTaskPriority, |
| 821 required_for_activate_count); | 883 required_for_activate_count); |
| 822 InsertNodeForTask(&graph_, required_for_draw_done_task.get(), | 884 InsertNodeForTask(&graph_, required_for_draw_done_task.get(), |
| 823 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, | 885 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, |
| 824 kRequiredForDrawDoneTaskPriority, required_for_draw_count); | 886 kRequiredForDrawDoneTaskPriority, required_for_draw_count); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1058 } | 1120 } |
| 1059 } | 1121 } |
| 1060 } | 1122 } |
| 1061 | 1123 |
| 1062 void TileManager::CheckIfMoreTilesNeedToBePrepared() { | 1124 void TileManager::CheckIfMoreTilesNeedToBePrepared() { |
| 1063 tile_task_manager_->CheckForCompletedTasks(); | 1125 tile_task_manager_->CheckForCompletedTasks(); |
| 1064 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1126 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1065 | 1127 |
| 1066 // When OOM, keep re-assigning memory until we reach a steady state | 1128 // When OOM, keep re-assigning memory until we reach a steady state |
| 1067 // where top-priority tiles are initialized. | 1129 // where top-priority tiles are initialized. |
| 1068 std::vector<PrioritizedTile> tiles_that_need_to_be_rasterized = | 1130 PrioritizedWorkToSchedule work_to_schedule = AssignGpuMemoryToTiles(); |
| 1069 AssignGpuMemoryToTiles(); | |
| 1070 | 1131 |
| 1071 // Inform the client that will likely require a draw if the highest priority | 1132 // Inform the client that will likely require a draw if the highest priority |
| 1072 // tile that will be rasterized is required for draw. | 1133 // tile that will be rasterized is required for draw. |
| 1073 client_->SetIsLikelyToRequireADraw( | 1134 client_->SetIsLikelyToRequireADraw( |
| 1074 !tiles_that_need_to_be_rasterized.empty() && | 1135 !work_to_schedule.tiles_to_raster.empty() && |
| 1075 tiles_that_need_to_be_rasterized.front().tile()->required_for_draw()); | 1136 work_to_schedule.tiles_to_raster.front().tile()->required_for_draw()); |
| 1076 | 1137 |
| 1077 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 1138 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 1078 // steady memory state. Keep scheduling tasks until we reach this state. | 1139 // steady memory state. Keep scheduling tasks until we reach this state. |
| 1079 if (!tiles_that_need_to_be_rasterized.empty()) { | 1140 if (!work_to_schedule.tiles_to_raster.empty()) { |
| 1080 ScheduleTasks(tiles_that_need_to_be_rasterized); | 1141 ScheduleTasks(work_to_schedule); |
| 1081 return; | 1142 return; |
| 1082 } | 1143 } |
| 1083 | 1144 |
| 1145 // If we're not in SMOOTHNESS_TAKES_PRIORITY mode, we should unlock all | |
| 1146 // images since we're technically going idle here at least for this frame. | |
| 1147 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) { | |
| 1148 for (auto& draw_image_pair : locked_images_) | |
| 1149 image_decode_controller_->UnrefImage(draw_image_pair.first); | |
| 1150 locked_images_.clear(); | |
| 1151 } | |
| 1152 | |
| 1084 FreeResourcesForReleasedTiles(); | 1153 FreeResourcesForReleasedTiles(); |
| 1085 | 1154 |
| 1086 resource_pool_->ReduceResourceUsage(); | 1155 resource_pool_->ReduceResourceUsage(); |
| 1087 image_decode_controller_->ReduceCacheUsage(); | 1156 image_decode_controller_->ReduceCacheUsage(); |
| 1088 | 1157 |
| 1089 signals_.all_tile_tasks_completed = true; | 1158 signals_.all_tile_tasks_completed = true; |
| 1090 signals_check_notifier_.Schedule(); | 1159 signals_check_notifier_.Schedule(); |
| 1091 | 1160 |
| 1092 // We don't reserve memory for required-for-activation tiles during | 1161 // We don't reserve memory for required-for-activation tiles during |
| 1093 // accelerated gestures, so we just postpone activation when we don't | 1162 // accelerated gestures, so we just postpone activation when we don't |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1242 | 1311 |
| 1243 void TileManager::Signals::reset() { | 1312 void TileManager::Signals::reset() { |
| 1244 ready_to_activate = false; | 1313 ready_to_activate = false; |
| 1245 did_notify_ready_to_activate = false; | 1314 did_notify_ready_to_activate = false; |
| 1246 ready_to_draw = false; | 1315 ready_to_draw = false; |
| 1247 did_notify_ready_to_draw = false; | 1316 did_notify_ready_to_draw = false; |
| 1248 all_tile_tasks_completed = false; | 1317 all_tile_tasks_completed = false; |
| 1249 did_notify_all_tile_tasks_completed = false; | 1318 did_notify_all_tile_tasks_completed = false; |
| 1250 } | 1319 } |
| 1251 | 1320 |
| 1321 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | |
| 1322 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | |
| 1323 PrioritizedWorkToSchedule&& other) = default; | |
| 1324 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | |
| 1325 | |
| 1252 } // namespace cc | 1326 } // namespace cc |
| OLD | NEW |