| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 16 #include "base/trace_event/trace_event_argument.h" | 16 #include "base/trace_event/trace_event_argument.h" |
| 17 #include "cc/base/histograms.h" | 17 #include "cc/base/histograms.h" |
| 18 #include "cc/debug/devtools_instrumentation.h" | 18 #include "cc/debug/devtools_instrumentation.h" |
| 19 #include "cc/debug/frame_viewer_instrumentation.h" | 19 #include "cc/debug/frame_viewer_instrumentation.h" |
| 20 #include "cc/debug/traced_value.h" | 20 #include "cc/debug/traced_value.h" |
| 21 #include "cc/layers/picture_layer_impl.h" | 21 #include "cc/layers/picture_layer_impl.h" |
| 22 #include "cc/raster/raster_buffer.h" | 22 #include "cc/raster/raster_buffer.h" |
| 23 #include "cc/raster/tile_task_runner.h" | 23 #include "cc/raster/tile_task_runner.h" |
| 24 #include "cc/tiles/tile.h" | 24 #include "cc/tiles/tile.h" |
| 25 #include "ui/gfx/geometry/rect_conversions.h" | 25 #include "ui/gfx/geometry/rect_conversions.h" |
| 26 | 26 |
| 27 #include "ui/gfx/transform.h" |
| 27 namespace cc { | 28 namespace cc { |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // Flag to indicate whether we should try and detect that | 31 // Flag to indicate whether we should try and detect that |
| 31 // a tile is of solid color. | 32 // a tile is of solid color. |
| 32 const bool kUseColorEstimator = true; | 33 const bool kUseColorEstimator = true; |
| 33 | 34 |
| 34 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( | 35 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( |
| 35 ScopedRasterTaskTimer, | 36 ScopedRasterTaskTimer, |
| 36 "Compositing.%s.RasterTask.RasterUs", | 37 "Compositing.%s.RasterTask.RasterUs", |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 for (auto* tile : released_tiles_) { | 273 for (auto* tile : released_tiles_) { |
| 273 if (tile->HasRasterTask()) { | 274 if (tile->HasRasterTask()) { |
| 274 tiles_to_retain.push_back(tile); | 275 tiles_to_retain.push_back(tile); |
| 275 continue; | 276 continue; |
| 276 } | 277 } |
| 277 | 278 |
| 278 DCHECK(!tile->draw_info().has_resource()); | 279 DCHECK(!tile->draw_info().has_resource()); |
| 279 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 280 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| 280 tiles_.erase(tile->id()); | 281 tiles_.erase(tile->id()); |
| 281 | 282 |
| 282 image_decode_controller_.SubtractLayerUsedCount(tile->layer_id()); | |
| 283 delete tile; | 283 delete tile; |
| 284 } | 284 } |
| 285 released_tiles_.swap(tiles_to_retain); | 285 released_tiles_.swap(tiles_to_retain); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) { | 288 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) { |
| 289 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set", | 289 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set", |
| 290 TaskSetName(task_set)); | 290 TaskSetName(task_set)); |
| 291 DCHECK(resource_pool_); | 291 DCHECK(resource_pool_); |
| 292 DCHECK(tile_task_runner_); | 292 DCHECK(tile_task_runner_); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 has_scheduled_tile_tasks_ = true; | 620 has_scheduled_tile_tasks_ = true; |
| 621 | 621 |
| 622 // Build a new task queue containing all task currently needed. Tasks | 622 // Build a new task queue containing all task currently needed. Tasks |
| 623 // are added in order of priority, highest priority task first. | 623 // are added in order of priority, highest priority task first. |
| 624 for (auto& prioritized_tile : tiles_that_need_to_be_rasterized) { | 624 for (auto& prioritized_tile : tiles_that_need_to_be_rasterized) { |
| 625 Tile* tile = prioritized_tile.tile(); | 625 Tile* tile = prioritized_tile.tile(); |
| 626 | 626 |
| 627 DCHECK(tile->draw_info().requires_resource()); | 627 DCHECK(tile->draw_info().requires_resource()); |
| 628 DCHECK(!tile->draw_info().resource_); | 628 DCHECK(!tile->draw_info().resource_); |
| 629 | 629 |
| 630 if (!tile->raster_task_.get()) | 630 if (!tile->raster_task_) |
| 631 tile->raster_task_ = CreateRasterTask(prioritized_tile); | 631 tile->raster_task_ = CreateRasterTask(prioritized_tile); |
| 632 | 632 |
| 633 TaskSetCollection task_sets; | 633 TaskSetCollection task_sets; |
| 634 if (tile->required_for_activation()) | 634 if (tile->required_for_activation()) |
| 635 task_sets.set(REQUIRED_FOR_ACTIVATION); | 635 task_sets.set(REQUIRED_FOR_ACTIVATION); |
| 636 if (tile->required_for_draw()) | 636 if (tile->required_for_draw()) |
| 637 task_sets.set(REQUIRED_FOR_DRAW); | 637 task_sets.set(REQUIRED_FOR_DRAW); |
| 638 task_sets.set(ALL); | 638 task_sets.set(ALL); |
| 639 raster_queue_.items.push_back( | 639 raster_queue_.items.push_back( |
| 640 TileTaskQueue::Item(tile->raster_task_.get(), task_sets)); | 640 TileTaskQueue::Item(tile->raster_task_.get(), task_sets)); |
| 641 } | 641 } |
| 642 | 642 |
| 643 // We must reduce the amount of unused resoruces before calling | 643 // We must reduce the amount of unused resoruces before calling |
| 644 // ScheduleTasks to prevent usage from rising above limits. | 644 // ScheduleTasks to prevent usage from rising above limits. |
| 645 resource_pool_->ReduceResourceUsage(); | 645 resource_pool_->ReduceResourceUsage(); |
| 646 image_decode_controller_.ReduceCacheUsage(); |
| 646 | 647 |
| 647 // Schedule running of |raster_queue_|. This replaces any previously | 648 // Schedule running of |raster_queue_|. This replaces any previously |
| 648 // scheduled tasks and effectively cancels all tasks not present | 649 // scheduled tasks and effectively cancels all tasks not present |
| 649 // in |raster_queue_|. | 650 // in |raster_queue_|. |
| 650 tile_task_runner_->ScheduleTasks(&raster_queue_); | 651 tile_task_runner_->ScheduleTasks(&raster_queue_); |
| 651 | 652 |
| 652 // It's now safe to clean up orphan tasks as raster worker pool is not | 653 // 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 | 654 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has |
| 654 // been called. | 655 // been called. |
| 655 orphan_raster_tasks_.clear(); | 656 orphan_raster_tasks_.clear(); |
| 656 | 657 |
| 657 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; | 658 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; |
| 658 } | 659 } |
| 659 | 660 |
| 660 scoped_refptr<RasterTask> TileManager::CreateRasterTask( | 661 scoped_refptr<RasterTask> TileManager::CreateRasterTask( |
| 661 const PrioritizedTile& prioritized_tile) { | 662 const PrioritizedTile& prioritized_tile) { |
| 662 Tile* tile = prioritized_tile.tile(); | 663 Tile* tile = prioritized_tile.tile(); |
| 664 |
| 665 // Get the resource. |
| 663 uint64_t resource_content_id = 0; | 666 uint64_t resource_content_id = 0; |
| 664 Resource* resource = nullptr; | 667 Resource* resource = nullptr; |
| 665 if (use_partial_raster_ && tile->invalidated_id()) { | 668 if (use_partial_raster_ && tile->invalidated_id()) { |
| 666 // TODO(danakj): For resources that are in use, we should still grab them | 669 // 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 | 670 // and copy from them instead of rastering everything. crbug.com/492754 |
| 668 resource = | 671 resource = |
| 669 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); | 672 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); |
| 670 } | 673 } |
| 671 if (resource) { | 674 if (resource) { |
| 672 resource_content_id = tile->invalidated_id(); | 675 resource_content_id = tile->invalidated_id(); |
| 673 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); | 676 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); |
| 674 DCHECK_EQ(tile->desired_texture_size().ToString(), | 677 DCHECK_EQ(tile->desired_texture_size().ToString(), |
| 675 resource->size().ToString()); | 678 resource->size().ToString()); |
| 676 } else { | 679 } else { |
| 677 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), | 680 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), |
| 678 DetermineResourceFormat(tile)); | 681 DetermineResourceFormat(tile)); |
| 679 } | 682 } |
| 680 | 683 |
| 681 // Create and queue all image decode tasks that this tile depends on. | 684 // Create and queue all image decode tasks that this tile depends on. |
| 682 ImageDecodeTask::Vector decode_tasks; | 685 ImageDecodeTask::Vector decode_tasks; |
| 683 std::vector<DrawImage> images; | 686 std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()]; |
| 687 images.clear(); |
| 684 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | 688 prioritized_tile.raster_source()->GetDiscardableImagesInRect( |
| 685 tile->enclosing_layer_rect(), tile->contents_scale(), &images); | 689 tile->enclosing_layer_rect(), tile->contents_scale(), &images); |
| 686 for (const auto& image : images) { | 690 for (const auto& image : images) { |
| 687 decode_tasks.push_back(image_decode_controller_.GetTaskForImage( | 691 scoped_refptr<ImageDecodeTask> task = |
| 688 image, tile->layer_id(), prepare_tiles_count_)); | 692 image_decode_controller_.GetTaskForImageAndRef(image, |
| 693 prepare_tiles_count_); |
| 694 if (task) |
| 695 decode_tasks.push_back(task); |
| 689 } | 696 } |
| 690 | 697 |
| 691 return make_scoped_refptr(new RasterTaskImpl( | 698 return make_scoped_refptr(new RasterTaskImpl( |
| 692 resource, prioritized_tile.raster_source(), tile->content_rect(), | 699 resource, prioritized_tile.raster_source(), tile->content_rect(), |
| 693 tile->invalidated_content_rect(), tile->contents_scale(), | 700 tile->invalidated_content_rect(), tile->contents_scale(), |
| 694 prioritized_tile.priority().resolution, tile->layer_id(), | 701 prioritized_tile.priority().resolution, tile->layer_id(), |
| 695 prepare_tiles_count_, static_cast<const void*>(tile), tile->id(), | 702 prepare_tiles_count_, static_cast<const void*>(tile), tile->id(), |
| 696 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), | 703 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), |
| 697 tile->use_picture_analysis(), | 704 tile->use_picture_analysis(), |
| 698 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 705 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
| 699 tile->id(), resource), | 706 tile->id(), resource), |
| 700 &decode_tasks)); | 707 &decode_tasks)); |
| 701 } | 708 } |
| 702 | 709 |
| 703 void TileManager::OnRasterTaskCompleted( | 710 void TileManager::OnRasterTaskCompleted( |
| 704 Tile::Id tile_id, | 711 Tile::Id tile_id, |
| 705 Resource* resource, | 712 Resource* resource, |
| 706 const DisplayListRasterSource::SolidColorAnalysis& analysis, | 713 const DisplayListRasterSource::SolidColorAnalysis& analysis, |
| 707 bool was_canceled) { | 714 bool was_canceled) { |
| 708 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 715 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
| 709 | 716 |
| 710 Tile* tile = tiles_[tile_id]; | 717 Tile* tile = tiles_[tile_id]; |
| 711 DCHECK(tile->raster_task_.get()); | 718 DCHECK(tile->raster_task_.get()); |
| 712 orphan_raster_tasks_.push_back(tile->raster_task_); | 719 orphan_raster_tasks_.push_back(tile->raster_task_); |
| 713 tile->raster_task_ = nullptr; | 720 tile->raster_task_ = nullptr; |
| 714 | 721 |
| 722 // Unref all the images. |
| 723 auto images_it = scheduled_draw_images_.find(tile->id()); |
| 724 const std::vector<DrawImage>& images = images_it->second; |
| 725 for (const auto& image : images) { |
| 726 const DrawImage& scaled_image = image.ApplyScale(tile->contents_scale()); |
| 727 image_decode_controller_.UnrefImage(scaled_image); |
| 728 } |
| 729 scheduled_draw_images_.erase(images_it); |
| 730 |
| 715 if (was_canceled) { | 731 if (was_canceled) { |
| 716 ++flush_stats_.canceled_count; | 732 ++flush_stats_.canceled_count; |
| 717 // TODO(ericrk): If more partial raster work is done in the future, it may | 733 // 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 | 734 // be worth returning the resource to the pool with its previous ID (not |
| 719 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method | 735 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method |
| 720 // of achieving this. | 736 // of achieving this. |
| 721 resource_pool_->ReleaseResource(resource, 0 /* content_id */); | 737 resource_pool_->ReleaseResource(resource, 0 /* content_id */); |
| 722 return; | 738 return; |
| 723 } | 739 } |
| 724 | 740 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 int source_frame_number, | 775 int source_frame_number, |
| 760 int flags) { | 776 int flags) { |
| 761 // We need to have a tile task worker pool to do anything meaningful with | 777 // We need to have a tile task worker pool to do anything meaningful with |
| 762 // tiles. | 778 // tiles. |
| 763 DCHECK(tile_task_runner_); | 779 DCHECK(tile_task_runner_); |
| 764 ScopedTilePtr tile( | 780 ScopedTilePtr tile( |
| 765 new Tile(this, info, layer_id, source_frame_number, flags)); | 781 new Tile(this, info, layer_id, source_frame_number, flags)); |
| 766 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 782 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| 767 | 783 |
| 768 tiles_[tile->id()] = tile.get(); | 784 tiles_[tile->id()] = tile.get(); |
| 769 image_decode_controller_.AddLayerUsedCount(tile->layer_id()); | |
| 770 return tile; | 785 return tile; |
| 771 } | 786 } |
| 772 | 787 |
| 773 void TileManager::SetTileTaskRunnerForTesting( | 788 void TileManager::SetTileTaskRunnerForTesting( |
| 774 TileTaskRunner* tile_task_runner) { | 789 TileTaskRunner* tile_task_runner) { |
| 775 tile_task_runner_ = tile_task_runner; | 790 tile_task_runner_ = tile_task_runner; |
| 776 tile_task_runner_->SetClient(this); | 791 tile_task_runner_->SetClient(this); |
| 777 } | 792 } |
| 778 | 793 |
| 779 bool TileManager::AreRequiredTilesReadyToDraw( | 794 bool TileManager::AreRequiredTilesReadyToDraw( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 void TileManager::Signals::reset() { | 1020 void TileManager::Signals::reset() { |
| 1006 ready_to_activate = false; | 1021 ready_to_activate = false; |
| 1007 did_notify_ready_to_activate = false; | 1022 did_notify_ready_to_activate = false; |
| 1008 ready_to_draw = false; | 1023 ready_to_draw = false; |
| 1009 did_notify_ready_to_draw = false; | 1024 did_notify_ready_to_draw = false; |
| 1010 all_tile_tasks_completed = false; | 1025 all_tile_tasks_completed = false; |
| 1011 did_notify_all_tile_tasks_completed = false; | 1026 did_notify_all_tile_tasks_completed = false; |
| 1012 } | 1027 } |
| 1013 | 1028 |
| 1014 } // namespace cc | 1029 } // namespace cc |
| OLD | NEW |