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