| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 411 |
| 412 // We must reduce the amount of unused resources before calling | 412 // We must reduce the amount of unused resources before calling |
| 413 // RunTasks to prevent usage from rising above limits. | 413 // RunTasks to prevent usage from rising above limits. |
| 414 resource_pool_->ReduceResourceUsage(); | 414 resource_pool_->ReduceResourceUsage(); |
| 415 | 415 |
| 416 // Run and complete all raster task synchronously. | 416 // Run and complete all raster task synchronously. |
| 417 rasterizer_->RasterizeTiles( | 417 rasterizer_->RasterizeTiles( |
| 418 tiles_that_need_to_be_rasterized, resource_pool_, | 418 tiles_that_need_to_be_rasterized, resource_pool_, |
| 419 base::Bind(&TileManager::UpdateTileDrawInfo, base::Unretained(this))); | 419 base::Bind(&TileManager::UpdateTileDrawInfo, base::Unretained(this))); |
| 420 | 420 |
| 421 // Use on-demand raster for any required-for-activation tiles that have not | |
| 422 // been been assigned memory after reaching a steady memory state. This | |
| 423 // ensures that we activate even when OOM. Note that we have to rebuilt the | |
| 424 // queue in case the last AssignGpuMemoryToTiles evicted some tiles that would | |
| 425 // otherwise not be picked up by the old raster queue. | |
| 426 client_->BuildRasterQueue(&raster_priority_queue_, | |
| 427 global_state_.tree_priority); | |
| 428 | |
| 429 // Use on-demand raster for any tiles that have not been been assigned | |
| 430 // memory. This ensures that we draw even when OOM. | |
| 431 while (!raster_priority_queue_.IsEmpty()) { | |
| 432 Tile* tile = raster_priority_queue_.Top(); | |
| 433 TileDrawInfo& draw_info = tile->draw_info(); | |
| 434 | |
| 435 if (tile->required_for_draw() && !draw_info.IsReadyToDraw()) { | |
| 436 draw_info.set_rasterize_on_demand(); | |
| 437 client_->NotifyTileStateChanged(tile); | |
| 438 } | |
| 439 raster_priority_queue_.Pop(); | |
| 440 } | |
| 441 raster_priority_queue_.Reset(); | |
| 442 | |
| 443 TRACE_EVENT_INSTANT1("cc", "DidRasterize", TRACE_EVENT_SCOPE_THREAD, "state", | 421 TRACE_EVENT_INSTANT1("cc", "DidRasterize", TRACE_EVENT_SCOPE_THREAD, "state", |
| 444 BasicStateAsValue()); | 422 BasicStateAsValue()); |
| 445 | 423 |
| 446 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, | 424 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, |
| 447 resource_pool_->total_memory_usage_bytes() - | 425 resource_pool_->total_memory_usage_bytes() - |
| 448 resource_pool_->acquired_memory_usage_bytes()); | 426 resource_pool_->acquired_memory_usage_bytes()); |
| 449 } | 427 } |
| 450 | 428 |
| 451 void TileManager::UpdateVisibleTiles( | 429 void TileManager::UpdateVisibleTiles( |
| 452 const GlobalStateThatImpactsTilePriority& state) { | 430 const GlobalStateThatImpactsTilePriority& state) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 bool had_enough_memory_to_schedule_tiles_needed_now = true; | 551 bool had_enough_memory_to_schedule_tiles_needed_now = true; |
| 574 | 552 |
| 575 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, | 553 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, |
| 576 global_state_.num_resources_limit); | 554 global_state_.num_resources_limit); |
| 577 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, | 555 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, |
| 578 global_state_.num_resources_limit); | 556 global_state_.num_resources_limit); |
| 579 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), | 557 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), |
| 580 resource_pool_->acquired_resource_count()); | 558 resource_pool_->acquired_resource_count()); |
| 581 | 559 |
| 582 eviction_priority_queue_is_up_to_date_ = false; | 560 eviction_priority_queue_is_up_to_date_ = false; |
| 561 // TODO(vmpstr): Take this as a parameter and have SynchronousRaster build a |
| 562 // REQUIRED_FOR_DRAW queue. |
| 583 client_->BuildRasterQueue(&raster_priority_queue_, | 563 client_->BuildRasterQueue(&raster_priority_queue_, |
| 584 global_state_.tree_priority); | 564 global_state_.tree_priority, |
| 565 RasterTilePriorityQueue::Type::ALL); |
| 585 | 566 |
| 586 while (!raster_priority_queue_.IsEmpty()) { | 567 while (!raster_priority_queue_.IsEmpty()) { |
| 587 Tile* tile = raster_priority_queue_.Top(); | 568 Tile* tile = raster_priority_queue_.Top(); |
| 588 | 569 |
| 589 // TODO(vmpstr): Remove this when the iterator returns the correct tiles | 570 // TODO(vmpstr): Remove this when the iterator returns the correct tiles |
| 590 // to draw for GPU rasterization. | 571 // to draw for GPU rasterization. |
| 591 if (required_for_draw_only) { | 572 if (required_for_draw_only) { |
| 592 if (!tile->required_for_draw()) { | 573 if (!tile->required_for_draw()) { |
| 593 raster_priority_queue_.Pop(); | 574 raster_priority_queue_.Pop(); |
| 594 continue; | 575 continue; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 void TileManager::SetTileTaskRunnerForTesting( | 854 void TileManager::SetTileTaskRunnerForTesting( |
| 874 TileTaskRunner* tile_task_runner) { | 855 TileTaskRunner* tile_task_runner) { |
| 875 tile_task_runner_ = tile_task_runner; | 856 tile_task_runner_ = tile_task_runner; |
| 876 tile_task_runner_->SetClient(this); | 857 tile_task_runner_->SetClient(this); |
| 877 } | 858 } |
| 878 | 859 |
| 879 bool TileManager::IsReadyToActivate() const { | 860 bool TileManager::IsReadyToActivate() const { |
| 880 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); | 861 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); |
| 881 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); | 862 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); |
| 882 | 863 |
| 864 // TODO(vmpstr): Replace this with building a REQUIRED_TO_ACTIVATE raster |
| 865 // queue and checking if it's empty. |
| 883 for (const auto& layer : layers) { | 866 for (const auto& layer : layers) { |
| 884 if (!layer->AllTilesRequiredForActivationAreReadyToDraw()) | 867 if (!layer->AllTilesRequiredForActivationAreReadyToDraw()) |
| 885 return false; | 868 return false; |
| 886 } | 869 } |
| 887 | 870 |
| 888 return true; | 871 return true; |
| 889 } | 872 } |
| 890 | 873 |
| 891 bool TileManager::IsReadyToDraw() const { | 874 bool TileManager::IsReadyToDraw() const { |
| 892 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); | 875 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); |
| 893 | 876 |
| 877 // TODO(vmpstr): Replace this with building a REQUIRED_TO_DRAW raster queue |
| 878 // and checking if it's empty. |
| 894 for (const auto& layer : layers) { | 879 for (const auto& layer : layers) { |
| 895 if (!layer->AllTilesRequiredForDrawAreReadyToDraw()) | 880 if (!layer->AllTilesRequiredForDrawAreReadyToDraw()) |
| 896 return false; | 881 return false; |
| 897 } | 882 } |
| 898 | 883 |
| 899 return true; | 884 return true; |
| 900 } | 885 } |
| 901 | 886 |
| 902 void TileManager::NotifyReadyToActivate() { | 887 void TileManager::NotifyReadyToActivate() { |
| 903 TRACE_EVENT0("cc", "TileManager::NotifyReadyToActivate"); | 888 TRACE_EVENT0("cc", "TileManager::NotifyReadyToActivate"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 // activate as activation can cause checkerboards. | 957 // activate as activation can cause checkerboards. |
| 973 bool allow_rasterize_on_demand = | 958 bool allow_rasterize_on_demand = |
| 974 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY && | 959 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY && |
| 975 global_state_.memory_limit_policy != ALLOW_NOTHING; | 960 global_state_.memory_limit_policy != ALLOW_NOTHING; |
| 976 | 961 |
| 977 // Use on-demand raster for any required-for-activation tiles that have | 962 // Use on-demand raster for any required-for-activation tiles that have |
| 978 // not been been assigned memory after reaching a steady memory state. This | 963 // not been been assigned memory after reaching a steady memory state. This |
| 979 // ensures that we activate even when OOM. Note that we have to rebuilt the | 964 // ensures that we activate even when OOM. Note that we have to rebuilt the |
| 980 // queue in case the last AssignGpuMemoryToTiles evicted some tiles that | 965 // queue in case the last AssignGpuMemoryToTiles evicted some tiles that |
| 981 // would otherwise not be picked up by the old raster queue. | 966 // would otherwise not be picked up by the old raster queue. |
| 967 // TODO(vmpstr): Make this use REQUIRED_FOR_ACTIVAITON queue. |
| 982 client_->BuildRasterQueue(&raster_priority_queue_, | 968 client_->BuildRasterQueue(&raster_priority_queue_, |
| 983 global_state_.tree_priority); | 969 global_state_.tree_priority, |
| 970 RasterTilePriorityQueue::Type::ALL); |
| 984 bool ready_to_activate = true; | 971 bool ready_to_activate = true; |
| 985 while (!raster_priority_queue_.IsEmpty()) { | 972 while (!raster_priority_queue_.IsEmpty()) { |
| 986 Tile* tile = raster_priority_queue_.Top(); | 973 Tile* tile = raster_priority_queue_.Top(); |
| 987 TileDrawInfo& draw_info = tile->draw_info(); | 974 TileDrawInfo& draw_info = tile->draw_info(); |
| 988 | 975 |
| 989 if (tile->required_for_activation() && !draw_info.IsReadyToDraw()) { | 976 if (tile->required_for_activation() && !draw_info.IsReadyToDraw()) { |
| 990 // If we can't raster on demand, give up early (and don't activate). | 977 // If we can't raster on demand, give up early (and don't activate). |
| 991 if (!allow_rasterize_on_demand) { | 978 if (!allow_rasterize_on_demand) { |
| 992 ready_to_activate = false; | 979 ready_to_activate = false; |
| 993 break; | 980 break; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 result -= other; | 1037 result -= other; |
| 1051 return result; | 1038 return result; |
| 1052 } | 1039 } |
| 1053 | 1040 |
| 1054 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1041 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 1055 return memory_bytes_ > limit.memory_bytes_ || | 1042 return memory_bytes_ > limit.memory_bytes_ || |
| 1056 resource_count_ > limit.resource_count_; | 1043 resource_count_ > limit.resource_count_; |
| 1057 } | 1044 } |
| 1058 | 1045 |
| 1059 } // namespace cc | 1046 } // namespace cc |
| OLD | NEW |