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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 | 418 |
| 419 use_gpu_rasterization_ = use_gpu_rasterization; | 419 use_gpu_rasterization_ = use_gpu_rasterization; |
| 420 scheduled_raster_task_limit_ = scheduled_raster_task_limit; | 420 scheduled_raster_task_limit_ = scheduled_raster_task_limit; |
| 421 resource_pool_ = resource_pool; | 421 resource_pool_ = resource_pool; |
| 422 image_controller_.SetImageDecodeCache(image_decode_cache); | 422 image_controller_.SetImageDecodeCache(image_decode_cache); |
| 423 tile_task_manager_ = TileTaskManagerImpl::Create(task_graph_runner); | 423 tile_task_manager_ = TileTaskManagerImpl::Create(task_graph_runner); |
| 424 raster_buffer_provider_ = raster_buffer_provider; | 424 raster_buffer_provider_ = raster_buffer_provider; |
| 425 } | 425 } |
| 426 | 426 |
| 427 void TileManager::Release(Tile* tile) { | 427 void TileManager::Release(Tile* tile) { |
| 428 if (tile->raster_task_scheduled_with_checker_images()) | |
| 429 num_of_tiles_with_checker_images_--; | |
| 430 DCHECK_GE(num_of_tiles_with_checker_images_, 0); | |
| 431 | |
| 428 FreeResourcesForTile(tile); | 432 FreeResourcesForTile(tile); |
| 429 tiles_.erase(tile->id()); | 433 tiles_.erase(tile->id()); |
| 430 } | 434 } |
| 431 | 435 |
| 432 void TileManager::DidFinishRunningTileTasksRequiredForActivation() { | 436 void TileManager::DidFinishRunningTileTasksRequiredForActivation() { |
| 433 TRACE_EVENT0("cc", | 437 TRACE_EVENT0("cc", |
| 434 "TileManager::DidFinishRunningTileTasksRequiredForActivation"); | 438 "TileManager::DidFinishRunningTileTasksRequiredForActivation"); |
| 435 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 439 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", |
| 436 ScheduledTasksStateAsValue()); | 440 ScheduledTasksStateAsValue()); |
| 437 // TODO(vmpstr): Temporary check to debug crbug.com/642927. | 441 // TODO(vmpstr): Temporary check to debug crbug.com/642927. |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 } | 683 } |
| 680 } | 684 } |
| 681 | 685 |
| 682 // Prepaint tiles that are far away are only processed for images. | 686 // Prepaint tiles that are far away are only processed for images. |
| 683 if (!tile->required_for_activation() && !tile->required_for_draw() && | 687 if (!tile->required_for_activation() && !tile->required_for_draw() && |
| 684 prioritized_tile.is_process_for_images_only()) { | 688 prioritized_tile.is_process_for_images_only()) { |
| 685 work_to_schedule.tiles_to_process_for_images.push_back(prioritized_tile); | 689 work_to_schedule.tiles_to_process_for_images.push_back(prioritized_tile); |
| 686 continue; | 690 continue; |
| 687 } | 691 } |
| 688 | 692 |
| 693 // Tiles in the raster queue should either require raster or decode for | |
| 694 // checker-images. If this tile does not need raster, process it only to | |
| 695 // build the decode queue for checkered images. | |
| 696 // Note that performing this check after the solid color analysis is not | |
| 697 // necessary for correctness. | |
| 698 if (!tile->draw_info().NeedsRaster()) { | |
| 699 DCHECK(tile->draw_info().is_checker_imaged()); | |
| 700 DCHECK(prioritized_tile.should_decode_checkered_images_for_tile()); | |
| 701 | |
| 702 AddCheckeredImagesToDecodeQueue( | |
| 703 prioritized_tile, raster_color_space, | |
| 704 &work_to_schedule.checker_image_decode_queue); | |
| 705 continue; | |
| 706 } | |
| 707 | |
| 689 // We won't be able to schedule this tile, so break out early. | 708 // We won't be able to schedule this tile, so break out early. |
| 690 if (work_to_schedule.tiles_to_raster.size() >= | 709 if (work_to_schedule.tiles_to_raster.size() >= |
| 691 scheduled_raster_task_limit_) { | 710 scheduled_raster_task_limit_) { |
| 692 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 711 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 693 break; | 712 break; |
| 694 } | 713 } |
| 695 | 714 |
| 696 tile->scheduled_priority_ = schedule_priority++; | 715 tile->scheduled_priority_ = schedule_priority++; |
| 697 | 716 |
| 698 DCHECK(tile->draw_info().mode() == TileDrawInfo::OOM_MODE || | 717 DCHECK(tile->draw_info().mode() == TileDrawInfo::OOM_MODE || |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 724 | 743 |
| 725 // If we couldn't fit the tile into our current memory limit, then we're | 744 // If we couldn't fit the tile into our current memory limit, then we're |
| 726 // done. | 745 // done. |
| 727 if (!memory_usage_is_within_limit) { | 746 if (!memory_usage_is_within_limit) { |
| 728 if (tile_is_needed_now) | 747 if (tile_is_needed_now) |
| 729 had_enough_memory_to_schedule_tiles_needed_now = false; | 748 had_enough_memory_to_schedule_tiles_needed_now = false; |
| 730 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 749 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 731 break; | 750 break; |
| 732 } | 751 } |
| 733 | 752 |
| 734 // If we were able to assign memory to this tile, create a raster task if | 753 // If the tile has a scheduled task that will rasterize a resource with |
| 735 // necessary. | 754 // checker-imaged content, add those images to the decode queue. Note that |
| 736 if (!tile->raster_task_) { | 755 // we add all images as we process the raster priority queue to ensure that |
| 756 // images are added to the decode queue in raster priority order. | |
| 757 if (tile->HasRasterTask()) { | |
| 758 if (tile->raster_task_scheduled_with_checker_images() && | |
| 759 prioritized_tile.should_decode_checkered_images_for_tile()) { | |
| 760 AddCheckeredImagesToDecodeQueue( | |
| 761 prioritized_tile, raster_color_space, | |
| 762 &work_to_schedule.checker_image_decode_queue); | |
| 763 } | |
| 764 } else { | |
| 765 // Creating the raster task here will acquire resources, but | |
| 766 // this resource usage has already been accounted for above. | |
| 737 tile->raster_task_ = | 767 tile->raster_task_ = |
| 738 CreateRasterTask(prioritized_tile, raster_color_space); | 768 CreateRasterTask(prioritized_tile, client_->GetRasterColorSpace(), |
| 769 &work_to_schedule.checker_image_decode_queue); | |
| 739 } | 770 } |
| 740 | 771 |
| 741 memory_usage += memory_required_by_tile_to_be_scheduled; | 772 memory_usage += memory_required_by_tile_to_be_scheduled; |
| 742 work_to_schedule.tiles_to_raster.push_back(prioritized_tile); | 773 work_to_schedule.tiles_to_raster.push_back(prioritized_tile); |
| 743 } | 774 } |
| 744 | 775 |
| 745 // Note that we should try and further reduce memory in case the above loop | 776 // Note that we should try and further reduce memory in case the above loop |
| 746 // didn't reduce memory. This ensures that we always release as many resources | 777 // didn't reduce memory. This ensures that we always release as many resources |
| 747 // as possible to stay within the memory limit. | 778 // as possible to stay within the memory limit. |
| 748 eviction_priority_queue = FreeTileResourcesUntilUsageIsWithinLimit( | 779 eviction_priority_queue = FreeTileResourcesUntilUsageIsWithinLimit( |
| 749 std::move(eviction_priority_queue), hard_memory_limit, &memory_usage); | 780 std::move(eviction_priority_queue), hard_memory_limit, &memory_usage); |
| 750 | 781 |
| 782 // At this point, if we ran out of memory when allocating resources and we | |
| 783 // couldn't go past even the NOW bin, this means we have evicted resources | |
| 784 // from all tiles with a lower priority while we still might have resources | |
| 785 // holding checker-imaged content. The invalidations for these resources will | |
| 786 // be generated only if the skipped images are decoded. So we must schedule | |
| 787 // decodes for these tiles to update their content. | |
| 788 if (!had_enough_memory_to_schedule_tiles_needed_now && | |
| 789 num_of_tiles_with_checker_images_ > 0) { | |
| 790 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | |
| 791 const PrioritizedTile& prioritized_tile = raster_priority_queue->Top(); | |
| 792 | |
| 793 if (prioritized_tile.priority().priority_bin > TilePriority::NOW) | |
| 794 break; | |
| 795 | |
| 796 if (!prioritized_tile.should_decode_checkered_images_for_tile()) | |
| 797 continue; | |
| 798 | |
| 799 Tile* tile = prioritized_tile.tile(); | |
| 800 if (tile->draw_info().is_checker_imaged() || | |
|
vmpstr
2017/04/20 20:59:33
Is this going to be false for tiles that don't hav
Khushal
2017/04/20 21:54:22
Yup.
| |
| 801 tile->raster_task_scheduled_with_checker_images()) { | |
| 802 AddCheckeredImagesToDecodeQueue( | |
| 803 prioritized_tile, raster_color_space, | |
| 804 &work_to_schedule.checker_image_decode_queue); | |
| 805 } | |
| 806 } | |
| 807 } | |
| 808 | |
| 751 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", | 809 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", |
| 752 !had_enough_memory_to_schedule_tiles_needed_now); | 810 !had_enough_memory_to_schedule_tiles_needed_now); |
| 753 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now; | 811 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now; |
| 754 | 812 |
| 755 memory_stats_from_last_assign_.total_budget_in_bytes = | 813 memory_stats_from_last_assign_.total_budget_in_bytes = |
| 756 global_state_.hard_memory_limit_in_bytes; | 814 global_state_.hard_memory_limit_in_bytes; |
| 757 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); | 815 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); |
| 758 DCHECK_GE(memory_stats_from_last_assign_.total_bytes_used, 0); | 816 DCHECK_GE(memory_stats_from_last_assign_.total_bytes_used, 0); |
| 759 memory_stats_from_last_assign_.had_enough_memory = | 817 memory_stats_from_last_assign_.had_enough_memory = |
| 760 had_enough_memory_to_schedule_tiles_needed_now; | 818 had_enough_memory_to_schedule_tiles_needed_now; |
| 761 | 819 |
| 762 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", | 820 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", |
| 763 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 821 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
| 764 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 822 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
| 765 "had_enough_memory_to_schedule_tiles_needed_now", | 823 "had_enough_memory_to_schedule_tiles_needed_now", |
| 766 had_enough_memory_to_schedule_tiles_needed_now); | 824 had_enough_memory_to_schedule_tiles_needed_now); |
| 767 return work_to_schedule; | 825 return work_to_schedule; |
| 768 } | 826 } |
| 769 | 827 |
| 770 void TileManager::FreeResourcesForTile(Tile* tile) { | 828 void TileManager::FreeResourcesForTile(Tile* tile) { |
| 771 TileDrawInfo& draw_info = tile->draw_info(); | 829 TileDrawInfo& draw_info = tile->draw_info(); |
| 830 | |
| 831 if (draw_info.is_checker_imaged()) | |
| 832 num_of_tiles_with_checker_images_--; | |
| 833 DCHECK_GE(num_of_tiles_with_checker_images_, 0); | |
| 834 | |
| 772 Resource* resource = draw_info.TakeResource(); | 835 Resource* resource = draw_info.TakeResource(); |
| 773 if (resource) { | 836 if (resource) { |
| 774 resource_pool_->ReleaseResource(resource); | 837 resource_pool_->ReleaseResource(resource); |
| 775 pending_gpu_work_tiles_.erase(tile); | 838 pending_gpu_work_tiles_.erase(tile); |
| 776 } | 839 } |
| 777 } | 840 } |
| 778 | 841 |
| 779 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( | 842 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( |
| 780 Tile* tile) { | 843 Tile* tile) { |
| 781 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); | 844 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); |
| 782 FreeResourcesForTile(tile); | 845 FreeResourcesForTile(tile); |
| 783 if (was_ready_to_draw) | 846 if (was_ready_to_draw) |
| 784 client_->NotifyTileStateChanged(tile); | 847 client_->NotifyTileStateChanged(tile); |
| 785 } | 848 } |
| 786 | 849 |
| 850 void TileManager::PartitionImagesForCheckering( | |
| 851 const PrioritizedTile& prioritized_tile, | |
| 852 const gfx::ColorSpace& raster_color_space, | |
| 853 std::vector<DrawImage>* sync_decoded_images, | |
| 854 std::vector<sk_sp<const SkImage>>* checkered_images) { | |
| 855 Tile* tile = prioritized_tile.tile(); | |
| 856 std::vector<DrawImage> images_in_tile; | |
| 857 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | |
| 858 tile->enclosing_layer_rect(), tile->raster_transform().scale(), | |
| 859 raster_color_space, &images_in_tile); | |
| 860 WhichTree tree = tile->tiling()->tree(); | |
| 861 | |
| 862 for (auto& draw_image : images_in_tile) { | |
| 863 if (checker_image_tracker_.ShouldCheckerImage(draw_image.image(), tree)) | |
| 864 checkered_images->push_back(draw_image.image()); | |
| 865 else | |
| 866 sync_decoded_images->push_back(draw_image); | |
| 867 } | |
| 868 } | |
| 869 | |
| 870 void TileManager::AddCheckeredImagesToDecodeQueue( | |
|
vmpstr
2017/04/20 20:59:32
nit: I guess I was just hoping to reuse the functi
Khushal
2017/04/20 21:54:22
Its a few more lines of code extra at call-sites f
| |
| 871 const PrioritizedTile& prioritized_tile, | |
| 872 const gfx::ColorSpace& raster_color_space, | |
| 873 CheckerImageTracker::ImageDecodeQueue* image_decode_queue) { | |
| 874 Tile* tile = prioritized_tile.tile(); | |
| 875 std::vector<DrawImage> images_in_tile; | |
| 876 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | |
| 877 tile->enclosing_layer_rect(), tile->raster_transform().scale(), | |
| 878 raster_color_space, &images_in_tile); | |
| 879 WhichTree tree = tile->tiling()->tree(); | |
| 880 | |
| 881 for (auto& draw_image : images_in_tile) { | |
| 882 if (checker_image_tracker_.ShouldCheckerImage(draw_image.image(), tree)) | |
| 883 image_decode_queue->push_back(draw_image.image()); | |
| 884 } | |
| 885 } | |
| 886 | |
| 787 void TileManager::ScheduleTasks( | 887 void TileManager::ScheduleTasks( |
| 788 const PrioritizedWorkToSchedule& work_to_schedule) { | 888 const PrioritizedWorkToSchedule& work_to_schedule) { |
| 789 const std::vector<PrioritizedTile>& tiles_that_need_to_be_rasterized = | 889 const std::vector<PrioritizedTile>& tiles_that_need_to_be_rasterized = |
| 790 work_to_schedule.tiles_to_raster; | 890 work_to_schedule.tiles_to_raster; |
| 791 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", "count", | 891 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", "count", |
| 792 tiles_that_need_to_be_rasterized.size()); | 892 tiles_that_need_to_be_rasterized.size()); |
| 793 | 893 |
| 794 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); | 894 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); |
| 795 | 895 |
| 796 if (!has_scheduled_tile_tasks_) { | 896 if (!has_scheduled_tile_tasks_) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 } | 978 } |
| 879 | 979 |
| 880 // TODO(vmpstr): SOON is misleading here, but these images can come from | 980 // TODO(vmpstr): SOON is misleading here, but these images can come from |
| 881 // several diffent tiles. Rethink what we actually want to trace here. Note | 981 // several diffent tiles. Rethink what we actually want to trace here. Note |
| 882 // that I'm using SOON, since it can't be NOW (these are prepaint). | 982 // that I'm using SOON, since it can't be NOW (these are prepaint). |
| 883 ImageDecodeCache::TracingInfo tracing_info(prepare_tiles_count_, | 983 ImageDecodeCache::TracingInfo tracing_info(prepare_tiles_count_, |
| 884 TilePriority::SOON); | 984 TilePriority::SOON); |
| 885 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks = | 985 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks = |
| 886 image_controller_.SetPredecodeImages(std::move(new_locked_images), | 986 image_controller_.SetPredecodeImages(std::move(new_locked_images), |
| 887 tracing_info); | 987 tracing_info); |
| 888 | |
| 889 for (auto& task : new_locked_image_tasks) { | 988 for (auto& task : new_locked_image_tasks) { |
| 890 auto decode_it = std::find_if(graph_.nodes.begin(), graph_.nodes.end(), | 989 auto decode_it = std::find_if(graph_.nodes.begin(), graph_.nodes.end(), |
| 891 [&task](const TaskGraph::Node& node) { | 990 [&task](const TaskGraph::Node& node) { |
| 892 return node.task == task.get(); | 991 return node.task == task.get(); |
| 893 }); | 992 }); |
| 894 // If this task is already in the graph, then we don't have to insert it. | 993 // If this task is already in the graph, then we don't have to insert it. |
| 895 if (decode_it != graph_.nodes.end()) | 994 if (decode_it != graph_.nodes.end()) |
| 896 continue; | 995 continue; |
| 897 | 996 |
| 898 InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); | 997 InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 927 kAllDoneTaskPriority, all_count); | 1026 kAllDoneTaskPriority, all_count); |
| 928 | 1027 |
| 929 // Synchronize worker with compositor. | 1028 // Synchronize worker with compositor. |
| 930 raster_buffer_provider_->OrderingBarrier(); | 1029 raster_buffer_provider_->OrderingBarrier(); |
| 931 | 1030 |
| 932 // Schedule running of |raster_queue_|. This replaces any previously | 1031 // Schedule running of |raster_queue_|. This replaces any previously |
| 933 // scheduled tasks and effectively cancels all tasks not present | 1032 // scheduled tasks and effectively cancels all tasks not present |
| 934 // in |raster_queue_|. | 1033 // in |raster_queue_|. |
| 935 tile_task_manager_->ScheduleTasks(&graph_); | 1034 tile_task_manager_->ScheduleTasks(&graph_); |
| 936 | 1035 |
| 1036 // Schedule running of the checker-image decode queue. This replaces the | |
| 1037 // previously scheduled queue and effectively cancels image decodes from the | |
| 1038 // previous queue, if not already started. | |
| 1039 checker_image_tracker_.ScheduleImageDecodeQueue( | |
| 1040 std::move(work_to_schedule.checker_image_decode_queue)); | |
| 1041 | |
| 937 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; | 1042 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; |
| 938 | 1043 |
| 939 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 1044 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", |
| 940 ScheduledTasksStateAsValue()); | 1045 ScheduledTasksStateAsValue()); |
| 941 } | 1046 } |
| 942 | 1047 |
| 943 scoped_refptr<TileTask> TileManager::CreateRasterTask( | 1048 scoped_refptr<TileTask> TileManager::CreateRasterTask( |
| 944 const PrioritizedTile& prioritized_tile, | 1049 const PrioritizedTile& prioritized_tile, |
| 945 const gfx::ColorSpace& color_space) { | 1050 const gfx::ColorSpace& color_space, |
| 1051 CheckerImageTracker::ImageDecodeQueue* checker_image_decode_queue) { | |
| 946 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1052 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 947 "TileManager::CreateRasterTask"); | 1053 "TileManager::CreateRasterTask"); |
| 948 | |
| 949 Tile* tile = prioritized_tile.tile(); | 1054 Tile* tile = prioritized_tile.tile(); |
| 1055 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1056 "TileManager::CreateRasterTask", "Tile", tile->id()); | |
| 950 | 1057 |
| 951 // Get the resource. | 1058 // Get the resource. |
| 952 uint64_t resource_content_id = 0; | 1059 uint64_t resource_content_id = 0; |
| 953 Resource* resource = nullptr; | 1060 Resource* resource = nullptr; |
| 954 gfx::Rect invalidated_rect = tile->invalidated_content_rect(); | 1061 gfx::Rect invalidated_rect = tile->invalidated_content_rect(); |
| 955 if (UsePartialRaster() && tile->invalidated_id()) { | 1062 if (UsePartialRaster() && tile->invalidated_id()) { |
| 956 resource = resource_pool_->TryAcquireResourceForPartialRaster( | 1063 resource = resource_pool_->TryAcquireResourceForPartialRaster( |
| 957 tile->id(), tile->invalidated_content_rect(), tile->invalidated_id(), | 1064 tile->id(), tile->invalidated_content_rect(), tile->invalidated_id(), |
| 958 &invalidated_rect); | 1065 &invalidated_rect); |
| 959 } | 1066 } |
| 960 | 1067 |
| 961 if (resource) { | 1068 if (resource) { |
| 962 resource_content_id = tile->invalidated_id(); | 1069 resource_content_id = tile->invalidated_id(); |
| 963 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); | 1070 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); |
| 964 } else { | 1071 } else { |
| 965 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), | 1072 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), |
| 966 DetermineResourceFormat(tile), | 1073 DetermineResourceFormat(tile), |
| 967 color_space); | 1074 color_space); |
| 968 } | 1075 } |
| 969 | 1076 |
| 970 // For LOW_RESOLUTION tiles, we don't draw or predecode images. | 1077 // For LOW_RESOLUTION tiles, we don't draw or predecode images. |
| 971 RasterSource::PlaybackSettings playback_settings; | 1078 RasterSource::PlaybackSettings playback_settings; |
| 972 playback_settings.skip_images = | 1079 playback_settings.skip_images = |
| 973 prioritized_tile.priority().resolution == LOW_RESOLUTION; | 1080 prioritized_tile.priority().resolution == LOW_RESOLUTION; |
| 974 | 1081 |
| 975 // Create and queue all image decode tasks that this tile depends on. | 1082 // Create and queue all image decode tasks that this tile depends on. Note |
| 1083 // that we need to store the images for decode tasks in | |
| 1084 // |scheduled_draw_images_| since the tile might have been destroyed by the | |
| 1085 // time the raster task finishes. | |
| 976 TileTask::Vector decode_tasks; | 1086 TileTask::Vector decode_tasks; |
| 977 std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()]; | 1087 std::vector<DrawImage>& sync_decoded_images = |
| 978 ImageIdFlatSet images_to_skip; | 1088 scheduled_draw_images_[tile->id()]; |
| 979 images.clear(); | 1089 sync_decoded_images.clear(); |
| 980 if (!playback_settings.skip_images) { | 1090 if (!playback_settings.skip_images) { |
| 981 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | 1091 std::vector<sk_sp<const SkImage>> checkered_images; |
| 982 tile->enclosing_layer_rect(), tile->raster_transform().scale(), | 1092 PartitionImagesForCheckering(prioritized_tile, color_space, |
| 983 color_space, &images); | 1093 &sync_decoded_images, &checkered_images); |
| 984 checker_image_tracker_.FilterImagesForCheckeringForTile( | 1094 for (const auto& image : checkered_images) { |
| 985 &images, &images_to_skip, prioritized_tile.tile()->tiling()->tree()); | 1095 ImageId image_id = image->uniqueID(); |
| 1096 playback_settings.images_to_skip.insert(image_id); | |
| 1097 | |
| 1098 // This can be the case for tiles on the active tree that will be replaced | |
| 1099 // or are occluded on the pending tree. While we still need to continue | |
| 1100 // skipping images for these tiles, we don't need to decode them since | |
| 1101 // they will not be required on the next active tree. | |
| 1102 if (prioritized_tile.should_decode_checkered_images_for_tile()) | |
| 1103 checker_image_decode_queue->push_back(image); | |
| 1104 } | |
| 986 } | 1105 } |
| 987 | 1106 |
| 988 // We can skip the image hijack canvas if we have no images, or no images to | 1107 // We can skip the image hijack canvas if we have no images, or no images to |
| 989 // skip during raster. | 1108 // skip during raster. |
| 990 playback_settings.use_image_hijack_canvas = | 1109 playback_settings.use_image_hijack_canvas = |
| 991 !images.empty() || !images_to_skip.empty(); | 1110 !sync_decoded_images.empty() || !playback_settings.images_to_skip.empty(); |
| 992 playback_settings.images_to_skip = std::move(images_to_skip); | 1111 |
| 1112 bool has_checker_images = !playback_settings.images_to_skip.empty(); | |
| 1113 tile->set_raster_task_scheduled_with_checker_images(has_checker_images); | |
| 1114 if (has_checker_images) | |
| 1115 num_of_tiles_with_checker_images_++; | |
| 993 | 1116 |
| 994 // Get the tasks for the required images. | 1117 // Get the tasks for the required images. |
| 995 ImageDecodeCache::TracingInfo tracing_info( | 1118 ImageDecodeCache::TracingInfo tracing_info( |
| 996 prepare_tiles_count_, prioritized_tile.priority().priority_bin); | 1119 prepare_tiles_count_, prioritized_tile.priority().priority_bin); |
| 997 image_controller_.GetTasksForImagesAndRef(&images, &decode_tasks, | 1120 image_controller_.GetTasksForImagesAndRef(&sync_decoded_images, &decode_tasks, |
| 998 tracing_info); | 1121 tracing_info); |
| 999 | 1122 |
| 1000 std::unique_ptr<RasterBuffer> raster_buffer = | 1123 std::unique_ptr<RasterBuffer> raster_buffer = |
| 1001 raster_buffer_provider_->AcquireBufferForRaster( | 1124 raster_buffer_provider_->AcquireBufferForRaster( |
| 1002 resource, resource_content_id, tile->invalidated_id()); | 1125 resource, resource_content_id, tile->invalidated_id()); |
| 1003 return make_scoped_refptr(new RasterTaskImpl( | 1126 return make_scoped_refptr(new RasterTaskImpl( |
| 1004 this, tile, resource, prioritized_tile.raster_source(), playback_settings, | 1127 this, tile, resource, prioritized_tile.raster_source(), playback_settings, |
| 1005 prioritized_tile.priority().resolution, invalidated_rect, | 1128 prioritized_tile.priority().resolution, invalidated_rect, |
| 1006 prepare_tiles_count_, std::move(raster_buffer), &decode_tasks, | 1129 prepare_tiles_count_, std::move(raster_buffer), &decode_tasks, |
| 1007 use_gpu_rasterization_)); | 1130 use_gpu_rasterization_)); |
| 1008 } | 1131 } |
| 1009 | 1132 |
| 1010 void TileManager::ResetSignalsForTesting() { | 1133 void TileManager::ResetSignalsForTesting() { |
| 1011 signals_.reset(); | 1134 signals_.reset(); |
| 1012 } | 1135 } |
| 1013 | 1136 |
| 1014 void TileManager::OnRasterTaskCompleted( | 1137 void TileManager::OnRasterTaskCompleted( |
| 1015 std::unique_ptr<RasterBuffer> raster_buffer, | 1138 std::unique_ptr<RasterBuffer> raster_buffer, |
| 1016 Tile::Id tile_id, | 1139 Tile::Id tile_id, |
| 1017 Resource* resource, | 1140 Resource* resource, |
| 1018 bool was_canceled) { | 1141 bool was_canceled) { |
| 1019 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); | 1142 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); |
| 1020 | 1143 |
| 1021 auto found = tiles_.find(tile_id); | 1144 auto found = tiles_.find(tile_id); |
| 1022 Tile* tile = nullptr; | 1145 Tile* tile = nullptr; |
| 1146 bool raster_task_was_scheduled_with_checker_images = false; | |
| 1023 if (found != tiles_.end()) { | 1147 if (found != tiles_.end()) { |
| 1024 tile = found->second; | 1148 tile = found->second; |
| 1025 DCHECK(tile->raster_task_.get()); | 1149 DCHECK(tile->raster_task_.get()); |
| 1026 tile->raster_task_ = nullptr; | 1150 tile->raster_task_ = nullptr; |
| 1151 raster_task_was_scheduled_with_checker_images = | |
| 1152 tile->set_raster_task_scheduled_with_checker_images(false); | |
| 1153 if (raster_task_was_scheduled_with_checker_images) | |
| 1154 num_of_tiles_with_checker_images_--; | |
| 1027 } | 1155 } |
| 1028 | 1156 |
| 1029 // Unref all the images. | 1157 // Unref all the images. |
| 1030 auto images_it = scheduled_draw_images_.find(tile_id); | 1158 auto images_it = scheduled_draw_images_.find(tile_id); |
| 1031 image_controller_.UnrefImages(images_it->second); | 1159 image_controller_.UnrefImages(images_it->second); |
| 1032 scheduled_draw_images_.erase(images_it); | 1160 scheduled_draw_images_.erase(images_it); |
| 1033 | 1161 |
| 1034 if (was_canceled) { | 1162 if (was_canceled) { |
| 1035 ++flush_stats_.canceled_count; | 1163 ++flush_stats_.canceled_count; |
| 1036 resource_pool_->ReleaseResource(resource); | 1164 resource_pool_->ReleaseResource(resource); |
| 1037 return; | 1165 return; |
| 1038 } | 1166 } |
| 1039 | 1167 |
| 1040 resource_pool_->OnContentReplaced(resource->id(), tile_id); | 1168 resource_pool_->OnContentReplaced(resource->id(), tile_id); |
| 1041 ++flush_stats_.completed_count; | 1169 ++flush_stats_.completed_count; |
| 1042 | 1170 |
| 1043 if (!tile) { | 1171 if (!tile) { |
| 1044 resource_pool_->ReleaseResource(resource); | 1172 resource_pool_->ReleaseResource(resource); |
| 1045 return; | 1173 return; |
| 1046 } | 1174 } |
| 1047 | 1175 |
| 1048 TileDrawInfo& draw_info = tile->draw_info(); | 1176 TileDrawInfo& draw_info = tile->draw_info(); |
| 1049 draw_info.set_resource(resource); | 1177 draw_info.set_resource(resource, |
| 1178 raster_task_was_scheduled_with_checker_images); | |
| 1050 draw_info.contents_swizzled_ = DetermineResourceRequiresSwizzle(tile); | 1179 draw_info.contents_swizzled_ = DetermineResourceRequiresSwizzle(tile); |
| 1180 if (raster_task_was_scheduled_with_checker_images) | |
| 1181 num_of_tiles_with_checker_images_++; | |
| 1051 | 1182 |
| 1052 // In SMOOTHNESS_TAKES_PRIORITY mode, we wait for GPU work to complete for a | 1183 // In SMOOTHNESS_TAKES_PRIORITY mode, we wait for GPU work to complete for a |
| 1053 // tile before setting it as ready to draw. | 1184 // tile before setting it as ready to draw. |
| 1054 if (global_state_.tree_priority == SMOOTHNESS_TAKES_PRIORITY && | 1185 if (global_state_.tree_priority == SMOOTHNESS_TAKES_PRIORITY && |
| 1055 !raster_buffer_provider_->IsResourceReadyToDraw(resource->id())) { | 1186 !raster_buffer_provider_->IsResourceReadyToDraw(resource->id())) { |
| 1056 pending_gpu_work_tiles_.insert(tile); | 1187 pending_gpu_work_tiles_.insert(tile); |
| 1057 return; | 1188 return; |
| 1058 } | 1189 } |
| 1059 | 1190 |
| 1060 draw_info.set_resource_ready_for_draw(); | 1191 draw_info.set_resource_ready_for_draw(); |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1506 all_tile_tasks_completed = false; | 1637 all_tile_tasks_completed = false; |
| 1507 did_notify_all_tile_tasks_completed = false; | 1638 did_notify_all_tile_tasks_completed = false; |
| 1508 } | 1639 } |
| 1509 | 1640 |
| 1510 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | 1641 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; |
| 1511 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | 1642 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( |
| 1512 PrioritizedWorkToSchedule&& other) = default; | 1643 PrioritizedWorkToSchedule&& other) = default; |
| 1513 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | 1644 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; |
| 1514 | 1645 |
| 1515 } // namespace cc | 1646 } // namespace cc |
| OLD | NEW |