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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 | 419 |
| 420 scoped_ptr<RasterTilePriorityQueue> required_for_draw_queue( | 420 scoped_ptr<RasterTilePriorityQueue> required_for_draw_queue( |
| 421 client_->BuildRasterQueue( | 421 client_->BuildRasterQueue( |
| 422 global_state_.tree_priority, | 422 global_state_.tree_priority, |
| 423 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW)); | 423 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW)); |
| 424 TileVector tiles_that_need_to_be_rasterized; | 424 TileVector tiles_that_need_to_be_rasterized; |
| 425 AssignGpuMemoryToTiles(required_for_draw_queue.get(), | 425 AssignGpuMemoryToTiles(required_for_draw_queue.get(), |
| 426 std::numeric_limits<size_t>::max(), | 426 std::numeric_limits<size_t>::max(), |
| 427 &tiles_that_need_to_be_rasterized); | 427 &tiles_that_need_to_be_rasterized); |
| 428 | 428 |
| 429 // Since we are synchronously rasterizing all tiles, we don't require further | |
| 430 // draws for that. Set the flag to false so that we can clear it if it was set | |
| 431 // earlier by PrepareTiles. | |
| 432 client_->SetIsLikelyToRequireADraw(false); | |
|
vmpstr
2015/03/27 17:23:28
Just FYI, this function is kind of slated for remo
sunnyps
2015/03/27 18:38:04
Yeah, would be nice to keep the test while it's al
| |
| 433 | |
| 429 // We must reduce the amount of unused resources before calling | 434 // We must reduce the amount of unused resources before calling |
| 430 // RunTasks to prevent usage from rising above limits. | 435 // RunTasks to prevent usage from rising above limits. |
| 431 resource_pool_->ReduceResourceUsage(); | 436 resource_pool_->ReduceResourceUsage(); |
| 432 | 437 |
| 433 // Run and complete all raster task synchronously. | 438 // Run and complete all raster task synchronously. |
| 434 rasterizer_->RasterizeTiles( | 439 rasterizer_->RasterizeTiles( |
| 435 tiles_that_need_to_be_rasterized, resource_pool_, | 440 tiles_that_need_to_be_rasterized, resource_pool_, |
| 436 tile_task_runner_->GetResourceFormat(), | 441 tile_task_runner_->GetResourceFormat(), |
| 437 base::Bind(&TileManager::UpdateTileDrawInfo, base::Unretained(this))); | 442 base::Bind(&TileManager::UpdateTileDrawInfo, base::Unretained(this))); |
| 438 | 443 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 used_layer_counts_[tile->layer_id()]++; | 874 used_layer_counts_[tile->layer_id()]++; |
| 870 return tile; | 875 return tile; |
| 871 } | 876 } |
| 872 | 877 |
| 873 void TileManager::SetTileTaskRunnerForTesting( | 878 void TileManager::SetTileTaskRunnerForTesting( |
| 874 TileTaskRunner* tile_task_runner) { | 879 TileTaskRunner* tile_task_runner) { |
| 875 tile_task_runner_ = tile_task_runner; | 880 tile_task_runner_ = tile_task_runner; |
| 876 tile_task_runner_->SetClient(this); | 881 tile_task_runner_->SetClient(this); |
| 877 } | 882 } |
| 878 | 883 |
| 884 void TileManager::CheckIfMoreTilesNeedToBePreparedForTesting() { | |
| 885 CheckIfMoreTilesNeedToBePrepared(); | |
|
vmpstr
2015/03/27 17:23:28
Feel free to inline this. (We don't typically impl
sunnyps
2015/03/27 18:38:04
Done.
| |
| 886 } | |
| 887 | |
| 879 bool TileManager::AreRequiredTilesReadyToDraw( | 888 bool TileManager::AreRequiredTilesReadyToDraw( |
| 880 RasterTilePriorityQueue::Type type) const { | 889 RasterTilePriorityQueue::Type type) const { |
| 881 scoped_ptr<RasterTilePriorityQueue> raster_priority_queue( | 890 scoped_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 882 client_->BuildRasterQueue(global_state_.tree_priority, type)); | 891 client_->BuildRasterQueue(global_state_.tree_priority, type)); |
| 883 // It is insufficient to check whether the raster queue we constructed is | 892 // It is insufficient to check whether the raster queue we constructed is |
| 884 // empty. The reason for this is that there are situations (rasterize on | 893 // empty. The reason for this is that there are situations (rasterize on |
| 885 // demand) when the tile both needs raster and it's ready to draw. Hence, we | 894 // demand) when the tile both needs raster and it's ready to draw. Hence, we |
| 886 // have to iterate the queue to check whether the required tiles are ready to | 895 // have to iterate the queue to check whether the required tiles are ready to |
| 887 // draw. | 896 // draw. |
| 888 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | 897 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 949 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 941 | 950 |
| 942 if (did_notify_ready_to_draw_) | 951 if (did_notify_ready_to_draw_) |
| 943 return; | 952 return; |
| 944 if (!IsReadyToDraw()) | 953 if (!IsReadyToDraw()) |
| 945 return; | 954 return; |
| 946 | 955 |
| 947 NotifyReadyToDraw(); | 956 NotifyReadyToDraw(); |
| 948 } | 957 } |
| 949 | 958 |
| 950 void TileManager::CheckIfMoreTilesNeedToBePrepared() { | 959 void TileManager::CheckIfMoreTilesNeedToBePrepared() { |
|
vmpstr
2015/03/27 17:23:28
Kind of thinking out loud, but this function and P
sunnyps
2015/03/27 18:38:04
Acknowledged.
| |
| 951 tile_task_runner_->CheckForCompletedTasks(); | 960 tile_task_runner_->CheckForCompletedTasks(); |
| 952 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 961 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 953 | 962 |
| 954 // When OOM, keep re-assigning memory until we reach a steady state | 963 // When OOM, keep re-assigning memory until we reach a steady state |
| 955 // where top-priority tiles are initialized. | 964 // where top-priority tiles are initialized. |
| 956 TileVector tiles_that_need_to_be_rasterized; | 965 TileVector tiles_that_need_to_be_rasterized; |
| 957 scoped_ptr<RasterTilePriorityQueue> raster_priority_queue( | 966 scoped_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 958 client_->BuildRasterQueue(global_state_.tree_priority, | 967 client_->BuildRasterQueue(global_state_.tree_priority, |
| 959 RasterTilePriorityQueue::Type::ALL)); | 968 RasterTilePriorityQueue::Type::ALL)); |
| 960 AssignGpuMemoryToTiles(raster_priority_queue.get(), | 969 AssignGpuMemoryToTiles(raster_priority_queue.get(), |
| 961 scheduled_raster_task_limit_, | 970 scheduled_raster_task_limit_, |
| 962 &tiles_that_need_to_be_rasterized); | 971 &tiles_that_need_to_be_rasterized); |
| 963 | 972 |
| 973 // Inform the client that will likely require a draw if the highest priority | |
| 974 // tile that will be rasterized is required for draw. | |
| 975 client_->SetIsLikelyToRequireADraw( | |
| 976 !tiles_that_need_to_be_rasterized.empty() && | |
| 977 (*tiles_that_need_to_be_rasterized.begin())->required_for_draw()); | |
| 978 | |
| 964 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 979 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 965 // steady memory state. Keep scheduling tasks until we reach this state. | 980 // steady memory state. Keep scheduling tasks until we reach this state. |
| 966 if (!tiles_that_need_to_be_rasterized.empty()) { | 981 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 967 ScheduleTasks(tiles_that_need_to_be_rasterized); | 982 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 968 return; | 983 return; |
| 969 } | 984 } |
| 970 | 985 |
| 971 FreeResourcesForReleasedTiles(); | 986 FreeResourcesForReleasedTiles(); |
| 972 | 987 |
| 973 resource_pool_->ReduceResourceUsage(); | 988 resource_pool_->ReduceResourceUsage(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1053 result -= other; | 1068 result -= other; |
| 1054 return result; | 1069 return result; |
| 1055 } | 1070 } |
| 1056 | 1071 |
| 1057 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1072 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 1058 return memory_bytes_ > limit.memory_bytes_ || | 1073 return memory_bytes_ > limit.memory_bytes_ || |
| 1059 resource_count_ > limit.resource_count_; | 1074 resource_count_ > limit.resource_count_; |
| 1060 } | 1075 } |
| 1061 | 1076 |
| 1062 } // namespace cc | 1077 } // namespace cc |
| OLD | NEW |