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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 bool use_foreground_category = | 835 bool use_foreground_category = |
837 tile->required_for_draw() || tile->required_for_activation() || | 836 tile->required_for_draw() || tile->required_for_activation() || |
838 prioritized_tile.priority().priority_bin == TilePriority::NOW; | 837 prioritized_tile.priority().priority_bin == TilePriority::NOW; |
839 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++, | 838 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++, |
840 use_foreground_category); | 839 use_foreground_category); |
841 } | 840 } |
842 | 841 |
843 const std::vector<PrioritizedTile>& tiles_to_process_for_images = | 842 const std::vector<PrioritizedTile>& tiles_to_process_for_images = |
844 work_to_schedule.tiles_to_process_for_images; | 843 work_to_schedule.tiles_to_process_for_images; |
845 std::vector<DrawImage> new_locked_images; | 844 std::vector<DrawImage> new_locked_images; |
846 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks; | |
847 for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { | 845 for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { |
848 Tile* tile = prioritized_tile.tile(); | 846 Tile* tile = prioritized_tile.tile(); |
849 | 847 |
850 std::vector<DrawImage> images; | 848 std::vector<DrawImage> images; |
851 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | 849 prioritized_tile.raster_source()->GetDiscardableImagesInRect( |
852 tile->enclosing_layer_rect(), tile->contents_scale(), &images); | 850 tile->enclosing_layer_rect(), tile->contents_scale(), &images); |
853 ImageDecodeController::TracingInfo tracing_info( | |
854 prepare_tiles_count_, prioritized_tile.priority().priority_bin); | |
855 image_manager_.GetTasksForImagesAndRef(&images, &new_locked_image_tasks, | |
856 tracing_info); | |
857 new_locked_images.insert(new_locked_images.end(), images.begin(), | 851 new_locked_images.insert(new_locked_images.end(), images.begin(), |
858 images.end()); | 852 images.end()); |
859 } | 853 } |
860 | 854 |
| 855 // TODO(vmpstr): SOON is misleading here, but these images can come from |
| 856 // several diffent tiles. Rethink what we actually want to trace here. Note |
| 857 // that I'm using SOON, since it can't be NOW (these are prepaint). |
| 858 ImageDecodeController::TracingInfo tracing_info(prepare_tiles_count_, |
| 859 TilePriority::SOON); |
| 860 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks = |
| 861 image_manager_.SetPredecodeImages(std::move(new_locked_images), |
| 862 tracing_info); |
| 863 |
861 for (auto& task : new_locked_image_tasks) { | 864 for (auto& task : new_locked_image_tasks) { |
862 auto decode_it = std::find_if(graph_.nodes.begin(), graph_.nodes.end(), | 865 auto decode_it = std::find_if(graph_.nodes.begin(), graph_.nodes.end(), |
863 [&task](const TaskGraph::Node& node) { | 866 [&task](const TaskGraph::Node& node) { |
864 return node.task == task.get(); | 867 return node.task == task.get(); |
865 }); | 868 }); |
866 // If this task is already in the graph, then we don't have to insert it. | 869 // If this task is already in the graph, then we don't have to insert it. |
867 if (decode_it != graph_.nodes.end()) | 870 if (decode_it != graph_.nodes.end()) |
868 continue; | 871 continue; |
869 | 872 |
870 InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); | 873 InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); |
871 all_count++; | 874 all_count++; |
872 graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); | 875 graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); |
873 } | 876 } |
874 | 877 |
875 image_manager_.UnrefImages(locked_images_); | 878 // The old locked images tasks have to stay around until past the |
876 // The old locked images have to stay around until past the ScheduleTasks call | 879 // ScheduleTasks call below, so we do a swap instead of a move. |
877 // below, so we do a swap instead of a move. | 880 // TODO(crbug.com/647402): Have the tile_task_manager keep a ref on the tasks, |
878 locked_images_.swap(new_locked_images); | 881 // since it makes it awkward for the callers to keep refs on tasks that only |
| 882 // exist within the task graph runner. |
879 locked_image_tasks_.swap(new_locked_image_tasks); | 883 locked_image_tasks_.swap(new_locked_image_tasks); |
880 | 884 |
881 // We must reduce the amount of unused resources before calling | 885 // We must reduce the amount of unused resources before calling |
882 // ScheduleTasks to prevent usage from rising above limits. | 886 // ScheduleTasks to prevent usage from rising above limits. |
883 resource_pool_->ReduceResourceUsage(); | 887 resource_pool_->ReduceResourceUsage(); |
884 image_manager_.ReduceMemoryUsage(); | 888 image_manager_.ReduceMemoryUsage(); |
885 | 889 |
886 // Insert nodes for our task completion tasks. We enqueue these using | 890 // Insert nodes for our task completion tasks. We enqueue these using |
887 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and | 891 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and |
888 // we'd like to run these tasks as soon as possible. | 892 // we'd like to run these tasks as soon as possible. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 991 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
988 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); | 992 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); |
989 | 993 |
990 TileDrawInfo& draw_info = tile->draw_info(); | 994 TileDrawInfo& draw_info = tile->draw_info(); |
991 DCHECK(tile->raster_task_.get()); | 995 DCHECK(tile->raster_task_.get()); |
992 orphan_tasks_.push_back(tile->raster_task_); | 996 orphan_tasks_.push_back(tile->raster_task_); |
993 tile->raster_task_ = nullptr; | 997 tile->raster_task_ = nullptr; |
994 | 998 |
995 // Unref all the images. | 999 // Unref all the images. |
996 auto images_it = scheduled_draw_images_.find(tile->id()); | 1000 auto images_it = scheduled_draw_images_.find(tile->id()); |
997 const std::vector<DrawImage>& images = images_it->second; | 1001 image_manager_.UnrefImages(images_it->second); |
998 image_manager_.UnrefImages(images); | |
999 scheduled_draw_images_.erase(images_it); | 1002 scheduled_draw_images_.erase(images_it); |
1000 | 1003 |
1001 if (was_canceled) { | 1004 if (was_canceled) { |
1002 ++flush_stats_.canceled_count; | 1005 ++flush_stats_.canceled_count; |
1003 resource_pool_->ReleaseResource(resource); | 1006 resource_pool_->ReleaseResource(resource); |
1004 return; | 1007 return; |
1005 } | 1008 } |
1006 | 1009 |
1007 resource_pool_->OnContentReplaced(resource->id(), tile->id()); | 1010 resource_pool_->OnContentReplaced(resource->id(), tile->id()); |
1008 ++flush_stats_.completed_count; | 1011 ++flush_stats_.completed_count; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 1141 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
1139 // steady memory state. Keep scheduling tasks until we reach this state. | 1142 // steady memory state. Keep scheduling tasks until we reach this state. |
1140 if (!work_to_schedule.tiles_to_raster.empty()) { | 1143 if (!work_to_schedule.tiles_to_raster.empty()) { |
1141 ScheduleTasks(work_to_schedule); | 1144 ScheduleTasks(work_to_schedule); |
1142 return; | 1145 return; |
1143 } | 1146 } |
1144 | 1147 |
1145 // If we're not in SMOOTHNESS_TAKES_PRIORITY mode, we should unlock all | 1148 // If we're not in SMOOTHNESS_TAKES_PRIORITY mode, we should unlock all |
1146 // images since we're technically going idle here at least for this frame. | 1149 // images since we're technically going idle here at least for this frame. |
1147 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) { | 1150 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) { |
1148 image_manager_.UnrefImages(locked_images_); | 1151 image_manager_.SetPredecodeImages(std::vector<DrawImage>(), |
1149 locked_images_.clear(); | 1152 ImageDecodeController::TracingInfo()); |
1150 locked_image_tasks_.clear(); | 1153 locked_image_tasks_.clear(); |
1151 } | 1154 } |
1152 | 1155 |
1153 FreeResourcesForReleasedTiles(); | 1156 FreeResourcesForReleasedTiles(); |
1154 | 1157 |
1155 resource_pool_->ReduceResourceUsage(); | 1158 resource_pool_->ReduceResourceUsage(); |
1156 image_manager_.ReduceMemoryUsage(); | 1159 image_manager_.ReduceMemoryUsage(); |
1157 | 1160 |
1158 // TODO(vmpstr): Temporary check to debug crbug.com/642927. | 1161 // TODO(vmpstr): Temporary check to debug crbug.com/642927. |
1159 CHECK(tile_task_manager_); | 1162 CHECK(tile_task_manager_); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 all_tile_tasks_completed = false; | 1327 all_tile_tasks_completed = false; |
1325 did_notify_all_tile_tasks_completed = false; | 1328 did_notify_all_tile_tasks_completed = false; |
1326 } | 1329 } |
1327 | 1330 |
1328 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | 1331 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; |
1329 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | 1332 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( |
1330 PrioritizedWorkToSchedule&& other) = default; | 1333 PrioritizedWorkToSchedule&& other) = default; |
1331 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | 1334 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; |
1332 | 1335 |
1333 } // namespace cc | 1336 } // namespace cc |
OLD | NEW |