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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 : client_(client), | 320 : client_(client), |
| 321 task_runner_(std::move(task_runner)), | 321 task_runner_(std::move(task_runner)), |
| 322 resource_pool_(nullptr), | 322 resource_pool_(nullptr), |
| 323 tile_task_manager_(nullptr), | 323 tile_task_manager_(nullptr), |
| 324 scheduled_raster_task_limit_(scheduled_raster_task_limit), | 324 scheduled_raster_task_limit_(scheduled_raster_task_limit), |
| 325 use_partial_raster_(use_partial_raster), | 325 use_partial_raster_(use_partial_raster), |
| 326 use_gpu_rasterization_(false), | 326 use_gpu_rasterization_(false), |
| 327 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), | 327 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), |
| 328 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 328 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 329 did_oom_on_last_assign_(false), | 329 did_oom_on_last_assign_(false), |
| 330 more_tiles_need_prepare_check_notifier_( | |
| 331 task_runner_.get(), | |
| 332 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, | |
| 333 base::Unretained(this))), | |
| 334 signals_check_notifier_(task_runner_.get(), | |
| 335 base::Bind(&TileManager::CheckAndIssueSignals, | |
| 336 base::Unretained(this))), | |
| 337 has_scheduled_tile_tasks_(false), | 330 has_scheduled_tile_tasks_(false), |
| 338 prepare_tiles_count_(0u), | 331 prepare_tiles_count_(0u), |
| 339 next_tile_id_(0u), | 332 next_tile_id_(0u), |
| 340 task_set_finished_weak_ptr_factory_(this) {} | 333 task_set_finished_weak_ptr_factory_(this) {} |
| 341 | 334 |
| 342 TileManager::~TileManager() { | 335 TileManager::~TileManager() { |
| 343 FinishTasksAndCleanUp(); | 336 FinishTasksAndCleanUp(); |
| 344 } | 337 } |
| 345 | 338 |
| 346 void TileManager::FinishTasksAndCleanUp() { | 339 void TileManager::FinishTasksAndCleanUp() { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 357 // |orphan_tasks_|. | 350 // |orphan_tasks_|. |
| 358 orphan_tasks_.clear(); | 351 orphan_tasks_.clear(); |
| 359 | 352 |
| 360 tile_task_manager_->CheckForCompletedTasks(); | 353 tile_task_manager_->CheckForCompletedTasks(); |
| 361 | 354 |
| 362 FreeResourcesForReleasedTiles(); | 355 FreeResourcesForReleasedTiles(); |
| 363 CleanUpReleasedTiles(); | 356 CleanUpReleasedTiles(); |
| 364 | 357 |
| 365 tile_task_manager_ = nullptr; | 358 tile_task_manager_ = nullptr; |
| 366 resource_pool_ = nullptr; | 359 resource_pool_ = nullptr; |
| 367 more_tiles_need_prepare_check_notifier_.Cancel(); | |
| 368 signals_check_notifier_.Cancel(); | |
| 369 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 360 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 370 } | 361 } |
| 371 | 362 |
| 372 void TileManager::SetResources(ResourcePool* resource_pool, | 363 void TileManager::SetResources(ResourcePool* resource_pool, |
| 373 ImageDecodeController* image_decode_controller, | 364 ImageDecodeController* image_decode_controller, |
| 374 TileTaskManager* tile_task_manager, | 365 TileTaskManager* tile_task_manager, |
| 375 size_t scheduled_raster_task_limit, | 366 size_t scheduled_raster_task_limit, |
| 376 bool use_gpu_rasterization) { | 367 bool use_gpu_rasterization) { |
| 377 DCHECK(!tile_task_manager_); | 368 DCHECK(!tile_task_manager_); |
| 378 DCHECK(tile_task_manager); | 369 DCHECK(tile_task_manager); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 403 | 394 |
| 404 DCHECK(!tile->draw_info().has_resource()); | 395 DCHECK(!tile->draw_info().has_resource()); |
| 405 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 396 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| 406 tiles_.erase(tile->id()); | 397 tiles_.erase(tile->id()); |
| 407 | 398 |
| 408 delete tile; | 399 delete tile; |
| 409 } | 400 } |
| 410 released_tiles_.swap(tiles_to_retain); | 401 released_tiles_.swap(tiles_to_retain); |
| 411 } | 402 } |
| 412 | 403 |
| 413 void TileManager::DidFinishRunningTileTasksRequiredForActivation() { | 404 void TileManager::DidFinishRunningTileTasksRequiredForActivation( |
| 405 uint64_t source_prepare_tiles_id) { | |
| 414 TRACE_EVENT0("cc", | 406 TRACE_EVENT0("cc", |
| 415 "TileManager::DidFinishRunningTileTasksRequiredForActivation"); | 407 "TileManager::DidFinishRunningTileTasksRequiredForActivation"); |
| 416 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 408 |
| 417 ScheduledTasksStateAsValue()); | 409 // Check if there is another request to PrepareTiles(). |
| 418 signals_.ready_to_activate = true; | 410 if (prepare_tiles_count_ != source_prepare_tiles_id) |
| 419 signals_check_notifier_.Schedule(); | 411 return; |
| 412 | |
| 413 CheckAndNotifyReadyToActivate(); | |
| 420 } | 414 } |
| 421 | 415 |
| 422 void TileManager::DidFinishRunningTileTasksRequiredForDraw() { | 416 void TileManager::DidFinishRunningTileTasksRequiredForDraw( |
| 417 uint64_t source_prepare_tiles_id) { | |
| 423 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTileTasksRequiredForDraw"); | 418 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTileTasksRequiredForDraw"); |
| 424 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 419 |
| 425 ScheduledTasksStateAsValue()); | 420 // Check if there is another request to PrepareTiles(). |
| 426 signals_.ready_to_draw = true; | 421 if (prepare_tiles_count_ != source_prepare_tiles_id) |
| 427 signals_check_notifier_.Schedule(); | 422 return; |
| 423 | |
| 424 CheckAndNotifyReadyToDraw(); | |
| 428 } | 425 } |
| 429 | 426 |
| 430 void TileManager::DidFinishRunningAllTileTasks() { | 427 void TileManager::DidFinishRunningAllTileTasks( |
| 428 uint64_t source_prepare_tiles_id) { | |
| 431 TRACE_EVENT0("cc", "TileManager::DidFinishRunningAllTileTasks"); | 429 TRACE_EVENT0("cc", "TileManager::DidFinishRunningAllTileTasks"); |
| 432 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 430 |
| 433 DCHECK(resource_pool_); | 431 // Check if there is another request to PrepareTiles(). |
| 434 DCHECK(tile_task_manager_); | 432 if (prepare_tiles_count_ != source_prepare_tiles_id) |
| 433 return; | |
| 435 | 434 |
| 436 has_scheduled_tile_tasks_ = false; | 435 has_scheduled_tile_tasks_ = false; |
| 437 | 436 |
| 437 DCHECK(resource_pool_); | |
| 438 | |
| 438 bool memory_usage_above_limit = resource_pool_->memory_usage_bytes() > | 439 bool memory_usage_above_limit = resource_pool_->memory_usage_bytes() > |
| 439 global_state_.soft_memory_limit_in_bytes; | 440 global_state_.soft_memory_limit_in_bytes; |
| 440 | 441 |
| 441 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && | 442 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && |
| 442 !memory_usage_above_limit) { | 443 !memory_usage_above_limit) { |
| 443 // TODO(ericrk): We should find a better way to safely handle re-entrant | 444 CheckAndNotifyAllTileTasksCompleted(); |
| 444 // notifications than always having to schedule a new task. | |
| 445 // http://crbug.com/498439 | |
| 446 signals_.all_tile_tasks_completed = true; | |
| 447 signals_check_notifier_.Schedule(); | |
| 448 return; | 445 return; |
| 449 } | 446 } |
| 450 | 447 |
| 451 more_tiles_need_prepare_check_notifier_.Schedule(); | 448 CheckIfMoreTilesNeedToBePrepared(); |
| 452 } | 449 } |
| 453 | 450 |
| 454 bool TileManager::PrepareTiles( | 451 bool TileManager::PrepareTiles( |
| 455 const GlobalStateThatImpactsTilePriority& state) { | 452 const GlobalStateThatImpactsTilePriority& state) { |
| 456 ++prepare_tiles_count_; | 453 ++prepare_tiles_count_; |
| 457 | 454 |
| 458 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id", | 455 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id", |
| 459 prepare_tiles_count_); | 456 prepare_tiles_count_); |
| 460 | 457 |
| 461 if (!tile_task_manager_) { | 458 if (!tile_task_manager_) { |
| 462 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted", | 459 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted", |
| 463 TRACE_EVENT_SCOPE_THREAD); | 460 TRACE_EVENT_SCOPE_THREAD); |
| 464 return false; | 461 return false; |
| 465 } | 462 } |
| 466 | 463 |
| 467 signals_.reset(); | |
| 468 global_state_ = state; | 464 global_state_ = state; |
| 469 | 465 |
| 470 // We need to call CheckForCompletedTasks() once in-between each call | 466 // We need to call CheckForCompletedTasks() once in-between each call |
| 471 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 467 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 472 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 468 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 473 tile_task_manager_->CheckForCompletedTasks(); | 469 tile_task_manager_->CheckForCompletedTasks(); |
| 474 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 470 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 475 } | 471 } |
| 476 | 472 |
| 477 FreeResourcesForReleasedTiles(); | 473 FreeResourcesForReleasedTiles(); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 tile->draw_info().set_solid_color(color); | 647 tile->draw_info().set_solid_color(color); |
| 652 tile->draw_info().set_was_ever_ready_to_draw(); | 648 tile->draw_info().set_was_ever_ready_to_draw(); |
| 653 if (!tile_is_needed_now) | 649 if (!tile_is_needed_now) |
| 654 tile->draw_info().set_was_a_prepaint_tile(); | 650 tile->draw_info().set_was_a_prepaint_tile(); |
| 655 client_->NotifyTileStateChanged(tile); | 651 client_->NotifyTileStateChanged(tile); |
| 656 continue; | 652 continue; |
| 657 } | 653 } |
| 658 } | 654 } |
| 659 | 655 |
| 660 // We won't be able to schedule this tile, so break out early. | 656 // We won't be able to schedule this tile, so break out early. |
| 661 if (tiles_that_need_to_be_rasterized->size() >= | 657 if (tiles_that_need_to_be_rasterized->size() > |
|
prashant.n
2016/05/27 14:29:22
If size of tiles_that_need_to_be_rasterized = 1 an
| |
| 662 scheduled_raster_task_limit) { | 658 scheduled_raster_task_limit) { |
| 663 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 659 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 664 break; | 660 break; |
| 665 } | 661 } |
| 666 | 662 |
| 667 tile->scheduled_priority_ = schedule_priority++; | 663 tile->scheduled_priority_ = schedule_priority++; |
| 668 | 664 |
| 669 DCHECK(tile->draw_info().mode() == TileDrawInfo::OOM_MODE || | 665 DCHECK(tile->draw_info().mode() == TileDrawInfo::OOM_MODE || |
| 670 !tile->draw_info().IsReadyToDraw()); | 666 !tile->draw_info().IsReadyToDraw()); |
| 671 | 667 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 // been called. | 870 // been called. |
| 875 orphan_tasks_.clear(); | 871 orphan_tasks_.clear(); |
| 876 | 872 |
| 877 // It's also now safe to replace our *_done_task_ tasks. | 873 // It's also now safe to replace our *_done_task_ tasks. |
| 878 required_for_activation_done_task_ = | 874 required_for_activation_done_task_ = |
| 879 std::move(required_for_activation_done_task); | 875 std::move(required_for_activation_done_task); |
| 880 required_for_draw_done_task_ = std::move(required_for_draw_done_task); | 876 required_for_draw_done_task_ = std::move(required_for_draw_done_task); |
| 881 all_done_task_ = std::move(all_done_task); | 877 all_done_task_ = std::move(all_done_task); |
| 882 | 878 |
| 883 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; | 879 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; |
| 884 | |
| 885 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | |
| 886 ScheduledTasksStateAsValue()); | |
| 887 } | 880 } |
| 888 | 881 |
| 889 scoped_refptr<TileTask> TileManager::CreateRasterTask( | 882 scoped_refptr<TileTask> TileManager::CreateRasterTask( |
| 890 const PrioritizedTile& prioritized_tile) { | 883 const PrioritizedTile& prioritized_tile) { |
| 891 Tile* tile = prioritized_tile.tile(); | 884 Tile* tile = prioritized_tile.tile(); |
| 892 | 885 |
| 893 // Get the resource. | 886 // Get the resource. |
| 894 uint64_t resource_content_id = 0; | 887 uint64_t resource_content_id = 0; |
| 895 Resource* resource = nullptr; | 888 Resource* resource = nullptr; |
| 896 if (use_partial_raster_ && tile->invalidated_id()) { | 889 if (use_partial_raster_ && tile->invalidated_id()) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1044 return AreRequiredTilesReadyToDraw( | 1037 return AreRequiredTilesReadyToDraw( |
| 1045 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); | 1038 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); |
| 1046 } | 1039 } |
| 1047 | 1040 |
| 1048 bool TileManager::IsReadyToDraw() const { | 1041 bool TileManager::IsReadyToDraw() const { |
| 1049 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); | 1042 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); |
| 1050 return AreRequiredTilesReadyToDraw( | 1043 return AreRequiredTilesReadyToDraw( |
| 1051 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); | 1044 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); |
| 1052 } | 1045 } |
| 1053 | 1046 |
| 1054 void TileManager::CheckAndIssueSignals() { | 1047 void TileManager::CheckAndNotifyReadyToActivate() { |
| 1055 TRACE_EVENT0("cc", "TileManager::CheckAndIssueSignals"); | 1048 TRACE_EVENT0("cc", "TileManager::CheckAndNotifyReadyToActivate"); |
| 1049 DCHECK(tile_task_manager_); | |
| 1050 | |
| 1056 tile_task_manager_->CheckForCompletedTasks(); | 1051 tile_task_manager_->CheckForCompletedTasks(); |
| 1057 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1052 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1058 | 1053 |
| 1059 // Ready to activate. | 1054 // Ready to activate. |
| 1060 if (signals_.ready_to_activate && !signals_.did_notify_ready_to_activate) { | 1055 if (IsReadyToActivate()) { |
| 1061 signals_.ready_to_activate = false; | 1056 TRACE_EVENT0( |
| 1062 if (IsReadyToActivate()) { | 1057 "disabled-by-default-cc.debug", |
| 1063 TRACE_EVENT0("disabled-by-default-cc.debug", | 1058 "TileManager::CheckAndNotifyReadyToActivate - ready to activate"); |
| 1064 "TileManager::CheckAndIssueSignals - ready to activate"); | 1059 client_->NotifyReadyToActivate(); |
| 1065 signals_.did_notify_ready_to_activate = true; | |
| 1066 client_->NotifyReadyToActivate(); | |
| 1067 } | |
| 1068 } | 1060 } |
| 1061 } | |
| 1062 void TileManager::CheckAndNotifyReadyToDraw() { | |
| 1063 TRACE_EVENT0("cc", "TileManager::CheckAndNotifyReadyToDraw"); | |
| 1064 | |
| 1065 DCHECK(tile_task_manager_); | |
| 1066 | |
| 1067 tile_task_manager_->CheckForCompletedTasks(); | |
| 1068 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | |
| 1069 | 1069 |
| 1070 // Ready to draw. | 1070 // Ready to draw. |
| 1071 if (signals_.ready_to_draw && !signals_.did_notify_ready_to_draw) { | 1071 if (IsReadyToDraw()) { |
| 1072 signals_.ready_to_draw = false; | 1072 TRACE_EVENT0("disabled-by-default-cc.debug", |
| 1073 if (IsReadyToDraw()) { | 1073 "TileManager::CheckAndNotifyReadyToDraw - ready to draw"); |
| 1074 TRACE_EVENT0("disabled-by-default-cc.debug", | 1074 client_->NotifyReadyToDraw(); |
| 1075 "TileManager::CheckAndIssueSignals - ready to draw"); | |
| 1076 signals_.did_notify_ready_to_draw = true; | |
| 1077 client_->NotifyReadyToDraw(); | |
| 1078 } | |
| 1079 } | 1075 } |
| 1076 } | |
| 1077 | |
| 1078 void TileManager::CheckAndNotifyAllTileTasksCompleted() { | |
| 1079 TRACE_EVENT0("cc", "TileManager::CheckAndNotifyAllTileTasksCompleted"); | |
| 1080 | |
| 1081 DCHECK(tile_task_manager_); | |
| 1082 tile_task_manager_->CheckForCompletedTasks(); | |
| 1083 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | |
| 1080 | 1084 |
| 1081 // All tile tasks completed. | 1085 // All tile tasks completed. |
| 1082 if (signals_.all_tile_tasks_completed && | 1086 if (!has_scheduled_tile_tasks_) { |
| 1083 !signals_.did_notify_all_tile_tasks_completed) { | 1087 TRACE_EVENT0("disabled-by-default-cc.debug", |
| 1084 signals_.all_tile_tasks_completed = false; | 1088 "TileManager::CheckAndNotifyAllTileTasksCompleted - all tile " |
| 1085 if (!has_scheduled_tile_tasks_) { | 1089 "tasks completed"); |
| 1086 TRACE_EVENT0( | 1090 client_->NotifyAllTileTasksCompleted(); |
| 1087 "disabled-by-default-cc.debug", | |
| 1088 "TileManager::CheckAndIssueSignals - all tile tasks completed"); | |
| 1089 signals_.did_notify_all_tile_tasks_completed = true; | |
| 1090 client_->NotifyAllTileTasksCompleted(); | |
| 1091 } | |
| 1092 } | 1091 } |
| 1093 } | 1092 } |
| 1094 | 1093 |
| 1095 void TileManager::CheckIfMoreTilesNeedToBePrepared() { | 1094 void TileManager::CheckIfMoreTilesNeedToBePrepared() { |
| 1095 DCHECK(tile_task_manager_); | |
| 1096 | |
| 1096 tile_task_manager_->CheckForCompletedTasks(); | 1097 tile_task_manager_->CheckForCompletedTasks(); |
| 1097 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1098 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1098 | 1099 |
| 1099 // When OOM, keep re-assigning memory until we reach a steady state | 1100 // When OOM, keep re-assigning memory until we reach a steady state |
| 1100 // where top-priority tiles are initialized. | 1101 // where top-priority tiles are initialized. |
| 1101 PrioritizedTileVector tiles_that_need_to_be_rasterized; | 1102 PrioritizedTileVector tiles_that_need_to_be_rasterized; |
| 1102 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( | 1103 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 1103 client_->BuildRasterQueue(global_state_.tree_priority, | 1104 client_->BuildRasterQueue(global_state_.tree_priority, |
| 1104 RasterTilePriorityQueue::Type::ALL)); | 1105 RasterTilePriorityQueue::Type::ALL)); |
| 1105 AssignGpuMemoryToTiles(raster_priority_queue.get(), | 1106 AssignGpuMemoryToTiles(raster_priority_queue.get(), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1117 if (!tiles_that_need_to_be_rasterized.empty()) { | 1118 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 1118 ScheduleTasks(tiles_that_need_to_be_rasterized); | 1119 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 1119 return; | 1120 return; |
| 1120 } | 1121 } |
| 1121 | 1122 |
| 1122 FreeResourcesForReleasedTiles(); | 1123 FreeResourcesForReleasedTiles(); |
| 1123 | 1124 |
| 1124 resource_pool_->ReduceResourceUsage(); | 1125 resource_pool_->ReduceResourceUsage(); |
| 1125 image_decode_controller_->ReduceCacheUsage(); | 1126 image_decode_controller_->ReduceCacheUsage(); |
| 1126 | 1127 |
| 1127 signals_.all_tile_tasks_completed = true; | |
| 1128 signals_check_notifier_.Schedule(); | |
| 1129 | |
| 1130 // We don't reserve memory for required-for-activation tiles during | 1128 // We don't reserve memory for required-for-activation tiles during |
| 1131 // accelerated gestures, so we just postpone activation when we don't | 1129 // accelerated gestures, so we just postpone activation when we don't |
| 1132 // have these tiles, and activate after the accelerated gesture. | 1130 // have these tiles, and activate after the accelerated gesture. |
| 1133 // Likewise if we don't allow any tiles (as is the case when we're | 1131 // Likewise if we don't allow any tiles (as is the case when we're |
| 1134 // invisible), if we have tiles that aren't ready, then we shouldn't | 1132 // invisible), if we have tiles that aren't ready, then we shouldn't |
| 1135 // activate as activation can cause checkerboards. | 1133 // activate as activation can cause checkerboards. |
| 1136 bool wait_for_all_required_tiles = | 1134 bool wait_for_all_required_tiles = |
| 1137 global_state_.tree_priority == SMOOTHNESS_TAKES_PRIORITY || | 1135 global_state_.tree_priority == SMOOTHNESS_TAKES_PRIORITY || |
| 1138 global_state_.memory_limit_policy == ALLOW_NOTHING; | 1136 global_state_.memory_limit_policy == ALLOW_NOTHING; |
| 1139 | 1137 |
| 1140 // If we have tiles left to raster for activation, and we don't allow | 1138 // If we have tiles left to raster for activation, and we don't allow |
| 1141 // activating without them, then skip activation and return early. | 1139 // activating without them, then skip activation and return early. |
| 1142 if (wait_for_all_required_tiles) | 1140 if (wait_for_all_required_tiles) |
| 1143 return; | 1141 return; |
| 1144 | 1142 |
| 1145 // Mark any required tiles that have not been been assigned memory after | 1143 // Mark any required tiles that have not been been assigned memory after |
| 1146 // reaching a steady memory state as OOM. This ensures that we activate/draw | 1144 // reaching a steady memory state as OOM. This ensures that we activate/draw |
| 1147 // even when OOM. Note that we can't reuse the queue we used for | 1145 // even when OOM. Note that we can't reuse the queue we used for |
| 1148 // AssignGpuMemoryToTiles, since the AssignGpuMemoryToTiles call could have | 1146 // AssignGpuMemoryToTiles, since the AssignGpuMemoryToTiles call could have |
| 1149 // evicted some tiles that would not be picked up by the old raster queue. | 1147 // evicted some tiles that would not be picked up by the old raster queue. |
| 1150 bool need_to_signal_activate = MarkTilesOutOfMemory(client_->BuildRasterQueue( | 1148 bool need_to_signal_activate = MarkTilesOutOfMemory(client_->BuildRasterQueue( |
| 1151 global_state_.tree_priority, | 1149 global_state_.tree_priority, |
| 1152 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); | 1150 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); |
| 1153 bool need_to_signal_draw = MarkTilesOutOfMemory(client_->BuildRasterQueue( | 1151 bool need_to_signal_draw = MarkTilesOutOfMemory(client_->BuildRasterQueue( |
| 1154 global_state_.tree_priority, | 1152 global_state_.tree_priority, |
| 1155 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW)); | 1153 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW)); |
| 1156 | 1154 |
| 1157 DCHECK(IsReadyToActivate()); | 1155 if (need_to_signal_activate) |
| 1158 DCHECK(IsReadyToDraw()); | 1156 CheckAndNotifyReadyToActivate(); |
|
prashant.n
2016/05/27 14:29:22
I'll remove checking of completed tasks to common
| |
| 1159 signals_.ready_to_activate = need_to_signal_activate; | 1157 |
| 1160 signals_.ready_to_draw = need_to_signal_draw; | 1158 if (need_to_signal_draw) |
| 1161 // TODO(ericrk): Investigate why we need to schedule this (not just call it | 1159 CheckAndNotifyReadyToDraw(); |
| 1162 // inline). http://crbug.com/498439 | 1160 |
| 1163 signals_check_notifier_.Schedule(); | 1161 CheckAndNotifyAllTileTasksCompleted(); |
| 1164 } | 1162 } |
| 1165 | 1163 |
| 1166 bool TileManager::MarkTilesOutOfMemory( | 1164 bool TileManager::MarkTilesOutOfMemory( |
| 1167 std::unique_ptr<RasterTilePriorityQueue> queue) const { | 1165 std::unique_ptr<RasterTilePriorityQueue> queue) const { |
| 1168 // Mark required tiles as OOM so that we can activate/draw without them. | 1166 // Mark required tiles as OOM so that we can activate/draw without them. |
| 1169 if (queue->IsEmpty()) | 1167 if (queue->IsEmpty()) |
| 1170 return false; | 1168 return false; |
| 1171 | 1169 |
| 1172 for (; !queue->IsEmpty(); queue->Pop()) { | 1170 for (; !queue->IsEmpty(); queue->Pop()) { |
| 1173 Tile* tile = queue->Top().tile(); | 1171 Tile* tile = queue->Top().tile(); |
| 1174 if (tile->draw_info().IsReadyToDraw()) | 1172 if (tile->draw_info().IsReadyToDraw()) |
| 1175 continue; | 1173 continue; |
| 1176 tile->draw_info().set_oom(); | 1174 tile->draw_info().set_oom(); |
| 1177 client_->NotifyTileStateChanged(tile); | 1175 client_->NotifyTileStateChanged(tile); |
| 1178 } | 1176 } |
| 1179 return true; | 1177 return true; |
| 1180 } | 1178 } |
| 1181 | 1179 |
| 1182 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { | 1180 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { |
| 1183 return tile_task_manager_->GetRasterBufferProvider()->GetResourceFormat( | 1181 return tile_task_manager_->GetRasterBufferProvider()->GetResourceFormat( |
| 1184 !tile->is_opaque()); | 1182 !tile->is_opaque()); |
| 1185 } | 1183 } |
| 1186 | 1184 |
| 1187 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const { | 1185 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const { |
| 1188 return tile_task_manager_->GetRasterBufferProvider() | 1186 return tile_task_manager_->GetRasterBufferProvider() |
| 1189 ->GetResourceRequiresSwizzle(!tile->is_opaque()); | 1187 ->GetResourceRequiresSwizzle(!tile->is_opaque()); |
| 1190 } | 1188 } |
| 1191 | 1189 |
| 1192 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | |
| 1193 TileManager::ScheduledTasksStateAsValue() const { | |
| 1194 std::unique_ptr<base::trace_event::TracedValue> state( | |
| 1195 new base::trace_event::TracedValue()); | |
| 1196 state->BeginDictionary("tasks_pending"); | |
| 1197 state->SetBoolean("ready_to_activate", signals_.ready_to_activate); | |
| 1198 state->SetBoolean("ready_to_draw", signals_.ready_to_draw); | |
| 1199 state->SetBoolean("all_tile_tasks_completed", | |
| 1200 signals_.all_tile_tasks_completed); | |
| 1201 state->EndDictionary(); | |
| 1202 return std::move(state); | |
| 1203 } | |
| 1204 | |
| 1205 // Utility function that can be used to create a "Task set finished" task that | 1190 // Utility function that can be used to create a "Task set finished" task that |
| 1206 // posts |callback| to |task_runner| when run. | 1191 // posts |callback| to |task_runner| when run. |
| 1207 scoped_refptr<TileTask> TileManager::CreateTaskSetFinishedTask( | 1192 scoped_refptr<TileTask> TileManager::CreateTaskSetFinishedTask( |
| 1208 void (TileManager::*callback)()) { | 1193 void (TileManager::*callback)(uint64_t source_prepare_tiles_id)) { |
| 1209 return make_scoped_refptr(new TaskSetFinishedTaskImpl( | 1194 return make_scoped_refptr(new TaskSetFinishedTaskImpl( |
| 1210 task_runner_.get(), | 1195 task_runner_.get(), |
| 1211 base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr()))); | 1196 base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr(), |
| 1197 prepare_tiles_count_))); | |
| 1212 } | 1198 } |
| 1213 | 1199 |
| 1214 TileManager::MemoryUsage::MemoryUsage() | 1200 TileManager::MemoryUsage::MemoryUsage() |
| 1215 : memory_bytes_(0), resource_count_(0) {} | 1201 : memory_bytes_(0), resource_count_(0) {} |
| 1216 | 1202 |
| 1217 TileManager::MemoryUsage::MemoryUsage(size_t memory_bytes, | 1203 TileManager::MemoryUsage::MemoryUsage(size_t memory_bytes, |
| 1218 size_t resource_count) | 1204 size_t resource_count) |
| 1219 : memory_bytes_(static_cast<int64_t>(memory_bytes)), | 1205 : memory_bytes_(static_cast<int64_t>(memory_bytes)), |
| 1220 resource_count_(static_cast<int>(resource_count)) { | 1206 resource_count_(static_cast<int>(resource_count)) { |
| 1221 // MemoryUsage is constructed using size_ts, since it deals with memory and | 1207 // MemoryUsage is constructed using size_ts, since it deals with memory and |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1267 MemoryUsage result = *this; | 1253 MemoryUsage result = *this; |
| 1268 result -= other; | 1254 result -= other; |
| 1269 return result; | 1255 return result; |
| 1270 } | 1256 } |
| 1271 | 1257 |
| 1272 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1258 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 1273 return memory_bytes_ > limit.memory_bytes_ || | 1259 return memory_bytes_ > limit.memory_bytes_ || |
| 1274 resource_count_ > limit.resource_count_; | 1260 resource_count_ > limit.resource_count_; |
| 1275 } | 1261 } |
| 1276 | 1262 |
| 1277 TileManager::Signals::Signals() { | |
| 1278 reset(); | |
| 1279 } | |
| 1280 | |
| 1281 void TileManager::Signals::reset() { | |
| 1282 ready_to_activate = false; | |
| 1283 did_notify_ready_to_activate = false; | |
| 1284 ready_to_draw = false; | |
| 1285 did_notify_ready_to_draw = false; | |
| 1286 all_tile_tasks_completed = false; | |
| 1287 did_notify_all_tile_tasks_completed = false; | |
| 1288 } | |
| 1289 | |
| 1290 } // namespace cc | 1263 } // namespace cc |
| OLD | NEW |