| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void TileManager::FinishTasksAndCleanUp() { | 340 void TileManager::FinishTasksAndCleanUp() { |
| 341 if (!tile_task_manager_) | 341 if (!tile_task_manager_) |
| 342 return; | 342 return; |
| 343 | 343 |
| 344 global_state_ = GlobalStateThatImpactsTilePriority(); | 344 global_state_ = GlobalStateThatImpactsTilePriority(); |
| 345 | 345 |
| 346 // This cancels tasks if possible, finishes pending tasks, and release any | 346 // This cancels tasks if possible, finishes pending tasks, and release any |
| 347 // uninitialized resources. | 347 // uninitialized resources. |
| 348 tile_task_manager_->Shutdown(); | 348 tile_task_manager_->Shutdown(); |
| 349 | 349 |
| 350 raster_buffer_provider_->Shutdown(); | 350 // Now that all tasks have been finished, we can clear any |
| 351 | 351 // |orphan_tasks_|. |
| 352 // Now that all tasks have been finished, we can clear any |orphan_tasks_|. | |
| 353 orphan_tasks_.clear(); | 352 orphan_tasks_.clear(); |
| 354 | 353 |
| 355 tile_task_manager_->CheckForCompletedTasks(); | 354 tile_task_manager_->CheckForCompletedTasks(); |
| 356 | 355 |
| 357 FreeResourcesForReleasedTiles(); | 356 FreeResourcesForReleasedTiles(); |
| 358 CleanUpReleasedTiles(); | 357 CleanUpReleasedTiles(); |
| 359 | 358 |
| 360 tile_task_manager_ = nullptr; | 359 tile_task_manager_ = nullptr; |
| 361 resource_pool_ = nullptr; | 360 resource_pool_ = nullptr; |
| 362 more_tiles_need_prepare_check_notifier_.Cancel(); | 361 more_tiles_need_prepare_check_notifier_.Cancel(); |
| 363 signals_check_notifier_.Cancel(); | 362 signals_check_notifier_.Cancel(); |
| 364 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 363 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 365 | 364 |
| 366 for (auto& draw_image_pair : locked_images_) | 365 for (auto& draw_image_pair : locked_images_) |
| 367 image_decode_controller_->UnrefImage(draw_image_pair.first); | 366 image_decode_controller_->UnrefImage(draw_image_pair.first); |
| 368 locked_images_.clear(); | 367 locked_images_.clear(); |
| 369 } | 368 } |
| 370 | 369 |
| 371 void TileManager::SetResources(ResourcePool* resource_pool, | 370 void TileManager::SetResources(ResourcePool* resource_pool, |
| 372 ImageDecodeController* image_decode_controller, | 371 ImageDecodeController* image_decode_controller, |
| 373 TileTaskManager* tile_task_manager, | 372 TileTaskManager* tile_task_manager, |
| 374 RasterBufferProvider* raster_buffer_provider, | |
| 375 size_t scheduled_raster_task_limit, | 373 size_t scheduled_raster_task_limit, |
| 376 bool use_gpu_rasterization) { | 374 bool use_gpu_rasterization) { |
| 377 DCHECK(!tile_task_manager_); | 375 DCHECK(!tile_task_manager_); |
| 378 DCHECK(tile_task_manager); | 376 DCHECK(tile_task_manager); |
| 379 | 377 |
| 380 use_gpu_rasterization_ = use_gpu_rasterization; | 378 use_gpu_rasterization_ = use_gpu_rasterization; |
| 381 scheduled_raster_task_limit_ = scheduled_raster_task_limit; | 379 scheduled_raster_task_limit_ = scheduled_raster_task_limit; |
| 382 resource_pool_ = resource_pool; | 380 resource_pool_ = resource_pool; |
| 383 image_decode_controller_ = image_decode_controller; | 381 image_decode_controller_ = image_decode_controller; |
| 384 tile_task_manager_ = tile_task_manager; | 382 tile_task_manager_ = tile_task_manager; |
| 385 raster_buffer_provider_ = raster_buffer_provider; | |
| 386 } | 383 } |
| 387 | 384 |
| 388 void TileManager::Release(Tile* tile) { | 385 void TileManager::Release(Tile* tile) { |
| 389 released_tiles_.push_back(tile); | 386 released_tiles_.push_back(tile); |
| 390 } | 387 } |
| 391 | 388 |
| 392 void TileManager::FreeResourcesForReleasedTiles() { | 389 void TileManager::FreeResourcesForReleasedTiles() { |
| 393 for (auto* tile : released_tiles_) | 390 for (auto* tile : released_tiles_) |
| 394 FreeResourcesForTile(tile); | 391 FreeResourcesForTile(tile); |
| 395 } | 392 } |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); | 871 graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); |
| 875 } | 872 } |
| 876 } | 873 } |
| 877 | 874 |
| 878 for (auto& draw_image_pair : locked_images_) | 875 for (auto& draw_image_pair : locked_images_) |
| 879 image_decode_controller_->UnrefImage(draw_image_pair.first); | 876 image_decode_controller_->UnrefImage(draw_image_pair.first); |
| 880 // The old locked images have to stay around until past the ScheduleTasks call | 877 // The old locked images have to stay around until past the ScheduleTasks call |
| 881 // below, so we do a swap instead of a move. | 878 // below, so we do a swap instead of a move. |
| 882 locked_images_.swap(new_locked_images); | 879 locked_images_.swap(new_locked_images); |
| 883 | 880 |
| 884 // We must reduce the amount of unused resources before calling | |
| 885 // ScheduleTasks to prevent usage from rising above limits. | |
| 886 resource_pool_->ReduceResourceUsage(); | |
| 887 image_decode_controller_->ReduceCacheUsage(); | |
| 888 | |
| 889 // Synchronize worker with compositor. This can fail for GPU/one-copy if the | |
| 890 // GL context is lost in which case it doesn't make sense to schedule tasks. | |
| 891 if (!raster_buffer_provider_->OrderingBarrier()) { | |
| 892 // Cancel and complete tasks to cleanup resources properly. | |
| 893 for (auto& node : graph_.nodes) { | |
| 894 TileTask* task = static_cast<TileTask*>(node.task); | |
| 895 task->state().DidCancel(); | |
| 896 task->OnTaskCompleted(); | |
| 897 task->DidComplete(); | |
| 898 } | |
| 899 graph_.Reset(); | |
| 900 required_for_activate_count = 0; | |
| 901 required_for_draw_count = 0; | |
| 902 all_count = 0; | |
| 903 } | |
| 904 | |
| 905 // Insert nodes for our task completion tasks. We enqueue these using | 881 // Insert nodes for our task completion tasks. We enqueue these using |
| 906 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and | 882 // NONCONCURRENT_FOREGROUND category this is the highest prioirty category and |
| 907 // we'd like to run these tasks as soon as possible. | 883 // we'd like to run these tasks as soon as possible. |
| 908 InsertNodeForTask(&graph_, required_for_activation_done_task.get(), | 884 InsertNodeForTask(&graph_, required_for_activation_done_task.get(), |
| 909 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, | 885 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, |
| 910 kRequiredForActivationDoneTaskPriority, | 886 kRequiredForActivationDoneTaskPriority, |
| 911 required_for_activate_count); | 887 required_for_activate_count); |
| 912 InsertNodeForTask(&graph_, required_for_draw_done_task.get(), | 888 InsertNodeForTask(&graph_, required_for_draw_done_task.get(), |
| 913 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, | 889 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, |
| 914 kRequiredForDrawDoneTaskPriority, required_for_draw_count); | 890 kRequiredForDrawDoneTaskPriority, required_for_draw_count); |
| 915 InsertNodeForTask(&graph_, all_done_task.get(), | 891 InsertNodeForTask(&graph_, all_done_task.get(), |
| 916 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, | 892 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, |
| 917 kAllDoneTaskPriority, all_count); | 893 kAllDoneTaskPriority, all_count); |
| 918 | 894 |
| 895 // We must reduce the amount of unused resoruces before calling |
| 896 // ScheduleTasks to prevent usage from rising above limits. |
| 897 resource_pool_->ReduceResourceUsage(); |
| 898 image_decode_controller_->ReduceCacheUsage(); |
| 899 |
| 919 // Schedule running of |raster_queue_|. This replaces any previously | 900 // Schedule running of |raster_queue_|. This replaces any previously |
| 920 // scheduled tasks and effectively cancels all tasks not present | 901 // scheduled tasks and effectively cancels all tasks not present |
| 921 // in |raster_queue_|. | 902 // in |raster_queue_|. |
| 922 tile_task_manager_->ScheduleTasks(&graph_); | 903 tile_task_manager_->ScheduleTasks(&graph_); |
| 923 | 904 |
| 924 // It's now safe to clean up orphan tasks as raster worker pool is not | 905 // It's now safe to clean up orphan tasks as raster worker pool is not |
| 925 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has | 906 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has |
| 926 // been called. | 907 // been called. |
| 927 orphan_tasks_.clear(); | 908 orphan_tasks_.clear(); |
| 928 | 909 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 decode_tasks.push_back(task); | 967 decode_tasks.push_back(task); |
| 987 | 968 |
| 988 if (need_to_unref_when_finished) | 969 if (need_to_unref_when_finished) |
| 989 ++it; | 970 ++it; |
| 990 else | 971 else |
| 991 it = images.erase(it); | 972 it = images.erase(it); |
| 992 } | 973 } |
| 993 | 974 |
| 994 bool supports_concurrent_execution = !use_gpu_rasterization_; | 975 bool supports_concurrent_execution = !use_gpu_rasterization_; |
| 995 std::unique_ptr<RasterBuffer> raster_buffer = | 976 std::unique_ptr<RasterBuffer> raster_buffer = |
| 996 raster_buffer_provider_->AcquireBufferForRaster( | 977 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( |
| 997 resource, resource_content_id, tile->invalidated_id()); | 978 resource, resource_content_id, tile->invalidated_id()); |
| 998 return make_scoped_refptr(new RasterTaskImpl( | 979 return make_scoped_refptr(new RasterTaskImpl( |
| 999 this, tile, resource, prioritized_tile.raster_source(), playback_settings, | 980 this, tile, resource, prioritized_tile.raster_source(), playback_settings, |
| 1000 prioritized_tile.priority().resolution, prepare_tiles_count_, | 981 prioritized_tile.priority().resolution, prepare_tiles_count_, |
| 1001 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); | 982 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); |
| 1002 } | 983 } |
| 1003 | 984 |
| 1004 void TileManager::OnRasterTaskCompleted( | 985 void TileManager::OnRasterTaskCompleted( |
| 1005 std::unique_ptr<RasterBuffer> raster_buffer, | 986 std::unique_ptr<RasterBuffer> raster_buffer, |
| 1006 Tile* tile, | 987 Tile* tile, |
| 1007 Resource* resource, | 988 Resource* resource, |
| 1008 bool was_canceled) { | 989 bool was_canceled) { |
| 1009 DCHECK(tile); | 990 DCHECK(tile); |
| 1010 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 991 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| 1011 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); | 992 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( |
| 993 std::move(raster_buffer)); |
| 1012 | 994 |
| 1013 TileDrawInfo& draw_info = tile->draw_info(); | 995 TileDrawInfo& draw_info = tile->draw_info(); |
| 1014 DCHECK(tile->raster_task_.get()); | 996 DCHECK(tile->raster_task_.get()); |
| 1015 orphan_tasks_.push_back(tile->raster_task_); | 997 orphan_tasks_.push_back(tile->raster_task_); |
| 1016 tile->raster_task_ = nullptr; | 998 tile->raster_task_ = nullptr; |
| 1017 | 999 |
| 1018 // Unref all the images. | 1000 // Unref all the images. |
| 1019 auto images_it = scheduled_draw_images_.find(tile->id()); | 1001 auto images_it = scheduled_draw_images_.find(tile->id()); |
| 1020 const std::vector<DrawImage>& images = images_it->second; | 1002 const std::vector<DrawImage>& images = images_it->second; |
| 1021 for (const auto& image : images) | 1003 for (const auto& image : images) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 | 1039 |
| 1058 tiles_[tile->id()] = tile.get(); | 1040 tiles_[tile->id()] = tile.get(); |
| 1059 return tile; | 1041 return tile; |
| 1060 } | 1042 } |
| 1061 | 1043 |
| 1062 void TileManager::SetTileTaskManagerForTesting( | 1044 void TileManager::SetTileTaskManagerForTesting( |
| 1063 TileTaskManager* tile_task_manager) { | 1045 TileTaskManager* tile_task_manager) { |
| 1064 tile_task_manager_ = tile_task_manager; | 1046 tile_task_manager_ = tile_task_manager; |
| 1065 } | 1047 } |
| 1066 | 1048 |
| 1067 void TileManager::SetRasterBufferProviderForTesting( | |
| 1068 RasterBufferProvider* raster_buffer_provider) { | |
| 1069 raster_buffer_provider_ = raster_buffer_provider; | |
| 1070 } | |
| 1071 | |
| 1072 bool TileManager::AreRequiredTilesReadyToDraw( | 1049 bool TileManager::AreRequiredTilesReadyToDraw( |
| 1073 RasterTilePriorityQueue::Type type) const { | 1050 RasterTilePriorityQueue::Type type) const { |
| 1074 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( | 1051 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 1075 client_->BuildRasterQueue(global_state_.tree_priority, type)); | 1052 client_->BuildRasterQueue(global_state_.tree_priority, type)); |
| 1076 // It is insufficient to check whether the raster queue we constructed is | 1053 // It is insufficient to check whether the raster queue we constructed is |
| 1077 // empty. The reason for this is that there are situations (rasterize on | 1054 // empty. The reason for this is that there are situations (rasterize on |
| 1078 // demand) when the tile both needs raster and it's ready to draw. Hence, we | 1055 // demand) when the tile both needs raster and it's ready to draw. Hence, we |
| 1079 // have to iterate the queue to check whether the required tiles are ready to | 1056 // have to iterate the queue to check whether the required tiles are ready to |
| 1080 // draw. | 1057 // draw. |
| 1081 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | 1058 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 Tile* tile = queue->Top().tile(); | 1208 Tile* tile = queue->Top().tile(); |
| 1232 if (tile->draw_info().IsReadyToDraw()) | 1209 if (tile->draw_info().IsReadyToDraw()) |
| 1233 continue; | 1210 continue; |
| 1234 tile->draw_info().set_oom(); | 1211 tile->draw_info().set_oom(); |
| 1235 client_->NotifyTileStateChanged(tile); | 1212 client_->NotifyTileStateChanged(tile); |
| 1236 } | 1213 } |
| 1237 return true; | 1214 return true; |
| 1238 } | 1215 } |
| 1239 | 1216 |
| 1240 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { | 1217 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { |
| 1241 return raster_buffer_provider_->GetResourceFormat(!tile->is_opaque()); | 1218 return tile_task_manager_->GetRasterBufferProvider()->GetResourceFormat( |
| 1219 !tile->is_opaque()); |
| 1242 } | 1220 } |
| 1243 | 1221 |
| 1244 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const { | 1222 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const { |
| 1245 return raster_buffer_provider_->GetResourceRequiresSwizzle( | 1223 return tile_task_manager_->GetRasterBufferProvider() |
| 1246 !tile->is_opaque()); | 1224 ->GetResourceRequiresSwizzle(!tile->is_opaque()); |
| 1247 } | 1225 } |
| 1248 | 1226 |
| 1249 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 1227 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 1250 TileManager::ScheduledTasksStateAsValue() const { | 1228 TileManager::ScheduledTasksStateAsValue() const { |
| 1251 std::unique_ptr<base::trace_event::TracedValue> state( | 1229 std::unique_ptr<base::trace_event::TracedValue> state( |
| 1252 new base::trace_event::TracedValue()); | 1230 new base::trace_event::TracedValue()); |
| 1253 state->BeginDictionary("tasks_pending"); | 1231 state->BeginDictionary("tasks_pending"); |
| 1254 state->SetBoolean("ready_to_activate", signals_.ready_to_activate); | 1232 state->SetBoolean("ready_to_activate", signals_.ready_to_activate); |
| 1255 state->SetBoolean("ready_to_draw", signals_.ready_to_draw); | 1233 state->SetBoolean("ready_to_draw", signals_.ready_to_draw); |
| 1256 state->SetBoolean("all_tile_tasks_completed", | 1234 state->SetBoolean("all_tile_tasks_completed", |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 all_tile_tasks_completed = false; | 1321 all_tile_tasks_completed = false; |
| 1344 did_notify_all_tile_tasks_completed = false; | 1322 did_notify_all_tile_tasks_completed = false; |
| 1345 } | 1323 } |
| 1346 | 1324 |
| 1347 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | 1325 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; |
| 1348 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | 1326 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( |
| 1349 PrioritizedWorkToSchedule&& other) = default; | 1327 PrioritizedWorkToSchedule&& other) = default; |
| 1350 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | 1328 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; |
| 1351 | 1329 |
| 1352 } // namespace cc | 1330 } // namespace cc |
| OLD | NEW |