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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 base::Bind(&TileManager::UpdateTileDrawInfo, base::Unretained(this))); | 432 base::Bind(&TileManager::UpdateTileDrawInfo, base::Unretained(this))); |
433 | 433 |
434 // Use on-demand raster for any required-for-draw tiles that have not been | 434 // Use on-demand raster for any required-for-draw tiles that have not been |
435 // assigned memory after reaching a steady memory state. | 435 // assigned memory after reaching a steady memory state. |
436 // TODO(hendrikw): Figure out why this would improve jank on some tests - See | 436 // TODO(hendrikw): Figure out why this would improve jank on some tests - See |
437 // crbug.com/449288 | 437 // crbug.com/449288 |
438 required_for_draw_queue = client_->BuildRasterQueue( | 438 required_for_draw_queue = client_->BuildRasterQueue( |
439 global_state_.tree_priority, | 439 global_state_.tree_priority, |
440 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); | 440 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); |
441 | 441 |
442 // Use on-demand raster for any tiles that have not been been assigned | 442 // Change to OOM mode for any tiles that have not been been assigned memory. |
443 // memory. This ensures that we draw even when OOM. | 443 // This ensures that we draw even when OOM. |
444 for (; !required_for_draw_queue->IsEmpty(); required_for_draw_queue->Pop()) { | 444 for (; !required_for_draw_queue->IsEmpty(); required_for_draw_queue->Pop()) { |
445 Tile* tile = required_for_draw_queue->Top(); | 445 Tile* tile = required_for_draw_queue->Top(); |
446 tile->draw_info().set_rasterize_on_demand(); | 446 tile->draw_info().set_oom(); |
447 client_->NotifyTileStateChanged(tile); | 447 client_->NotifyTileStateChanged(tile); |
448 } | 448 } |
449 | 449 |
450 TRACE_EVENT_INSTANT1("cc", "DidRasterize", TRACE_EVENT_SCOPE_THREAD, "state", | 450 TRACE_EVENT_INSTANT1("cc", "DidRasterize", TRACE_EVENT_SCOPE_THREAD, "state", |
451 BasicStateAsValue()); | 451 BasicStateAsValue()); |
452 | 452 |
453 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, | 453 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, |
454 resource_pool_->total_memory_usage_bytes() - | 454 resource_pool_->total_memory_usage_bytes() - |
455 resource_pool_->acquired_memory_usage_bytes()); | 455 resource_pool_->acquired_memory_usage_bytes()); |
456 } | 456 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 // We won't be able to schedule this tile, so break out early. | 597 // We won't be able to schedule this tile, so break out early. |
598 if (tiles_that_need_to_be_rasterized->size() >= | 598 if (tiles_that_need_to_be_rasterized->size() >= |
599 scheduled_raster_task_limit) { | 599 scheduled_raster_task_limit) { |
600 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 600 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
601 break; | 601 break; |
602 } | 602 } |
603 | 603 |
604 TileDrawInfo& draw_info = tile->draw_info(); | 604 TileDrawInfo& draw_info = tile->draw_info(); |
605 tile->scheduled_priority_ = schedule_priority++; | 605 tile->scheduled_priority_ = schedule_priority++; |
606 | 606 |
607 DCHECK(draw_info.mode() == TileDrawInfo::PICTURE_PILE_MODE || | 607 DCHECK_IMPLIES(draw_info.mode() != TileDrawInfo::OOM_MODE, |
608 !draw_info.IsReadyToDraw()); | 608 !draw_info.IsReadyToDraw()); |
609 | 609 |
610 // If the tile already has a raster_task, then the memory used by it is | 610 // If the tile already has a raster_task, then the memory used by it is |
611 // already accounted for in memory_usage. Otherwise, we'll have to acquire | 611 // already accounted for in memory_usage. Otherwise, we'll have to acquire |
612 // more memory to create a raster task. | 612 // more memory to create a raster task. |
613 MemoryUsage memory_required_by_tile_to_be_scheduled; | 613 MemoryUsage memory_required_by_tile_to_be_scheduled; |
614 if (!tile->raster_task_.get()) { | 614 if (!tile->raster_task_.get()) { |
615 memory_required_by_tile_to_be_scheduled = MemoryUsage::FromConfig( | 615 memory_required_by_tile_to_be_scheduled = MemoryUsage::FromConfig( |
616 tile->desired_texture_size(), tile_task_runner_->GetResourceFormat()); | 616 tile->desired_texture_size(), tile_task_runner_->GetResourceFormat()); |
617 } | 617 } |
618 | 618 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 FreeResourcesForReleasedTiles(); | 966 FreeResourcesForReleasedTiles(); |
967 | 967 |
968 resource_pool_->ReduceResourceUsage(); | 968 resource_pool_->ReduceResourceUsage(); |
969 | 969 |
970 // We don't reserve memory for required-for-activation tiles during | 970 // We don't reserve memory for required-for-activation tiles during |
971 // accelerated gestures, so we just postpone activation when we don't | 971 // accelerated gestures, so we just postpone activation when we don't |
972 // have these tiles, and activate after the accelerated gesture. | 972 // have these tiles, and activate after the accelerated gesture. |
973 // Likewise if we don't allow any tiles (as is the case when we're | 973 // Likewise if we don't allow any tiles (as is the case when we're |
974 // invisible), if we have tiles that aren't ready, then we shouldn't | 974 // invisible), if we have tiles that aren't ready, then we shouldn't |
975 // activate as activation can cause checkerboards. | 975 // activate as activation can cause checkerboards. |
976 bool allow_rasterize_on_demand = | 976 bool wait_for_all_required_tiles = |
977 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY && | 977 global_state_.tree_priority == SMOOTHNESS_TAKES_PRIORITY || |
978 global_state_.memory_limit_policy != ALLOW_NOTHING; | 978 global_state_.memory_limit_policy == ALLOW_NOTHING; |
979 | 979 |
980 // Use on-demand raster for any required-for-activation tiles that have | 980 // Mark any required-for-activation tiles that have not been been assigned |
981 // not been been assigned memory after reaching a steady memory state. This | 981 // memory after reaching a steady memory state as OOM. This ensures that we |
982 // ensures that we activate even when OOM. Note that we can't reuse the queue | 982 // activate even when OOM. Note that we can't reuse the queue we used for |
983 // we used for AssignGpuMemoryToTiles, since the AssignGpuMemoryToTiles call | 983 // AssignGpuMemoryToTiles, since the AssignGpuMemoryToTiles call could have |
984 // could have evicted some tiles that would not be picked up by the old raster | 984 // evicted some tiles that would not be picked up by the old raster queue. |
985 // queue. | |
986 scoped_ptr<RasterTilePriorityQueue> required_for_activation_queue( | 985 scoped_ptr<RasterTilePriorityQueue> required_for_activation_queue( |
987 client_->BuildRasterQueue( | 986 client_->BuildRasterQueue( |
988 global_state_.tree_priority, | 987 global_state_.tree_priority, |
989 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); | 988 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); |
990 | 989 |
991 // If we have tiles to mark as rasterize on demand, but we don't allow | 990 // If we have tiles left to raster for activation, and we don't allow |
992 // rasterize on demand, then skip activation and return early. | 991 // activating without them, then skip activation and return early. |
993 if (!required_for_activation_queue->IsEmpty() && !allow_rasterize_on_demand) | 992 if (!required_for_activation_queue->IsEmpty() && wait_for_all_required_tiles) |
994 return; | 993 return; |
995 | 994 |
996 // Mark required tiles as rasterize on demand. | 995 // Mark required tiles as OOM so that we can activate without them. |
997 for (; !required_for_activation_queue->IsEmpty(); | 996 for (; !required_for_activation_queue->IsEmpty(); |
998 required_for_activation_queue->Pop()) { | 997 required_for_activation_queue->Pop()) { |
999 Tile* tile = required_for_activation_queue->Top(); | 998 Tile* tile = required_for_activation_queue->Top(); |
1000 tile->draw_info().set_rasterize_on_demand(); | 999 tile->draw_info().set_oom(); |
1001 client_->NotifyTileStateChanged(tile); | 1000 client_->NotifyTileStateChanged(tile); |
1002 } | 1001 } |
1003 | 1002 |
1004 DCHECK(IsReadyToActivate()); | 1003 DCHECK(IsReadyToActivate()); |
1005 ready_to_activate_check_notifier_.Schedule(); | 1004 ready_to_activate_check_notifier_.Schedule(); |
1006 } | 1005 } |
1007 | 1006 |
1008 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { | 1007 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { |
1009 } | 1008 } |
1010 | 1009 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 result -= other; | 1048 result -= other; |
1050 return result; | 1049 return result; |
1051 } | 1050 } |
1052 | 1051 |
1053 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1052 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
1054 return memory_bytes_ > limit.memory_bytes_ || | 1053 return memory_bytes_ > limit.memory_bytes_ || |
1055 resource_count_ > limit.resource_count_; | 1054 resource_count_ > limit.resource_count_; |
1056 } | 1055 } |
1057 | 1056 |
1058 } // namespace cc | 1057 } // namespace cc |
OLD | NEW |