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