| 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/resources/tile_manager.h" | 5 #include "cc/resources/tile_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/debug/trace_event_argument.h" | 12 #include "base/debug/trace_event_argument.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "cc/debug/devtools_instrumentation.h" | 16 #include "cc/debug/devtools_instrumentation.h" |
| 17 #include "cc/debug/frame_viewer_instrumentation.h" | 17 #include "cc/debug/frame_viewer_instrumentation.h" |
| 18 #include "cc/debug/traced_value.h" | 18 #include "cc/debug/traced_value.h" |
| 19 #include "cc/layers/picture_layer_impl.h" | 19 #include "cc/layers/picture_layer_impl.h" |
| 20 #include "cc/resources/raster_buffer.h" | 20 #include "cc/resources/raster_buffer.h" |
| 21 #include "cc/resources/rasterizer.h" |
| 21 #include "cc/resources/tile.h" | 22 #include "cc/resources/tile.h" |
| 22 #include "cc/resources/tile_task_runner.h" | 23 #include "cc/resources/tile_task_runner.h" |
| 23 #include "ui/gfx/geometry/rect_conversions.h" | 24 #include "ui/gfx/geometry/rect_conversions.h" |
| 24 | 25 |
| 25 namespace cc { | 26 namespace cc { |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Flag to indicate whether we should try and detect that | 29 // Flag to indicate whether we should try and detect that |
| 29 // a tile is of solid color. | 30 // a tile is of solid color. |
| 30 const bool kUseColorEstimator = true; | 31 const bool kUseColorEstimator = true; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 state->SetInteger("canceled_count", stats.canceled_count); | 195 state->SetInteger("canceled_count", stats.canceled_count); |
| 195 return state; | 196 return state; |
| 196 } | 197 } |
| 197 | 198 |
| 198 // static | 199 // static |
| 199 scoped_ptr<TileManager> TileManager::Create( | 200 scoped_ptr<TileManager> TileManager::Create( |
| 200 TileManagerClient* client, | 201 TileManagerClient* client, |
| 201 base::SequencedTaskRunner* task_runner, | 202 base::SequencedTaskRunner* task_runner, |
| 202 ResourcePool* resource_pool, | 203 ResourcePool* resource_pool, |
| 203 TileTaskRunner* tile_task_runner, | 204 TileTaskRunner* tile_task_runner, |
| 205 Rasterizer* rasterizer, |
| 204 size_t scheduled_raster_task_limit) { | 206 size_t scheduled_raster_task_limit) { |
| 205 return make_scoped_ptr(new TileManager(client, task_runner, resource_pool, | 207 return make_scoped_ptr(new TileManager(client, task_runner, resource_pool, |
| 206 tile_task_runner, | 208 tile_task_runner, rasterizer, |
| 207 scheduled_raster_task_limit)); | 209 scheduled_raster_task_limit)); |
| 208 } | 210 } |
| 209 | 211 |
| 210 TileManager::TileManager( | 212 TileManager::TileManager( |
| 211 TileManagerClient* client, | 213 TileManagerClient* client, |
| 212 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 214 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 213 ResourcePool* resource_pool, | 215 ResourcePool* resource_pool, |
| 214 TileTaskRunner* tile_task_runner, | 216 TileTaskRunner* tile_task_runner, |
| 217 Rasterizer* rasterizer, |
| 215 size_t scheduled_raster_task_limit) | 218 size_t scheduled_raster_task_limit) |
| 216 : client_(client), | 219 : client_(client), |
| 217 task_runner_(task_runner), | 220 task_runner_(task_runner), |
| 218 resource_pool_(resource_pool), | 221 resource_pool_(resource_pool), |
| 219 tile_task_runner_(tile_task_runner), | 222 tile_task_runner_(tile_task_runner), |
| 223 rasterizer_(rasterizer), |
| 220 scheduled_raster_task_limit_(scheduled_raster_task_limit), | 224 scheduled_raster_task_limit_(scheduled_raster_task_limit), |
| 221 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), | 225 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), |
| 222 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 226 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 223 did_oom_on_last_assign_(false), | 227 did_oom_on_last_assign_(false), |
| 228 ready_to_activate_notifier_( |
| 229 task_runner_.get(), |
| 230 base::Bind(&TileManager::NotifyReadyToActivate, |
| 231 base::Unretained(this))), |
| 232 ready_to_draw_notifier_( |
| 233 task_runner_.get(), |
| 234 base::Bind(&TileManager::NotifyReadyToDraw, base::Unretained(this))), |
| 224 ready_to_activate_check_notifier_( | 235 ready_to_activate_check_notifier_( |
| 225 task_runner_.get(), | 236 task_runner_.get(), |
| 226 base::Bind(&TileManager::CheckIfReadyToActivate, | 237 base::Bind(&TileManager::CheckIfReadyToActivate, |
| 227 base::Unretained(this))), | 238 base::Unretained(this))), |
| 228 ready_to_draw_check_notifier_( | 239 ready_to_draw_check_notifier_( |
| 229 task_runner_.get(), | 240 task_runner_.get(), |
| 230 base::Bind(&TileManager::CheckIfReadyToDraw, base::Unretained(this))), | 241 base::Bind(&TileManager::CheckIfReadyToDraw, base::Unretained(this))), |
| 231 more_tiles_need_prepare_check_notifier_( | 242 more_tiles_need_prepare_check_notifier_( |
| 232 task_runner_.get(), | 243 task_runner_.get(), |
| 233 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, | 244 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 340 |
| 330 NOTREACHED(); | 341 NOTREACHED(); |
| 331 } | 342 } |
| 332 | 343 |
| 333 void TileManager::PrepareTiles( | 344 void TileManager::PrepareTiles( |
| 334 const GlobalStateThatImpactsTilePriority& state) { | 345 const GlobalStateThatImpactsTilePriority& state) { |
| 335 TRACE_EVENT0("cc", "TileManager::PrepareTiles"); | 346 TRACE_EVENT0("cc", "TileManager::PrepareTiles"); |
| 336 | 347 |
| 337 global_state_ = state; | 348 global_state_ = state; |
| 338 | 349 |
| 339 // We need to call CheckForCompletedTasks() once in-between each call | 350 PrepareTilesMode prepare_tiles_mode = rasterizer_->GetPrepareTilesMode(); |
| 340 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 351 |
| 341 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 352 // TODO(hendrikw): Consider moving some of this code to the rasterizer. |
| 342 tile_task_runner_->CheckForCompletedTasks(); | 353 if (prepare_tiles_mode != PrepareTilesMode::PREPARE_NONE) { |
| 343 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 354 // We need to call CheckForCompletedTasks() once in-between each call |
| 355 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 356 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 357 tile_task_runner_->CheckForCompletedTasks(); |
| 358 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 359 } |
| 360 |
| 361 FreeResourcesForReleasedTiles(); |
| 362 CleanUpReleasedTiles(); |
| 363 |
| 364 TileVector tiles_that_need_to_be_rasterized; |
| 365 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 366 scheduled_raster_task_limit_); |
| 367 |
| 368 // Schedule tile tasks. |
| 369 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 370 |
| 371 did_notify_ready_to_activate_ = false; |
| 372 did_notify_ready_to_draw_ = false; |
| 373 } else { |
| 374 if (global_state_.hard_memory_limit_in_bytes == 0) { |
| 375 TileVector tiles_that_need_to_be_rasterized; |
| 376 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 377 scheduled_raster_task_limit_); |
| 378 DCHECK(tiles_that_need_to_be_rasterized.empty()); |
| 379 } |
| 380 |
| 381 did_notify_ready_to_activate_ = false; |
| 382 did_notify_ready_to_draw_ = false; |
| 383 ready_to_activate_notifier_.Schedule(); |
| 384 ready_to_draw_notifier_.Schedule(); |
| 344 } | 385 } |
| 345 | 386 |
| 387 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, |
| 388 "state", BasicStateAsValue()); |
| 389 |
| 390 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, |
| 391 resource_pool_->total_memory_usage_bytes() - |
| 392 resource_pool_->acquired_memory_usage_bytes()); |
| 393 } |
| 394 |
| 395 void TileManager::SynchronouslyRasterizeTiles( |
| 396 const GlobalStateThatImpactsTilePriority& state) { |
| 397 TRACE_EVENT0("cc", "TileManager::SynchronouslyRasterizeTiles"); |
| 398 |
| 399 DCHECK(rasterizer_->GetPrepareTilesMode() != |
| 400 PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES); |
| 401 |
| 402 global_state_ = state; |
| 403 |
| 346 FreeResourcesForReleasedTiles(); | 404 FreeResourcesForReleasedTiles(); |
| 347 CleanUpReleasedTiles(); | 405 CleanUpReleasedTiles(); |
| 348 | 406 |
| 349 TileVector tiles_that_need_to_be_rasterized; | 407 TileVector tiles_that_need_to_be_rasterized; |
| 350 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); | 408 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 409 std::numeric_limits<size_t>::max()); |
| 351 | 410 |
| 352 // Schedule tile tasks. | 411 // We must reduce the amount of unused resources before calling |
| 353 ScheduleTasks(tiles_that_need_to_be_rasterized); | 412 // RunTasks to prevent usage from rising above limits. |
| 413 resource_pool_->ReduceResourceUsage(); |
| 354 | 414 |
| 355 did_notify_ready_to_activate_ = false; | 415 // Run and complete all raster task synchronously. |
| 356 did_notify_ready_to_draw_ = false; | 416 rasterizer_->RasterizeTiles( |
| 417 tiles_that_need_to_be_rasterized, resource_pool_, |
| 418 base::Bind(&TileManager::UpdateTileDrawInfo, base::Unretained(this))); |
| 357 | 419 |
| 358 TRACE_EVENT_INSTANT1("cc", "DidPrepare", TRACE_EVENT_SCOPE_THREAD, "state", | 420 // Use on-demand raster for any required-for-activation tiles that have not |
| 421 // been been assigned memory after reaching a steady memory state. This |
| 422 // ensures that we activate even when OOM. Note that we have to rebuilt the |
| 423 // queue in case the last AssignGpuMemoryToTiles evicted some tiles that would |
| 424 // otherwise not be picked up by the old raster queue. |
| 425 client_->BuildRasterQueue(&raster_priority_queue_, |
| 426 global_state_.tree_priority); |
| 427 |
| 428 // Use on-demand raster for any tiles that have not been been assigned |
| 429 // memory. This ensures that we draw even when OOM. |
| 430 while (!raster_priority_queue_.IsEmpty()) { |
| 431 Tile* tile = raster_priority_queue_.Top(); |
| 432 TileDrawInfo& draw_info = tile->draw_info(); |
| 433 |
| 434 if (tile->required_for_draw() && !draw_info.IsReadyToDraw()) { |
| 435 draw_info.set_rasterize_on_demand(); |
| 436 client_->NotifyTileStateChanged(tile); |
| 437 } |
| 438 raster_priority_queue_.Pop(); |
| 439 } |
| 440 raster_priority_queue_.Reset(); |
| 441 |
| 442 TRACE_EVENT_INSTANT1("cc", "DidRasterize", TRACE_EVENT_SCOPE_THREAD, "state", |
| 359 BasicStateAsValue()); | 443 BasicStateAsValue()); |
| 360 | 444 |
| 361 TRACE_COUNTER_ID1("cc", | 445 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, |
| 362 "unused_memory_bytes", | |
| 363 this, | |
| 364 resource_pool_->total_memory_usage_bytes() - | 446 resource_pool_->total_memory_usage_bytes() - |
| 365 resource_pool_->acquired_memory_usage_bytes()); | 447 resource_pool_->acquired_memory_usage_bytes()); |
| 366 } | 448 } |
| 367 | 449 |
| 368 void TileManager::UpdateVisibleTiles() { | 450 void TileManager::UpdateVisibleTiles( |
| 451 const GlobalStateThatImpactsTilePriority& state) { |
| 369 TRACE_EVENT0("cc", "TileManager::UpdateVisibleTiles"); | 452 TRACE_EVENT0("cc", "TileManager::UpdateVisibleTiles"); |
| 370 | 453 |
| 371 tile_task_runner_->CheckForCompletedTasks(); | 454 tile_task_runner_->CheckForCompletedTasks(); |
| 455 |
| 456 DCHECK(rasterizer_); |
| 457 PrepareTilesMode prepare_tiles_mode = rasterizer_->GetPrepareTilesMode(); |
| 458 if (prepare_tiles_mode != PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES) |
| 459 SynchronouslyRasterizeTiles(state); |
| 460 |
| 372 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 461 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 373 | 462 |
| 374 TRACE_EVENT_INSTANT1( | 463 TRACE_EVENT_INSTANT1( |
| 375 "cc", | 464 "cc", |
| 376 "DidUpdateVisibleTiles", | 465 "DidUpdateVisibleTiles", |
| 377 TRACE_EVENT_SCOPE_THREAD, | 466 TRACE_EVENT_SCOPE_THREAD, |
| 378 "stats", | 467 "stats", |
| 379 RasterTaskCompletionStatsAsValue(update_visible_tiles_stats_)); | 468 RasterTaskCompletionStatsAsValue(update_visible_tiles_stats_)); |
| 380 update_visible_tiles_stats_ = RasterTaskCompletionStats(); | 469 update_visible_tiles_stats_ = RasterTaskCompletionStats(); |
| 381 } | 470 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 return priority.priority_bin > TilePriority::SOON; | 546 return priority.priority_bin > TilePriority::SOON; |
| 458 case ALLOW_ANYTHING: | 547 case ALLOW_ANYTHING: |
| 459 return priority.distance_to_visible == | 548 return priority.distance_to_visible == |
| 460 std::numeric_limits<float>::infinity(); | 549 std::numeric_limits<float>::infinity(); |
| 461 } | 550 } |
| 462 NOTREACHED(); | 551 NOTREACHED(); |
| 463 return true; | 552 return true; |
| 464 } | 553 } |
| 465 | 554 |
| 466 void TileManager::AssignGpuMemoryToTiles( | 555 void TileManager::AssignGpuMemoryToTiles( |
| 467 TileVector* tiles_that_need_to_be_rasterized) { | 556 TileVector* tiles_that_need_to_be_rasterized, |
| 557 size_t scheduled_raster_task_limit) { |
| 468 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); | 558 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 469 | 559 |
| 470 // Maintain the list of released resources that can potentially be re-used | 560 // Maintain the list of released resources that can potentially be re-used |
| 471 // or deleted. | 561 // or deleted. |
| 472 // If this operation becomes expensive too, only do this after some | 562 // If this operation becomes expensive too, only do this after some |
| 473 // resource(s) was returned. Note that in that case, one also need to | 563 // resource(s) was returned. Note that in that case, one also need to |
| 474 // invalidate when releasing some resource from the pool. | 564 // invalidate when releasing some resource from the pool. |
| 475 resource_pool_->CheckBusyResources(false); | 565 resource_pool_->CheckBusyResources(false); |
| 476 | 566 |
| 477 // Now give memory out to the tiles until we're out, and build | 567 // Now give memory out to the tiles until we're out, and build |
| (...skipping 12 matching lines...) Expand all Loading... |
| 490 eviction_priority_queue_is_up_to_date_ = false; | 580 eviction_priority_queue_is_up_to_date_ = false; |
| 491 client_->BuildRasterQueue(&raster_priority_queue_, | 581 client_->BuildRasterQueue(&raster_priority_queue_, |
| 492 global_state_.tree_priority); | 582 global_state_.tree_priority); |
| 493 | 583 |
| 494 while (!raster_priority_queue_.IsEmpty()) { | 584 while (!raster_priority_queue_.IsEmpty()) { |
| 495 Tile* tile = raster_priority_queue_.Top(); | 585 Tile* tile = raster_priority_queue_.Top(); |
| 496 TilePriority priority = tile->combined_priority(); | 586 TilePriority priority = tile->combined_priority(); |
| 497 | 587 |
| 498 if (TilePriorityViolatesMemoryPolicy(priority)) { | 588 if (TilePriorityViolatesMemoryPolicy(priority)) { |
| 499 TRACE_EVENT_INSTANT0( | 589 TRACE_EVENT_INSTANT0( |
| 500 "cc", | 590 "cc", "TileManager::AssignGpuMemory tile violates memory policy", |
| 501 "TileManager::AssignGpuMemory tile violates memory policy", | |
| 502 TRACE_EVENT_SCOPE_THREAD); | 591 TRACE_EVENT_SCOPE_THREAD); |
| 503 break; | 592 break; |
| 504 } | 593 } |
| 505 | 594 |
| 506 // We won't be able to schedule this tile, so break out early. | 595 // We won't be able to schedule this tile, so break out early. |
| 507 if (tiles_that_need_to_be_rasterized->size() >= | 596 if (tiles_that_need_to_be_rasterized->size() >= |
| 508 scheduled_raster_task_limit_) { | 597 scheduled_raster_task_limit) { |
| 509 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 598 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 510 break; | 599 break; |
| 511 } | 600 } |
| 512 | 601 |
| 513 TileDrawInfo& draw_info = tile->draw_info(); | 602 TileDrawInfo& draw_info = tile->draw_info(); |
| 514 tile->scheduled_priority_ = schedule_priority++; | 603 tile->scheduled_priority_ = schedule_priority++; |
| 515 | 604 |
| 516 DCHECK(draw_info.mode() == TileDrawInfo::PICTURE_PILE_MODE || | 605 DCHECK(draw_info.mode() == TileDrawInfo::PICTURE_PILE_MODE || |
| 517 !draw_info.IsReadyToDraw()); | 606 !draw_info.IsReadyToDraw()); |
| 518 | 607 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 529 | 618 |
| 530 // This is the memory limit that will be used by this tile. Depending on | 619 // This is the memory limit that will be used by this tile. Depending on |
| 531 // the tile priority, it will be one of hard_memory_limit or | 620 // the tile priority, it will be one of hard_memory_limit or |
| 532 // soft_memory_limit. | 621 // soft_memory_limit. |
| 533 MemoryUsage& tile_memory_limit = | 622 MemoryUsage& tile_memory_limit = |
| 534 tile_is_needed_now ? hard_memory_limit : soft_memory_limit; | 623 tile_is_needed_now ? hard_memory_limit : soft_memory_limit; |
| 535 | 624 |
| 536 bool memory_usage_is_within_limit = | 625 bool memory_usage_is_within_limit = |
| 537 FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 626 FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 538 tile_memory_limit - memory_required_by_tile_to_be_scheduled, | 627 tile_memory_limit - memory_required_by_tile_to_be_scheduled, |
| 539 priority, | 628 priority, &memory_usage); |
| 540 &memory_usage); | |
| 541 | 629 |
| 542 // If we couldn't fit the tile into our current memory limit, then we're | 630 // If we couldn't fit the tile into our current memory limit, then we're |
| 543 // done. | 631 // done. |
| 544 if (!memory_usage_is_within_limit) { | 632 if (!memory_usage_is_within_limit) { |
| 545 if (tile_is_needed_now) | 633 if (tile_is_needed_now) |
| 546 had_enough_memory_to_schedule_tiles_needed_now = false; | 634 had_enough_memory_to_schedule_tiles_needed_now = false; |
| 547 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 635 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 548 break; | 636 break; |
| 549 } | 637 } |
| 550 | 638 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 563 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now; | 651 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now; |
| 564 | 652 |
| 565 memory_stats_from_last_assign_.total_budget_in_bytes = | 653 memory_stats_from_last_assign_.total_budget_in_bytes = |
| 566 global_state_.hard_memory_limit_in_bytes; | 654 global_state_.hard_memory_limit_in_bytes; |
| 567 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); | 655 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); |
| 568 memory_stats_from_last_assign_.had_enough_memory = | 656 memory_stats_from_last_assign_.had_enough_memory = |
| 569 had_enough_memory_to_schedule_tiles_needed_now; | 657 had_enough_memory_to_schedule_tiles_needed_now; |
| 570 | 658 |
| 571 raster_priority_queue_.Reset(); | 659 raster_priority_queue_.Reset(); |
| 572 | 660 |
| 573 TRACE_EVENT_END2("cc", | 661 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", |
| 574 "TileManager::AssignGpuMemoryToTiles", | |
| 575 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 662 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
| 576 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 663 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
| 577 "had_enough_memory_to_schedule_tiles_needed_now", | 664 "had_enough_memory_to_schedule_tiles_needed_now", |
| 578 had_enough_memory_to_schedule_tiles_needed_now); | 665 had_enough_memory_to_schedule_tiles_needed_now); |
| 579 } | 666 } |
| 580 | 667 |
| 581 void TileManager::FreeResourcesForTile(Tile* tile) { | 668 void TileManager::FreeResourcesForTile(Tile* tile) { |
| 582 TileDrawInfo& draw_info = tile->draw_info(); | 669 TileDrawInfo& draw_info = tile->draw_info(); |
| 583 if (draw_info.resource_) | 670 if (draw_info.resource_) |
| 584 resource_pool_->ReleaseResource(draw_info.resource_.Pass()); | 671 resource_pool_->ReleaseResource(draw_info.resource_.Pass()); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 } | 802 } |
| 716 | 803 |
| 717 void TileManager::OnRasterTaskCompleted( | 804 void TileManager::OnRasterTaskCompleted( |
| 718 Tile::Id tile_id, | 805 Tile::Id tile_id, |
| 719 scoped_ptr<ScopedResource> resource, | 806 scoped_ptr<ScopedResource> resource, |
| 720 const RasterSource::SolidColorAnalysis& analysis, | 807 const RasterSource::SolidColorAnalysis& analysis, |
| 721 bool was_canceled) { | 808 bool was_canceled) { |
| 722 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 809 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
| 723 | 810 |
| 724 Tile* tile = tiles_[tile_id]; | 811 Tile* tile = tiles_[tile_id]; |
| 725 TileDrawInfo& draw_info = tile->draw_info(); | |
| 726 DCHECK(tile->raster_task_.get()); | 812 DCHECK(tile->raster_task_.get()); |
| 727 orphan_raster_tasks_.push_back(tile->raster_task_); | 813 orphan_raster_tasks_.push_back(tile->raster_task_); |
| 728 tile->raster_task_ = NULL; | 814 tile->raster_task_ = nullptr; |
| 729 | 815 |
| 730 if (was_canceled) { | 816 if (was_canceled) { |
| 731 ++update_visible_tiles_stats_.canceled_count; | 817 ++update_visible_tiles_stats_.canceled_count; |
| 732 resource_pool_->ReleaseResource(resource.Pass()); | 818 resource_pool_->ReleaseResource(resource.Pass()); |
| 733 return; | 819 return; |
| 734 } | 820 } |
| 735 | 821 |
| 822 UpdateTileDrawInfo(tile, resource.Pass(), analysis); |
| 823 } |
| 824 |
| 825 void TileManager::UpdateTileDrawInfo( |
| 826 Tile* tile, |
| 827 scoped_ptr<ScopedResource> resource, |
| 828 const RasterSource::SolidColorAnalysis& analysis) { |
| 829 TileDrawInfo& draw_info = tile->draw_info(); |
| 830 |
| 736 ++update_visible_tiles_stats_.completed_count; | 831 ++update_visible_tiles_stats_.completed_count; |
| 737 | 832 |
| 738 if (analysis.is_solid_color) { | 833 if (analysis.is_solid_color) { |
| 739 draw_info.set_solid_color(analysis.solid_color); | 834 draw_info.set_solid_color(analysis.solid_color); |
| 740 resource_pool_->ReleaseResource(resource.Pass()); | 835 resource_pool_->ReleaseResource(resource.Pass()); |
| 741 } else { | 836 } else { |
| 742 draw_info.set_use_resource(); | 837 draw_info.set_use_resource(); |
| 743 draw_info.resource_ = resource.Pass(); | 838 draw_info.resource_ = resource.Pass(); |
| 744 } | 839 } |
| 745 | 840 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); | 885 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); |
| 791 | 886 |
| 792 for (const auto& layer : layers) { | 887 for (const auto& layer : layers) { |
| 793 if (!layer->AllTilesRequiredForDrawAreReadyToDraw()) | 888 if (!layer->AllTilesRequiredForDrawAreReadyToDraw()) |
| 794 return false; | 889 return false; |
| 795 } | 890 } |
| 796 | 891 |
| 797 return true; | 892 return true; |
| 798 } | 893 } |
| 799 | 894 |
| 895 void TileManager::NotifyReadyToActivate() { |
| 896 TRACE_EVENT0("cc", "TileManager::NotifyReadyToActivate"); |
| 897 if (did_notify_ready_to_activate_) |
| 898 return; |
| 899 client_->NotifyReadyToActivate(); |
| 900 did_notify_ready_to_activate_ = true; |
| 901 } |
| 902 |
| 903 void TileManager::NotifyReadyToDraw() { |
| 904 TRACE_EVENT0("cc", "TileManager::NotifyReadyToDraw"); |
| 905 if (did_notify_ready_to_draw_) |
| 906 return; |
| 907 client_->NotifyReadyToDraw(); |
| 908 did_notify_ready_to_draw_ = true; |
| 909 } |
| 910 |
| 800 void TileManager::CheckIfReadyToActivate() { | 911 void TileManager::CheckIfReadyToActivate() { |
| 801 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 912 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
| 802 | 913 |
| 803 tile_task_runner_->CheckForCompletedTasks(); | 914 tile_task_runner_->CheckForCompletedTasks(); |
| 804 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 915 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 805 | 916 |
| 806 if (did_notify_ready_to_activate_) | 917 if (did_notify_ready_to_activate_) |
| 807 return; | 918 return; |
| 808 if (!IsReadyToActivate()) | 919 if (!IsReadyToActivate()) |
| 809 return; | 920 return; |
| 810 | 921 |
| 811 client_->NotifyReadyToActivate(); | 922 NotifyReadyToActivate(); |
| 812 did_notify_ready_to_activate_ = true; | |
| 813 } | 923 } |
| 814 | 924 |
| 815 void TileManager::CheckIfReadyToDraw() { | 925 void TileManager::CheckIfReadyToDraw() { |
| 816 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToDraw"); | 926 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToDraw"); |
| 817 | 927 |
| 818 tile_task_runner_->CheckForCompletedTasks(); | 928 tile_task_runner_->CheckForCompletedTasks(); |
| 819 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 929 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 820 | 930 |
| 821 if (did_notify_ready_to_draw_) | 931 if (did_notify_ready_to_draw_) |
| 822 return; | 932 return; |
| 823 if (!IsReadyToDraw()) | 933 if (!IsReadyToDraw()) |
| 824 return; | 934 return; |
| 825 | 935 |
| 826 client_->NotifyReadyToDraw(); | 936 NotifyReadyToDraw(); |
| 827 did_notify_ready_to_draw_ = true; | |
| 828 } | 937 } |
| 829 | 938 |
| 830 void TileManager::CheckIfMoreTilesNeedToBePrepared() { | 939 void TileManager::CheckIfMoreTilesNeedToBePrepared() { |
| 831 tile_task_runner_->CheckForCompletedTasks(); | 940 tile_task_runner_->CheckForCompletedTasks(); |
| 832 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 941 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 833 | 942 |
| 834 // When OOM, keep re-assigning memory until we reach a steady state | 943 // When OOM, keep re-assigning memory until we reach a steady state |
| 835 // where top-priority tiles are initialized. | 944 // where top-priority tiles are initialized. |
| 836 TileVector tiles_that_need_to_be_rasterized; | 945 TileVector tiles_that_need_to_be_rasterized; |
| 837 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); | 946 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 947 scheduled_raster_task_limit_); |
| 838 | 948 |
| 839 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 949 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 840 // steady memory state. Keep scheduling tasks until we reach this state. | 950 // steady memory state. Keep scheduling tasks until we reach this state. |
| 841 if (!tiles_that_need_to_be_rasterized.empty()) { | 951 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 842 ScheduleTasks(tiles_that_need_to_be_rasterized); | 952 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 843 return; | 953 return; |
| 844 } | 954 } |
| 845 | 955 |
| 846 FreeResourcesForReleasedTiles(); | 956 FreeResourcesForReleasedTiles(); |
| 847 | 957 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 result -= other; | 1042 result -= other; |
| 933 return result; | 1043 return result; |
| 934 } | 1044 } |
| 935 | 1045 |
| 936 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1046 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 937 return memory_bytes_ > limit.memory_bytes_ || | 1047 return memory_bytes_ > limit.memory_bytes_ || |
| 938 resource_count_ > limit.resource_count_; | 1048 resource_count_ > limit.resource_count_; |
| 939 } | 1049 } |
| 940 | 1050 |
| 941 } // namespace cc | 1051 } // namespace cc |
| OLD | NEW |