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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 FreeResourcesForReleasedTiles(); | 355 FreeResourcesForReleasedTiles(); |
356 CleanUpReleasedTiles(); | 356 CleanUpReleasedTiles(); |
357 | 357 |
358 tile_task_manager_ = nullptr; | 358 tile_task_manager_ = nullptr; |
359 resource_pool_ = nullptr; | 359 resource_pool_ = nullptr; |
360 more_tiles_need_prepare_check_notifier_.Cancel(); | 360 more_tiles_need_prepare_check_notifier_.Cancel(); |
361 signals_check_notifier_.Cancel(); | 361 signals_check_notifier_.Cancel(); |
362 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 362 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
363 | 363 |
364 image_manager_.UnrefImages(locked_images_); | 364 image_manager_.SetImageDecodeController(nullptr); |
365 locked_images_.clear(); | |
366 locked_image_tasks_.clear(); | 365 locked_image_tasks_.clear(); |
367 } | 366 } |
368 | 367 |
369 void TileManager::SetResources(ResourcePool* resource_pool, | 368 void TileManager::SetResources(ResourcePool* resource_pool, |
370 ImageDecodeController* image_decode_controller, | 369 ImageDecodeController* image_decode_controller, |
371 TileTaskManager* tile_task_manager, | 370 TileTaskManager* tile_task_manager, |
372 RasterBufferProvider* raster_buffer_provider, | 371 RasterBufferProvider* raster_buffer_provider, |
373 size_t scheduled_raster_task_limit, | 372 size_t scheduled_raster_task_limit, |
374 bool use_gpu_rasterization) { | 373 bool use_gpu_rasterization) { |
375 DCHECK(!tile_task_manager_); | 374 DCHECK(!tile_task_manager_); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 bool use_foreground_category = | 829 bool use_foreground_category = |
831 tile->required_for_draw() || tile->required_for_activation() || | 830 tile->required_for_draw() || tile->required_for_activation() || |
832 prioritized_tile.priority().priority_bin == TilePriority::NOW; | 831 prioritized_tile.priority().priority_bin == TilePriority::NOW; |
833 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++, | 832 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++, |
834 use_foreground_category); | 833 use_foreground_category); |
835 } | 834 } |
836 | 835 |
837 const std::vector<PrioritizedTile>& tiles_to_process_for_images = | 836 const std::vector<PrioritizedTile>& tiles_to_process_for_images = |
838 work_to_schedule.tiles_to_process_for_images; | 837 work_to_schedule.tiles_to_process_for_images; |
839 std::vector<DrawImage> new_locked_images; | 838 std::vector<DrawImage> new_locked_images; |
840 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks; | |
841 for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { | 839 for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { |
842 Tile* tile = prioritized_tile.tile(); | 840 Tile* tile = prioritized_tile.tile(); |
843 | 841 |
844 std::vector<DrawImage> images; | 842 std::vector<DrawImage> images; |
845 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | 843 prioritized_tile.raster_source()->GetDiscardableImagesInRect( |
846 tile->enclosing_layer_rect(), tile->contents_scale(), &images); | 844 tile->enclosing_layer_rect(), tile->contents_scale(), &images); |
847 ImageDecodeController::TracingInfo tracing_info( | |
848 prepare_tiles_count_, prioritized_tile.priority().priority_bin); | |
849 image_manager_.GetTasksForImagesAndRef(&images, &new_locked_image_tasks, | |
850 tracing_info); | |
851 new_locked_images.insert(new_locked_images.end(), images.begin(), | 845 new_locked_images.insert(new_locked_images.end(), images.begin(), |
852 images.end()); | 846 images.end()); |
853 } | 847 } |
854 | 848 |
| 849 // TODO(vmpstr): SOON is misleading here, but these images can come from |
| 850 // several diffent tiles. Rethink what we actually want to trace here. Note |
| 851 // that I'm using SOON, since it can't be NOW (these are prepaint). |
| 852 ImageDecodeController::TracingInfo tracing_info(prepare_tiles_count_, |
| 853 TilePriority::SOON); |
| 854 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks = |
| 855 image_manager_.SetPredecodeImages(std::move(new_locked_images), |
| 856 tracing_info); |
| 857 |
855 for (auto& task : new_locked_image_tasks) { | 858 for (auto& task : new_locked_image_tasks) { |
856 auto decode_it = std::find_if(graph_.nodes.begin(), graph_.nodes.end(), | 859 auto decode_it = std::find_if(graph_.nodes.begin(), graph_.nodes.end(), |
857 [&task](const TaskGraph::Node& node) { | 860 [&task](const TaskGraph::Node& node) { |
858 return node.task == task.get(); | 861 return node.task == task.get(); |
859 }); | 862 }); |
860 // If this task is already in the graph, then we don't have to insert it. | 863 // If this task is already in the graph, then we don't have to insert it. |
861 if (decode_it != graph_.nodes.end()) | 864 if (decode_it != graph_.nodes.end()) |
862 continue; | 865 continue; |
863 | 866 |
864 InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); | 867 InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); |
865 all_count++; | 868 all_count++; |
866 graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); | 869 graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); |
867 } | 870 } |
868 | 871 |
869 image_manager_.UnrefImages(locked_images_); | 872 // The old locked images tasks have to stay around until past the |
870 // The old locked images have to stay around until past the ScheduleTasks call | 873 // ScheduleTasks call below, so we do a swap instead of a move. |
871 // below, so we do a swap instead of a move. | 874 // TODO(crbug.com/647402): Have the tile_task_manager keep a ref on the tasks, |
872 locked_images_.swap(new_locked_images); | 875 // since it makes it awkward for the callers to keep refs on tasks that only |
| 876 // exist within the task graph runner. |
873 locked_image_tasks_.swap(new_locked_image_tasks); | 877 locked_image_tasks_.swap(new_locked_image_tasks); |
874 | 878 |
875 // We must reduce the amount of unused resources before calling | 879 // We must reduce the amount of unused resources before calling |
876 // ScheduleTasks to prevent usage from rising above limits. | 880 // ScheduleTasks to prevent usage from rising above limits. |
877 resource_pool_->ReduceResourceUsage(); | 881 resource_pool_->ReduceResourceUsage(); |
878 image_manager_.ReduceMemoryUsage(); | 882 image_manager_.ReduceMemoryUsage(); |
879 | 883 |
880 // Insert nodes for our task completion tasks. We enqueue these using | 884 // Insert nodes for our task completion tasks. We enqueue these using |
881 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and | 885 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and |
882 // we'd like to run these tasks as soon as possible. | 886 // we'd like to run these tasks as soon as possible. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 985 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
982 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); | 986 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); |
983 | 987 |
984 TileDrawInfo& draw_info = tile->draw_info(); | 988 TileDrawInfo& draw_info = tile->draw_info(); |
985 DCHECK(tile->raster_task_.get()); | 989 DCHECK(tile->raster_task_.get()); |
986 orphan_tasks_.push_back(tile->raster_task_); | 990 orphan_tasks_.push_back(tile->raster_task_); |
987 tile->raster_task_ = nullptr; | 991 tile->raster_task_ = nullptr; |
988 | 992 |
989 // Unref all the images. | 993 // Unref all the images. |
990 auto images_it = scheduled_draw_images_.find(tile->id()); | 994 auto images_it = scheduled_draw_images_.find(tile->id()); |
991 const std::vector<DrawImage>& images = images_it->second; | 995 image_manager_.UnrefImages(images_it->second); |
992 image_manager_.UnrefImages(images); | |
993 scheduled_draw_images_.erase(images_it); | 996 scheduled_draw_images_.erase(images_it); |
994 | 997 |
995 if (was_canceled) { | 998 if (was_canceled) { |
996 ++flush_stats_.canceled_count; | 999 ++flush_stats_.canceled_count; |
997 resource_pool_->ReleaseResource(resource); | 1000 resource_pool_->ReleaseResource(resource); |
998 return; | 1001 return; |
999 } | 1002 } |
1000 | 1003 |
1001 resource_pool_->OnContentReplaced(resource->id(), tile->id()); | 1004 resource_pool_->OnContentReplaced(resource->id(), tile->id()); |
1002 ++flush_stats_.completed_count; | 1005 ++flush_stats_.completed_count; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 1135 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
1133 // steady memory state. Keep scheduling tasks until we reach this state. | 1136 // steady memory state. Keep scheduling tasks until we reach this state. |
1134 if (!work_to_schedule.tiles_to_raster.empty()) { | 1137 if (!work_to_schedule.tiles_to_raster.empty()) { |
1135 ScheduleTasks(work_to_schedule); | 1138 ScheduleTasks(work_to_schedule); |
1136 return; | 1139 return; |
1137 } | 1140 } |
1138 | 1141 |
1139 // If we're not in SMOOTHNESS_TAKES_PRIORITY mode, we should unlock all | 1142 // If we're not in SMOOTHNESS_TAKES_PRIORITY mode, we should unlock all |
1140 // images since we're technically going idle here at least for this frame. | 1143 // images since we're technically going idle here at least for this frame. |
1141 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) { | 1144 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) { |
1142 image_manager_.UnrefImages(locked_images_); | 1145 image_manager_.SetPredecodeImages(std::vector<DrawImage>(), |
1143 locked_images_.clear(); | 1146 ImageDecodeController::TracingInfo()); |
1144 locked_image_tasks_.clear(); | 1147 locked_image_tasks_.clear(); |
1145 } | 1148 } |
1146 | 1149 |
1147 FreeResourcesForReleasedTiles(); | 1150 FreeResourcesForReleasedTiles(); |
1148 | 1151 |
1149 resource_pool_->ReduceResourceUsage(); | 1152 resource_pool_->ReduceResourceUsage(); |
1150 image_manager_.ReduceMemoryUsage(); | 1153 image_manager_.ReduceMemoryUsage(); |
1151 | 1154 |
1152 signals_.all_tile_tasks_completed = true; | 1155 signals_.all_tile_tasks_completed = true; |
1153 signals_check_notifier_.Schedule(); | 1156 signals_check_notifier_.Schedule(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 all_tile_tasks_completed = false; | 1317 all_tile_tasks_completed = false; |
1315 did_notify_all_tile_tasks_completed = false; | 1318 did_notify_all_tile_tasks_completed = false; |
1316 } | 1319 } |
1317 | 1320 |
1318 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | 1321 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; |
1319 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | 1322 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( |
1320 PrioritizedWorkToSchedule&& other) = default; | 1323 PrioritizedWorkToSchedule&& other) = default; |
1321 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | 1324 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; |
1322 | 1325 |
1323 } // namespace cc | 1326 } // namespace cc |
OLD | NEW |