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