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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 CleanUpReleasedTiles(); | 241 CleanUpReleasedTiles(); |
| 242 | 242 |
| 243 tile_task_runner_ = nullptr; | 243 tile_task_runner_ = nullptr; |
| 244 resource_pool_ = nullptr; | 244 resource_pool_ = nullptr; |
| 245 more_tiles_need_prepare_check_notifier_.Cancel(); | 245 more_tiles_need_prepare_check_notifier_.Cancel(); |
| 246 signals_check_notifier_.Cancel(); | 246 signals_check_notifier_.Cancel(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void TileManager::SetResources(ResourcePool* resource_pool, | 249 void TileManager::SetResources(ResourcePool* resource_pool, |
| 250 TileTaskRunner* tile_task_runner, | 250 TileTaskRunner* tile_task_runner, |
| 251 size_t scheduled_raster_task_limit) { | 251 size_t scheduled_raster_task_limit, |
| 252 bool is_using_gpu_rasterization) { | |
| 252 DCHECK(!tile_task_runner_); | 253 DCHECK(!tile_task_runner_); |
| 253 DCHECK(tile_task_runner); | 254 DCHECK(tile_task_runner); |
| 254 | 255 |
| 255 scheduled_raster_task_limit_ = scheduled_raster_task_limit; | 256 scheduled_raster_task_limit_ = scheduled_raster_task_limit; |
| 256 resource_pool_ = resource_pool; | 257 resource_pool_ = resource_pool; |
| 257 tile_task_runner_ = tile_task_runner; | 258 tile_task_runner_ = tile_task_runner; |
| 258 tile_task_runner_->SetClient(this); | 259 tile_task_runner_->SetClient(this); |
| 260 image_decode_controller_.SetIsUsingGpuRasterization( | |
| 261 is_using_gpu_rasterization); | |
| 259 } | 262 } |
| 260 | 263 |
| 261 void TileManager::Release(Tile* tile) { | 264 void TileManager::Release(Tile* tile) { |
| 262 released_tiles_.push_back(tile); | 265 released_tiles_.push_back(tile); |
| 263 } | 266 } |
| 264 | 267 |
| 265 void TileManager::FreeResourcesForReleasedTiles() { | 268 void TileManager::FreeResourcesForReleasedTiles() { |
| 266 for (auto* tile : released_tiles_) | 269 for (auto* tile : released_tiles_) |
| 267 FreeResourcesForTile(tile); | 270 FreeResourcesForTile(tile); |
| 268 } | 271 } |
| 269 | 272 |
| 270 void TileManager::CleanUpReleasedTiles() { | 273 void TileManager::CleanUpReleasedTiles() { |
| 271 std::vector<Tile*> tiles_to_retain; | 274 std::vector<Tile*> tiles_to_retain; |
| 272 for (auto* tile : released_tiles_) { | 275 for (auto* tile : released_tiles_) { |
| 273 if (tile->HasRasterTask()) { | 276 if (tile->HasRasterTask()) { |
| 274 tiles_to_retain.push_back(tile); | 277 tiles_to_retain.push_back(tile); |
| 275 continue; | 278 continue; |
| 276 } | 279 } |
| 277 | 280 |
| 278 DCHECK(!tile->draw_info().has_resource()); | 281 DCHECK(!tile->draw_info().has_resource()); |
| 279 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 282 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| 280 tiles_.erase(tile->id()); | 283 tiles_.erase(tile->id()); |
| 281 | 284 |
| 282 image_decode_controller_.SubtractLayerUsedCount(tile->layer_id()); | |
| 283 delete tile; | 285 delete tile; |
| 284 } | 286 } |
| 285 released_tiles_.swap(tiles_to_retain); | 287 released_tiles_.swap(tiles_to_retain); |
| 286 } | 288 } |
| 287 | 289 |
| 288 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) { | 290 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) { |
| 289 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set", | 291 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set", |
| 290 TaskSetName(task_set)); | 292 TaskSetName(task_set)); |
| 291 DCHECK(resource_pool_); | 293 DCHECK(resource_pool_); |
| 292 DCHECK(tile_task_runner_); | 294 DCHECK(tile_task_runner_); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 has_scheduled_tile_tasks_ = true; | 622 has_scheduled_tile_tasks_ = true; |
| 621 | 623 |
| 622 // Build a new task queue containing all task currently needed. Tasks | 624 // Build a new task queue containing all task currently needed. Tasks |
| 623 // are added in order of priority, highest priority task first. | 625 // are added in order of priority, highest priority task first. |
| 624 for (auto& prioritized_tile : tiles_that_need_to_be_rasterized) { | 626 for (auto& prioritized_tile : tiles_that_need_to_be_rasterized) { |
| 625 Tile* tile = prioritized_tile.tile(); | 627 Tile* tile = prioritized_tile.tile(); |
| 626 | 628 |
| 627 DCHECK(tile->draw_info().requires_resource()); | 629 DCHECK(tile->draw_info().requires_resource()); |
| 628 DCHECK(!tile->draw_info().resource_); | 630 DCHECK(!tile->draw_info().resource_); |
| 629 | 631 |
| 630 if (!tile->raster_task_.get()) | 632 if (!tile->raster_task_) |
| 631 tile->raster_task_ = CreateRasterTask(prioritized_tile); | 633 tile->raster_task_ = CreateRasterTask(prioritized_tile); |
| 632 | 634 |
| 633 TaskSetCollection task_sets; | 635 TaskSetCollection task_sets; |
| 634 if (tile->required_for_activation()) | 636 if (tile->required_for_activation()) |
| 635 task_sets.set(REQUIRED_FOR_ACTIVATION); | 637 task_sets.set(REQUIRED_FOR_ACTIVATION); |
| 636 if (tile->required_for_draw()) | 638 if (tile->required_for_draw()) |
| 637 task_sets.set(REQUIRED_FOR_DRAW); | 639 task_sets.set(REQUIRED_FOR_DRAW); |
| 638 task_sets.set(ALL); | 640 task_sets.set(ALL); |
| 639 raster_queue_.items.push_back( | 641 raster_queue_.items.push_back( |
| 640 TileTaskQueue::Item(tile->raster_task_.get(), task_sets)); | 642 TileTaskQueue::Item(tile->raster_task_.get(), task_sets)); |
| 641 } | 643 } |
| 642 | 644 |
| 643 // We must reduce the amount of unused resoruces before calling | 645 // We must reduce the amount of unused resoruces before calling |
| 644 // ScheduleTasks to prevent usage from rising above limits. | 646 // ScheduleTasks to prevent usage from rising above limits. |
| 645 resource_pool_->ReduceResourceUsage(); | 647 resource_pool_->ReduceResourceUsage(); |
| 648 image_decode_controller_.ReduceCacheUsage(); | |
|
ericrk
2015/12/04 00:50:46
should we also ReduceCacheUsage in CheckIfMoreTile
| |
| 646 | 649 |
| 647 // Schedule running of |raster_queue_|. This replaces any previously | 650 // Schedule running of |raster_queue_|. This replaces any previously |
| 648 // scheduled tasks and effectively cancels all tasks not present | 651 // scheduled tasks and effectively cancels all tasks not present |
| 649 // in |raster_queue_|. | 652 // in |raster_queue_|. |
| 650 tile_task_runner_->ScheduleTasks(&raster_queue_); | 653 tile_task_runner_->ScheduleTasks(&raster_queue_); |
| 651 | 654 |
| 652 // It's now safe to clean up orphan tasks as raster worker pool is not | 655 // It's now safe to clean up orphan tasks as raster worker pool is not |
| 653 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has | 656 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has |
| 654 // been called. | 657 // been called. |
| 655 orphan_raster_tasks_.clear(); | 658 orphan_raster_tasks_.clear(); |
| 656 | 659 |
| 657 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; | 660 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; |
| 658 } | 661 } |
| 659 | 662 |
| 660 scoped_refptr<RasterTask> TileManager::CreateRasterTask( | 663 scoped_refptr<RasterTask> TileManager::CreateRasterTask( |
| 661 const PrioritizedTile& prioritized_tile) { | 664 const PrioritizedTile& prioritized_tile) { |
| 662 Tile* tile = prioritized_tile.tile(); | 665 Tile* tile = prioritized_tile.tile(); |
| 666 | |
| 667 // Get the resource. | |
| 663 uint64_t resource_content_id = 0; | 668 uint64_t resource_content_id = 0; |
| 664 Resource* resource = nullptr; | 669 Resource* resource = nullptr; |
| 665 if (use_partial_raster_ && tile->invalidated_id()) { | 670 if (use_partial_raster_ && tile->invalidated_id()) { |
| 666 // TODO(danakj): For resources that are in use, we should still grab them | 671 // TODO(danakj): For resources that are in use, we should still grab them |
| 667 // and copy from them instead of rastering everything. crbug.com/492754 | 672 // and copy from them instead of rastering everything. crbug.com/492754 |
| 668 resource = | 673 resource = |
| 669 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); | 674 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); |
| 670 } | 675 } |
| 671 if (resource) { | 676 if (resource) { |
| 672 resource_content_id = tile->invalidated_id(); | 677 resource_content_id = tile->invalidated_id(); |
| 673 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); | 678 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); |
| 674 DCHECK_EQ(tile->desired_texture_size().ToString(), | 679 DCHECK_EQ(tile->desired_texture_size().ToString(), |
| 675 resource->size().ToString()); | 680 resource->size().ToString()); |
| 676 } else { | 681 } else { |
| 677 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), | 682 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), |
| 678 DetermineResourceFormat(tile)); | 683 DetermineResourceFormat(tile)); |
| 679 } | 684 } |
| 680 | 685 |
| 681 // Create and queue all image decode tasks that this tile depends on. | 686 // Create and queue all image decode tasks that this tile depends on. |
| 682 ImageDecodeTask::Vector decode_tasks; | 687 ImageDecodeTask::Vector decode_tasks; |
| 683 std::vector<DrawImage> images; | 688 std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()]; |
| 689 images.clear(); | |
| 684 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | 690 prioritized_tile.raster_source()->GetDiscardableImagesInRect( |
| 685 tile->enclosing_layer_rect(), tile->contents_scale(), &images); | 691 tile->enclosing_layer_rect(), tile->contents_scale(), &images); |
| 686 for (const auto& image : images) { | 692 for (auto it = images.begin(); it != images.end();) { |
| 687 decode_tasks.push_back(image_decode_controller_.GetTaskForImage( | 693 scoped_refptr<ImageDecodeTask> task; |
| 688 image, tile->layer_id(), prepare_tiles_count_)); | 694 bool need_to_unref_when_finished = |
| 695 image_decode_controller_.GetTaskForImageAndRef( | |
| 696 *it, prepare_tiles_count_, &task); | |
| 697 if (task) | |
| 698 decode_tasks.push_back(task); | |
| 699 | |
| 700 if (need_to_unref_when_finished) | |
| 701 ++it; | |
| 702 else | |
| 703 it = images.erase(it); | |
| 689 } | 704 } |
| 690 | 705 |
| 691 return make_scoped_refptr(new RasterTaskImpl( | 706 return make_scoped_refptr(new RasterTaskImpl( |
| 692 resource, prioritized_tile.raster_source(), tile->content_rect(), | 707 resource, prioritized_tile.raster_source(), tile->content_rect(), |
| 693 tile->invalidated_content_rect(), tile->contents_scale(), | 708 tile->invalidated_content_rect(), tile->contents_scale(), |
| 694 prioritized_tile.priority().resolution, tile->layer_id(), | 709 prioritized_tile.priority().resolution, tile->layer_id(), |
| 695 prepare_tiles_count_, static_cast<const void*>(tile), tile->id(), | 710 prepare_tiles_count_, static_cast<const void*>(tile), tile->id(), |
| 696 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), | 711 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), |
| 697 tile->use_picture_analysis(), | 712 tile->use_picture_analysis(), |
| 698 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 713 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
| 699 tile->id(), resource), | 714 tile->id(), resource), |
| 700 &decode_tasks)); | 715 &decode_tasks)); |
| 701 } | 716 } |
| 702 | 717 |
| 703 void TileManager::OnRasterTaskCompleted( | 718 void TileManager::OnRasterTaskCompleted( |
| 704 Tile::Id tile_id, | 719 Tile::Id tile_id, |
| 705 Resource* resource, | 720 Resource* resource, |
| 706 const DisplayListRasterSource::SolidColorAnalysis& analysis, | 721 const DisplayListRasterSource::SolidColorAnalysis& analysis, |
| 707 bool was_canceled) { | 722 bool was_canceled) { |
| 708 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 723 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
| 709 | 724 |
| 710 Tile* tile = tiles_[tile_id]; | 725 Tile* tile = tiles_[tile_id]; |
| 711 DCHECK(tile->raster_task_.get()); | 726 DCHECK(tile->raster_task_.get()); |
| 712 orphan_raster_tasks_.push_back(tile->raster_task_); | 727 orphan_raster_tasks_.push_back(tile->raster_task_); |
| 713 tile->raster_task_ = nullptr; | 728 tile->raster_task_ = nullptr; |
| 714 | 729 |
| 730 // Unref all the images. | |
| 731 auto images_it = scheduled_draw_images_.find(tile->id()); | |
| 732 const std::vector<DrawImage>& images = images_it->second; | |
| 733 for (const auto& image : images) | |
| 734 image_decode_controller_.UnrefImage(image); | |
| 735 scheduled_draw_images_.erase(images_it); | |
| 736 | |
| 715 if (was_canceled) { | 737 if (was_canceled) { |
| 716 ++flush_stats_.canceled_count; | 738 ++flush_stats_.canceled_count; |
| 717 // TODO(ericrk): If more partial raster work is done in the future, it may | 739 // TODO(ericrk): If more partial raster work is done in the future, it may |
| 718 // be worth returning the resource to the pool with its previous ID (not | 740 // be worth returning the resource to the pool with its previous ID (not |
| 719 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method | 741 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method |
| 720 // of achieving this. | 742 // of achieving this. |
| 721 resource_pool_->ReleaseResource(resource, 0 /* content_id */); | 743 resource_pool_->ReleaseResource(resource, 0 /* content_id */); |
| 722 return; | 744 return; |
| 723 } | 745 } |
| 724 | 746 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 int source_frame_number, | 781 int source_frame_number, |
| 760 int flags) { | 782 int flags) { |
| 761 // We need to have a tile task worker pool to do anything meaningful with | 783 // We need to have a tile task worker pool to do anything meaningful with |
| 762 // tiles. | 784 // tiles. |
| 763 DCHECK(tile_task_runner_); | 785 DCHECK(tile_task_runner_); |
| 764 ScopedTilePtr tile( | 786 ScopedTilePtr tile( |
| 765 new Tile(this, info, layer_id, source_frame_number, flags)); | 787 new Tile(this, info, layer_id, source_frame_number, flags)); |
| 766 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 788 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| 767 | 789 |
| 768 tiles_[tile->id()] = tile.get(); | 790 tiles_[tile->id()] = tile.get(); |
| 769 image_decode_controller_.AddLayerUsedCount(tile->layer_id()); | |
| 770 return tile; | 791 return tile; |
| 771 } | 792 } |
| 772 | 793 |
| 773 void TileManager::SetTileTaskRunnerForTesting( | 794 void TileManager::SetTileTaskRunnerForTesting( |
| 774 TileTaskRunner* tile_task_runner) { | 795 TileTaskRunner* tile_task_runner) { |
| 775 tile_task_runner_ = tile_task_runner; | 796 tile_task_runner_ = tile_task_runner; |
| 776 tile_task_runner_->SetClient(this); | 797 tile_task_runner_->SetClient(this); |
| 777 } | 798 } |
| 778 | 799 |
| 779 bool TileManager::AreRequiredTilesReadyToDraw( | 800 bool TileManager::AreRequiredTilesReadyToDraw( |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1017 void TileManager::Signals::reset() { | 1038 void TileManager::Signals::reset() { |
| 1018 ready_to_activate = false; | 1039 ready_to_activate = false; |
| 1019 did_notify_ready_to_activate = false; | 1040 did_notify_ready_to_activate = false; |
| 1020 ready_to_draw = false; | 1041 ready_to_draw = false; |
| 1021 did_notify_ready_to_draw = false; | 1042 did_notify_ready_to_draw = false; |
| 1022 all_tile_tasks_completed = false; | 1043 all_tile_tasks_completed = false; |
| 1023 did_notify_all_tile_tasks_completed = false; | 1044 did_notify_all_tile_tasks_completed = false; |
| 1024 } | 1045 } |
| 1025 | 1046 |
| 1026 } // namespace cc | 1047 } // namespace cc |
| OLD | NEW |