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/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 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 const RasterTaskCompletionStats& stats) { | 359 const RasterTaskCompletionStats& stats) { |
| 360 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 360 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 361 state->SetInteger("completed_count", stats.completed_count); | 361 state->SetInteger("completed_count", stats.completed_count); |
| 362 state->SetInteger("canceled_count", stats.canceled_count); | 362 state->SetInteger("canceled_count", stats.canceled_count); |
| 363 return state.PassAs<base::Value>(); | 363 return state.PassAs<base::Value>(); |
| 364 } | 364 } |
| 365 | 365 |
| 366 // static | 366 // static |
| 367 scoped_ptr<TileManager> TileManager::Create( | 367 scoped_ptr<TileManager> TileManager::Create( |
| 368 TileManagerClient* client, | 368 TileManagerClient* client, |
| 369 base::SequencedTaskRunner* task_runner, | |
| 369 ResourcePool* resource_pool, | 370 ResourcePool* resource_pool, |
| 370 Rasterizer* rasterizer, | 371 Rasterizer* rasterizer, |
| 371 Rasterizer* gpu_rasterizer, | 372 Rasterizer* gpu_rasterizer, |
| 372 bool use_rasterize_on_demand, | |
| 373 RenderingStatsInstrumentation* rendering_stats_instrumentation) { | 373 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
| 374 return make_scoped_ptr(new TileManager(client, | 374 return make_scoped_ptr(new TileManager(client, |
| 375 task_runner, | |
| 375 resource_pool, | 376 resource_pool, |
| 376 rasterizer, | 377 rasterizer, |
| 377 gpu_rasterizer, | 378 gpu_rasterizer, |
| 378 use_rasterize_on_demand, | |
| 379 rendering_stats_instrumentation)); | 379 rendering_stats_instrumentation)); |
| 380 } | 380 } |
| 381 | 381 |
| 382 TileManager::TileManager( | 382 TileManager::TileManager( |
| 383 TileManagerClient* client, | 383 TileManagerClient* client, |
| 384 base::SequencedTaskRunner* task_runner, | |
| 384 ResourcePool* resource_pool, | 385 ResourcePool* resource_pool, |
| 385 Rasterizer* rasterizer, | 386 Rasterizer* rasterizer, |
| 386 Rasterizer* gpu_rasterizer, | 387 Rasterizer* gpu_rasterizer, |
| 387 bool use_rasterize_on_demand, | |
| 388 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 388 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 389 : client_(client), | 389 : client_(client), |
| 390 task_runner_(task_runner), | |
| 390 resource_pool_(resource_pool), | 391 resource_pool_(resource_pool), |
| 391 prioritized_tiles_dirty_(false), | 392 prioritized_tiles_dirty_(false), |
| 392 all_tiles_that_need_to_be_rasterized_have_memory_(true), | 393 all_tiles_that_need_to_be_rasterized_have_memory_(true), |
| 393 all_tiles_required_for_activation_have_memory_(true), | 394 all_tiles_required_for_activation_have_memory_(true), |
| 394 memory_required_bytes_(0), | 395 memory_required_bytes_(0), |
| 395 memory_nice_to_have_bytes_(0), | 396 memory_nice_to_have_bytes_(0), |
| 396 bytes_releasable_(0), | 397 bytes_releasable_(0), |
| 397 resources_releasable_(0), | 398 resources_releasable_(0), |
| 398 ever_exceeded_memory_budget_(false), | 399 ever_exceeded_memory_budget_(false), |
| 399 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 400 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 400 did_initialize_visible_tile_(false), | 401 did_initialize_visible_tile_(false), |
| 401 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 402 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 402 use_rasterize_on_demand_(use_rasterize_on_demand) { | 403 check_if_ready_to_activate_pending_(false), |
| 404 weak_ptr_factory_(this) { | |
| 403 Rasterizer* rasterizers[NUM_RASTERIZER_TYPES] = { | 405 Rasterizer* rasterizers[NUM_RASTERIZER_TYPES] = { |
| 404 rasterizer, // RASTERIZER_TYPE_DEFAULT | 406 rasterizer, // RASTERIZER_TYPE_DEFAULT |
| 405 gpu_rasterizer, // RASTERIZER_TYPE_GPU | 407 gpu_rasterizer, // RASTERIZER_TYPE_GPU |
| 406 }; | 408 }; |
| 407 rasterizer_delegate_ = | 409 rasterizer_delegate_ = |
| 408 RasterizerDelegate::Create(this, rasterizers, arraysize(rasterizers)); | 410 RasterizerDelegate::Create(this, rasterizers, arraysize(rasterizers)); |
| 409 } | 411 } |
| 410 | 412 |
| 411 TileManager::~TileManager() { | 413 TileManager::~TileManager() { |
| 412 // Reset global state and manage. This should cause | 414 // Reset global state and manage. This should cause |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 531 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 530 Tile* tile = it->second; | 532 Tile* tile = it->second; |
| 531 ManagedTileState& mts = tile->managed_state(); | 533 ManagedTileState& mts = tile->managed_state(); |
| 532 ManagedTileState::TileVersion& tile_version = | 534 ManagedTileState::TileVersion& tile_version = |
| 533 mts.tile_versions[mts.raster_mode]; | 535 mts.tile_versions[mts.raster_mode]; |
| 534 | 536 |
| 535 if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) { | 537 if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) { |
| 536 // If we can't raster on demand, give up early (and don't activate). | 538 // If we can't raster on demand, give up early (and don't activate). |
| 537 if (!allow_rasterize_on_demand) | 539 if (!allow_rasterize_on_demand) |
| 538 return; | 540 return; |
| 539 if (use_rasterize_on_demand_) | 541 |
| 540 tile_version.set_rasterize_on_demand(); | 542 tile_version.set_rasterize_on_demand(); |
| 543 client_->NotifyTileInitialized(tile); | |
|
vmpstr
2014/05/15 17:46:23
This means that we might end up calling NotifyTile
reveman
2014/05/15 19:01:43
That's already the case as we have multiple tile v
vmpstr
2014/05/16 00:38:45
Fair enough. I agree that with versions it should
| |
| 541 } | 544 } |
| 542 } | 545 } |
| 543 | 546 |
| 544 client_->NotifyReadyToActivate(); | 547 DCHECK(IsReadyToActivate()); |
| 548 ScheduleCheckIfReadyToActivate(); | |
| 545 } | 549 } |
| 546 | 550 |
| 547 void TileManager::DidFinishRunningTasksRequiredForActivation() { | 551 void TileManager::DidFinishRunningTasksRequiredForActivation() { |
| 548 // This is only a true indication that all tiles required for | 552 // This is only a true indication that all tiles required for |
| 549 // activation are initialized when no tiles are OOM. We need to | 553 // activation are initialized when no tiles are OOM. We need to |
| 550 // wait for DidFinishRunningTasks() to be called, try to re-assign | 554 // wait for DidFinishRunningTasks() to be called, try to re-assign |
| 551 // memory and in worst case use on-demand raster when tiles | 555 // memory and in worst case use on-demand raster when tiles |
| 552 // required for activation are OOM. | 556 // required for activation are OOM. |
| 553 if (!all_tiles_required_for_activation_have_memory_) | 557 if (!all_tiles_required_for_activation_have_memory_) |
| 554 return; | 558 return; |
| 555 | 559 |
| 556 client_->NotifyReadyToActivate(); | 560 ScheduleCheckIfReadyToActivate(); |
| 557 } | 561 } |
| 558 | 562 |
| 559 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { | 563 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { |
| 560 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); | 564 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); |
| 561 | 565 |
| 562 // Compute new stats to be return by GetMemoryStats(). | 566 // Compute new stats to be return by GetMemoryStats(). |
| 563 memory_required_bytes_ = 0; | 567 memory_required_bytes_ = 0; |
| 564 memory_nice_to_have_bytes_ = 0; | 568 memory_nice_to_have_bytes_ = 0; |
| 565 | 569 |
| 566 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; | 570 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 } | 887 } |
| 884 } | 888 } |
| 885 | 889 |
| 886 // Tile is OOM. | 890 // Tile is OOM. |
| 887 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | 891 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { |
| 888 FreeResourcesForTile(tile); | 892 FreeResourcesForTile(tile); |
| 889 | 893 |
| 890 // This tile was already on screen and now its resources have been | 894 // This tile was already on screen and now its resources have been |
| 891 // released. In order to prevent checkerboarding, set this tile as | 895 // released. In order to prevent checkerboarding, set this tile as |
| 892 // rasterize on demand immediately. | 896 // rasterize on demand immediately. |
| 893 if (mts.visible_and_ready_to_draw && use_rasterize_on_demand_) | 897 if (mts.visible_and_ready_to_draw) |
|
vmpstr
2014/05/15 17:46:23
Why this change?
reveman
2014/05/15 19:01:43
We can't handle situations where the renderer does
vmpstr
2014/05/16 00:38:45
I don't follow. This part was there to prevent us
reveman
2014/05/16 16:50:13
This patch just moves the awareness of support for
vmpstr
2014/05/16 17:09:06
Oh, I missed the bit where it's handled in AppendQ
| |
| 894 tile_version.set_rasterize_on_demand(); | 898 tile_version.set_rasterize_on_demand(); |
| 895 | 899 |
| 896 oomed_soft = true; | 900 oomed_soft = true; |
| 897 if (tile_uses_hard_limit) { | 901 if (tile_uses_hard_limit) { |
| 898 oomed_hard = true; | 902 oomed_hard = true; |
| 899 bytes_that_exceeded_memory_budget += tile_bytes; | 903 bytes_that_exceeded_memory_budget += tile_bytes; |
| 900 } | 904 } |
| 901 } else { | 905 } else { |
| 902 resources_left -= tile_resources; | 906 resources_left -= tile_resources; |
| 903 hard_bytes_left -= tile_bytes; | 907 hard_bytes_left -= tile_bytes; |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1609 bool prioritize_low_res = tree_priority_ != SMOOTHNESS_TAKES_PRIORITY; | 1613 bool prioritize_low_res = tree_priority_ != SMOOTHNESS_TAKES_PRIORITY; |
| 1610 | 1614 |
| 1611 if (b_priority.resolution != a_priority.resolution) { | 1615 if (b_priority.resolution != a_priority.resolution) { |
| 1612 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || | 1616 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || |
| 1613 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || | 1617 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || |
| 1614 (a_priority.resolution == NON_IDEAL_RESOLUTION); | 1618 (a_priority.resolution == NON_IDEAL_RESOLUTION); |
| 1615 } | 1619 } |
| 1616 return a_priority.IsHigherPriorityThan(b_priority); | 1620 return a_priority.IsHigherPriorityThan(b_priority); |
| 1617 } | 1621 } |
| 1618 | 1622 |
| 1623 bool TileManager::IsReadyToActivate() const { | |
| 1624 for (std::vector<PictureLayerImpl*>::const_iterator it = layers_.begin(); | |
|
vmpstr
2014/05/16 00:38:45
This is probably dependent on my patch that clears
reveman
2014/05/16 16:50:13
Yes, we should hold off on this until that lands.
| |
| 1625 it != layers_.end(); | |
| 1626 ++it) { | |
| 1627 if (!(*it)->AllTilesRequiredForActivationAreReadyToDraw()) | |
| 1628 return false; | |
| 1629 } | |
| 1630 | |
| 1631 return true; | |
| 1632 } | |
| 1633 | |
| 1634 void TileManager::ScheduleCheckIfReadyToActivate() { | |
| 1635 if (check_if_ready_to_activate_pending_) | |
|
vmpstr
2014/05/16 00:38:45
As an aside, this pattern seems to be in a few pla
reveman
2014/05/16 16:50:13
Yes, that would be nice and we can probably bake t
| |
| 1636 return; | |
| 1637 | |
| 1638 task_runner_->PostTask(FROM_HERE, | |
| 1639 base::Bind(&TileManager::CheckIfReadyToActivate, | |
| 1640 weak_ptr_factory_.GetWeakPtr())); | |
| 1641 check_if_ready_to_activate_pending_ = true; | |
| 1642 } | |
| 1643 | |
| 1644 void TileManager::CheckIfReadyToActivate() { | |
| 1645 DCHECK(check_if_ready_to_activate_pending_); | |
| 1646 check_if_ready_to_activate_pending_ = false; | |
| 1647 | |
| 1648 rasterizer_delegate_->CheckForCompletedTasks(); | |
| 1649 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | |
| 1650 | |
| 1651 if (IsReadyToActivate()) | |
| 1652 client_->NotifyReadyToActivate(); | |
| 1653 } | |
| 1654 | |
| 1619 } // namespace cc | 1655 } // namespace cc |
| OLD | NEW |