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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 base::saturated_cast<int>(stats.canceled_count)); | 341 base::saturated_cast<int>(stats.canceled_count)); |
| 342 return std::move(state); | 342 return std::move(state); |
| 343 } | 343 } |
| 344 | 344 |
| 345 TileManager::TileManager(TileManagerClient* client, | 345 TileManager::TileManager(TileManagerClient* client, |
| 346 base::SequencedTaskRunner* task_runner, | 346 base::SequencedTaskRunner* task_runner, |
| 347 size_t scheduled_raster_task_limit, | 347 size_t scheduled_raster_task_limit, |
| 348 bool use_partial_raster) | 348 bool use_partial_raster) |
| 349 : client_(client), | 349 : client_(client), |
| 350 task_runner_(task_runner), | 350 task_runner_(task_runner), |
| 351 resource_pool_(nullptr), | |
| 352 tile_task_manager_(nullptr), | |
| 353 scheduled_raster_task_limit_(scheduled_raster_task_limit), | 351 scheduled_raster_task_limit_(scheduled_raster_task_limit), |
| 354 use_partial_raster_(use_partial_raster), | 352 use_partial_raster_(use_partial_raster), |
| 355 use_gpu_rasterization_(false), | |
| 356 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), | |
| 357 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | |
| 358 did_oom_on_last_assign_(false), | |
| 359 more_tiles_need_prepare_check_notifier_( | 353 more_tiles_need_prepare_check_notifier_( |
| 360 task_runner_, | 354 task_runner_, |
| 361 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, | 355 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, |
| 362 base::Unretained(this))), | 356 base::Unretained(this))), |
| 363 signals_check_notifier_(task_runner_, | 357 signals_check_notifier_(task_runner_, |
| 364 base::Bind(&TileManager::CheckAndIssueSignals, | 358 base::Bind(&TileManager::CheckAndIssueSignals, |
| 365 base::Unretained(this))), | 359 base::Unretained(this))), |
| 366 has_scheduled_tile_tasks_(false), | 360 task_set_finished_weak_ptr_factory_(this), |
| 367 prepare_tiles_count_(0u), | 361 weak_ptr_factory_(this) {} |
| 368 next_tile_id_(0u), | |
| 369 task_set_finished_weak_ptr_factory_(this) {} | |
| 370 | 362 |
| 371 TileManager::~TileManager() { | 363 TileManager::~TileManager() { |
| 372 FinishTasksAndCleanUp(); | 364 FinishTasksAndCleanUp(); |
| 373 } | 365 } |
| 374 | 366 |
| 375 void TileManager::FinishTasksAndCleanUp() { | 367 void TileManager::FinishTasksAndCleanUp() { |
| 376 if (!tile_task_manager_) | 368 if (!tile_task_manager_) |
| 377 return; | 369 return; |
| 378 | 370 |
| 379 global_state_ = GlobalStateThatImpactsTilePriority(); | 371 global_state_ = GlobalStateThatImpactsTilePriority(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 390 orphan_tasks_.clear(); | 382 orphan_tasks_.clear(); |
| 391 | 383 |
| 392 FreeResourcesForReleasedTiles(); | 384 FreeResourcesForReleasedTiles(); |
| 393 CleanUpReleasedTiles(); | 385 CleanUpReleasedTiles(); |
| 394 | 386 |
| 395 tile_task_manager_ = nullptr; | 387 tile_task_manager_ = nullptr; |
| 396 resource_pool_ = nullptr; | 388 resource_pool_ = nullptr; |
| 397 more_tiles_need_prepare_check_notifier_.Cancel(); | 389 more_tiles_need_prepare_check_notifier_.Cancel(); |
| 398 signals_check_notifier_.Cancel(); | 390 signals_check_notifier_.Cancel(); |
| 399 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 391 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 392 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 400 | 393 |
| 401 image_manager_.SetImageDecodeController(nullptr); | 394 image_manager_.SetImageDecodeController(nullptr); |
| 402 locked_image_tasks_.clear(); | 395 locked_image_tasks_.clear(); |
| 403 } | 396 } |
| 404 | 397 |
| 405 void TileManager::SetResources(ResourcePool* resource_pool, | 398 void TileManager::SetResources(ResourcePool* resource_pool, |
| 406 ImageDecodeController* image_decode_controller, | 399 ImageDecodeController* image_decode_controller, |
| 407 TaskGraphRunner* task_graph_runner, | 400 TaskGraphRunner* task_graph_runner, |
| 408 RasterBufferProvider* raster_buffer_provider, | 401 RasterBufferProvider* raster_buffer_provider, |
| 409 size_t scheduled_raster_task_limit, | 402 size_t scheduled_raster_task_limit, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 delete tile; | 436 delete tile; |
| 444 } | 437 } |
| 445 released_tiles_.swap(tiles_to_retain); | 438 released_tiles_.swap(tiles_to_retain); |
| 446 } | 439 } |
| 447 | 440 |
| 448 void TileManager::DidFinishRunningTileTasksRequiredForActivation() { | 441 void TileManager::DidFinishRunningTileTasksRequiredForActivation() { |
| 449 TRACE_EVENT0("cc", | 442 TRACE_EVENT0("cc", |
| 450 "TileManager::DidFinishRunningTileTasksRequiredForActivation"); | 443 "TileManager::DidFinishRunningTileTasksRequiredForActivation"); |
| 451 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 444 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", |
| 452 ScheduledTasksStateAsValue()); | 445 ScheduledTasksStateAsValue()); |
| 446 | |
| 447 // In SMOOTHNESS_TAKES_PRIORITY, we want to wait on all required for | |
| 448 // activation | |
|
vmpstr
2016/12/07 21:00:25
nit: reformat plz
| |
| 449 // resources being ready to draw (from the RasterBufferProvider's perspective) | |
| 450 // before activating. Depending on the RasterBufferProvider, this may involve | |
| 451 // waiting on a GL sync token for GPU work to complete. | |
| 452 if (global_state_.tree_priority == SMOOTHNESS_TAKES_PRIORITY) { | |
| 453 // Build a list of all resources required for activation. | |
| 454 ResourceProvider::ResourceIdArray array; | |
|
vmpstr
2016/12/07 21:00:25
nit: resource_ids
| |
| 455 auto raster_priority_queue(client_->BuildRasterQueue( | |
|
vmpstr
2016/12/07 21:00:25
nit: I kinda prefer = instead of ()
| |
| 456 global_state_.tree_priority, | |
| 457 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); | |
| 458 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | |
| 459 const TileDrawInfo& draw_info = | |
| 460 raster_priority_queue->Top().tile()->draw_info(); | |
| 461 if (!draw_info.has_resource()) { | |
|
vmpstr
2016/12/07 21:00:25
Can you verify that OOM case is still handled. I t
| |
| 462 // If we encounter any required for activation tile with a missing | |
| 463 // resource, more raster tasks need to be scheduled to activate, so | |
| 464 // there's no reason to wait on a callback yet. | |
| 465 return; | |
| 466 } | |
| 467 array.push_back(draw_info.resource_id()); | |
| 468 } | |
| 469 | |
| 470 // Enqueue a callback which will be triggered when all resources in |array| | |
| 471 // are ready for draw. | |
| 472 pending_activation_callback_id_ = | |
| 473 raster_buffer_provider_->SetReadyToDrawCallback( | |
| 474 array, | |
| 475 base::Bind(&TileManager::RequiredForActivationTilesAreReadyToDraw, | |
| 476 weak_ptr_factory_.GetWeakPtr()), | |
| 477 pending_activation_callback_id_); | |
| 478 | |
| 479 if (pending_activation_callback_id_ != 0) { | |
| 480 // We need to wait on the callback, don't schedule any notifications. | |
| 481 return; | |
| 482 } | |
| 483 } | |
| 484 | |
| 453 // TODO(vmpstr): Temporary check to debug crbug.com/642927. | 485 // TODO(vmpstr): Temporary check to debug crbug.com/642927. |
| 454 CHECK(tile_task_manager_); | 486 CHECK(tile_task_manager_); |
| 455 signals_.ready_to_activate = true; | 487 signals_.ready_to_activate = true; |
| 456 signals_check_notifier_.Schedule(); | 488 signals_check_notifier_.Schedule(); |
| 457 } | 489 } |
| 458 | 490 |
| 459 void TileManager::DidFinishRunningTileTasksRequiredForDraw() { | 491 void TileManager::DidFinishRunningTileTasksRequiredForDraw() { |
| 460 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTileTasksRequiredForDraw"); | 492 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTileTasksRequiredForDraw"); |
| 461 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 493 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", |
| 462 ScheduledTasksStateAsValue()); | 494 ScheduledTasksStateAsValue()); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 841 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
| 810 } | 842 } |
| 811 | 843 |
| 812 // Cancel existing OnTaskSetFinished callbacks. | 844 // Cancel existing OnTaskSetFinished callbacks. |
| 813 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 845 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 814 | 846 |
| 815 // Even when scheduling an empty set of tiles, the TTWP does some work, and | 847 // Even when scheduling an empty set of tiles, the TTWP does some work, and |
| 816 // will always trigger a DidFinishRunningTileTasks notification. Because of | 848 // will always trigger a DidFinishRunningTileTasks notification. Because of |
| 817 // this we unconditionally set |has_scheduled_tile_tasks_| to true. | 849 // this we unconditionally set |has_scheduled_tile_tasks_| to true. |
| 818 has_scheduled_tile_tasks_ = true; | 850 has_scheduled_tile_tasks_ = true; |
| 851 // And reset |pending_activation_callback_id_|. | |
| 852 pending_activation_callback_id_ = 0; | |
| 819 | 853 |
| 820 // Track the number of dependents for each *_done task. | 854 // Track the number of dependents for each *_done task. |
| 821 size_t required_for_activate_count = 0; | 855 size_t required_for_activate_count = 0; |
| 822 size_t required_for_draw_count = 0; | 856 size_t required_for_draw_count = 0; |
| 823 size_t all_count = 0; | 857 size_t all_count = 0; |
| 824 | 858 |
| 825 size_t priority = kTileTaskPriorityBase; | 859 size_t priority = kTileTaskPriorityBase; |
| 826 | 860 |
| 827 graph_.Reset(); | 861 graph_.Reset(); |
| 828 | 862 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1096 Tile* tile = all_queue->Top().tile(); | 1130 Tile* tile = all_queue->Top().tile(); |
| 1097 DCHECK(!tile->required_for_activation() || | 1131 DCHECK(!tile->required_for_activation() || |
| 1098 tile->draw_info().IsReadyToDraw()); | 1132 tile->draw_info().IsReadyToDraw()); |
| 1099 } | 1133 } |
| 1100 #endif | 1134 #endif |
| 1101 return true; | 1135 return true; |
| 1102 } | 1136 } |
| 1103 | 1137 |
| 1104 bool TileManager::IsReadyToActivate() const { | 1138 bool TileManager::IsReadyToActivate() const { |
| 1105 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); | 1139 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); |
| 1106 return AreRequiredTilesReadyToDraw( | 1140 return pending_activation_callback_id_ == 0 && |
| 1107 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); | 1141 AreRequiredTilesReadyToDraw( |
| 1142 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); | |
| 1108 } | 1143 } |
| 1109 | 1144 |
| 1110 bool TileManager::IsReadyToDraw() const { | 1145 bool TileManager::IsReadyToDraw() const { |
| 1111 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); | 1146 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); |
| 1112 return AreRequiredTilesReadyToDraw( | 1147 return AreRequiredTilesReadyToDraw( |
| 1113 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); | 1148 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); |
| 1114 } | 1149 } |
| 1115 | 1150 |
| 1116 void TileManager::CheckAndIssueSignals() { | 1151 void TileManager::CheckAndIssueSignals() { |
| 1117 TRACE_EVENT0("cc", "TileManager::CheckAndIssueSignals"); | 1152 TRACE_EVENT0("cc", "TileManager::CheckAndIssueSignals"); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 signals_.all_tile_tasks_completed); | 1299 signals_.all_tile_tasks_completed); |
| 1265 state->EndDictionary(); | 1300 state->EndDictionary(); |
| 1266 return std::move(state); | 1301 return std::move(state); |
| 1267 } | 1302 } |
| 1268 | 1303 |
| 1269 bool TileManager::UsePartialRaster() const { | 1304 bool TileManager::UsePartialRaster() const { |
| 1270 return use_partial_raster_ && | 1305 return use_partial_raster_ && |
| 1271 raster_buffer_provider_->CanPartialRasterIntoProvidedResource(); | 1306 raster_buffer_provider_->CanPartialRasterIntoProvidedResource(); |
| 1272 } | 1307 } |
| 1273 | 1308 |
| 1309 void TileManager::RequiredForActivationTilesAreReadyToDraw( | |
| 1310 uint64_t callback_id) { | |
| 1311 if (pending_activation_callback_id_ != callback_id) { | |
| 1312 // This callback has already been superceded by a new one. Ignore it. | |
| 1313 return; | |
| 1314 } | |
| 1315 | |
| 1316 pending_activation_callback_id_ = 0; | |
| 1317 signals_.ready_to_activate = true; | |
| 1318 signals_check_notifier_.Schedule(); | |
| 1319 } | |
| 1320 | |
| 1274 // Utility function that can be used to create a "Task set finished" task that | 1321 // Utility function that can be used to create a "Task set finished" task that |
| 1275 // posts |callback| to |task_runner| when run. | 1322 // posts |callback| to |task_runner| when run. |
| 1276 scoped_refptr<TileTask> TileManager::CreateTaskSetFinishedTask( | 1323 scoped_refptr<TileTask> TileManager::CreateTaskSetFinishedTask( |
| 1277 void (TileManager::*callback)()) { | 1324 void (TileManager::*callback)()) { |
| 1278 return make_scoped_refptr(new TaskSetFinishedTaskImpl( | 1325 return make_scoped_refptr(new TaskSetFinishedTaskImpl( |
| 1279 task_runner_, | 1326 task_runner_, |
| 1280 base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr()))); | 1327 base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr()))); |
| 1281 } | 1328 } |
| 1282 | 1329 |
| 1283 TileManager::MemoryUsage::MemoryUsage() | 1330 TileManager::MemoryUsage::MemoryUsage() |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1355 all_tile_tasks_completed = false; | 1402 all_tile_tasks_completed = false; |
| 1356 did_notify_all_tile_tasks_completed = false; | 1403 did_notify_all_tile_tasks_completed = false; |
| 1357 } | 1404 } |
| 1358 | 1405 |
| 1359 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | 1406 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; |
| 1360 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | 1407 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( |
| 1361 PrioritizedWorkToSchedule&& other) = default; | 1408 PrioritizedWorkToSchedule&& other) = default; |
| 1362 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | 1409 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; |
| 1363 | 1410 |
| 1364 } // namespace cc | 1411 } // namespace cc |
| OLD | NEW |