| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 357 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 358 tile_task_runner_->CheckForCompletedTasks(); | 358 tile_task_runner_->CheckForCompletedTasks(); |
| 359 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 359 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 360 } | 360 } |
| 361 | 361 |
| 362 FreeResourcesForReleasedTiles(); | 362 FreeResourcesForReleasedTiles(); |
| 363 CleanUpReleasedTiles(); | 363 CleanUpReleasedTiles(); |
| 364 | 364 |
| 365 TileVector tiles_that_need_to_be_rasterized; | 365 TileVector tiles_that_need_to_be_rasterized; |
| 366 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, | 366 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 367 scheduled_raster_task_limit_); | 367 scheduled_raster_task_limit_, false); |
| 368 | 368 |
| 369 // Schedule tile tasks. | 369 // Schedule tile tasks. |
| 370 ScheduleTasks(tiles_that_need_to_be_rasterized); | 370 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 371 | 371 |
| 372 did_notify_ready_to_activate_ = false; | 372 did_notify_ready_to_activate_ = false; |
| 373 did_notify_ready_to_draw_ = false; | 373 did_notify_ready_to_draw_ = false; |
| 374 } else { | 374 } else { |
| 375 if (global_state_.hard_memory_limit_in_bytes == 0) { | 375 if (global_state_.hard_memory_limit_in_bytes == 0) { |
| 376 TileVector tiles_that_need_to_be_rasterized; | 376 TileVector tiles_that_need_to_be_rasterized; |
| 377 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, | 377 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 378 scheduled_raster_task_limit_); | 378 scheduled_raster_task_limit_, false); |
| 379 DCHECK(tiles_that_need_to_be_rasterized.empty()); | 379 DCHECK(tiles_that_need_to_be_rasterized.empty()); |
| 380 } | 380 } |
| 381 | 381 |
| 382 did_notify_ready_to_activate_ = false; | 382 did_notify_ready_to_activate_ = false; |
| 383 did_notify_ready_to_draw_ = false; | 383 did_notify_ready_to_draw_ = false; |
| 384 ready_to_activate_notifier_.Schedule(); | 384 ready_to_activate_notifier_.Schedule(); |
| 385 ready_to_draw_notifier_.Schedule(); | 385 ready_to_draw_notifier_.Schedule(); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, | 388 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 400 DCHECK(rasterizer_->GetPrepareTilesMode() != | 400 DCHECK(rasterizer_->GetPrepareTilesMode() != |
| 401 PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES); | 401 PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES); |
| 402 | 402 |
| 403 global_state_ = state; | 403 global_state_ = state; |
| 404 | 404 |
| 405 FreeResourcesForReleasedTiles(); | 405 FreeResourcesForReleasedTiles(); |
| 406 CleanUpReleasedTiles(); | 406 CleanUpReleasedTiles(); |
| 407 | 407 |
| 408 TileVector tiles_that_need_to_be_rasterized; | 408 TileVector tiles_that_need_to_be_rasterized; |
| 409 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, | 409 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 410 std::numeric_limits<size_t>::max()); | 410 std::numeric_limits<size_t>::max(), true); |
| 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 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 case ALLOW_ANYTHING: | 548 case ALLOW_ANYTHING: |
| 549 return priority.distance_to_visible == | 549 return priority.distance_to_visible == |
| 550 std::numeric_limits<float>::infinity(); | 550 std::numeric_limits<float>::infinity(); |
| 551 } | 551 } |
| 552 NOTREACHED(); | 552 NOTREACHED(); |
| 553 return true; | 553 return true; |
| 554 } | 554 } |
| 555 | 555 |
| 556 void TileManager::AssignGpuMemoryToTiles( | 556 void TileManager::AssignGpuMemoryToTiles( |
| 557 TileVector* tiles_that_need_to_be_rasterized, | 557 TileVector* tiles_that_need_to_be_rasterized, |
| 558 size_t scheduled_raster_task_limit) { | 558 size_t scheduled_raster_task_limit, |
| 559 bool required_for_draw_only) { |
| 559 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); | 560 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 560 | 561 |
| 561 // Maintain the list of released resources that can potentially be re-used | 562 // Maintain the list of released resources that can potentially be re-used |
| 562 // or deleted. | 563 // or deleted. |
| 563 // If this operation becomes expensive too, only do this after some | 564 // If this operation becomes expensive too, only do this after some |
| 564 // resource(s) was returned. Note that in that case, one also need to | 565 // resource(s) was returned. Note that in that case, one also need to |
| 565 // invalidate when releasing some resource from the pool. | 566 // invalidate when releasing some resource from the pool. |
| 566 resource_pool_->CheckBusyResources(false); | 567 resource_pool_->CheckBusyResources(false); |
| 567 | 568 |
| 568 // Now give memory out to the tiles until we're out, and build | 569 // Now give memory out to the tiles until we're out, and build |
| 569 // the needs-to-be-rasterized queue. | 570 // the needs-to-be-rasterized queue. |
| 570 unsigned schedule_priority = 1u; | 571 unsigned schedule_priority = 1u; |
| 571 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true; | 572 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true; |
| 572 bool had_enough_memory_to_schedule_tiles_needed_now = true; | 573 bool had_enough_memory_to_schedule_tiles_needed_now = true; |
| 573 | 574 |
| 574 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, | 575 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, |
| 575 global_state_.num_resources_limit); | 576 global_state_.num_resources_limit); |
| 576 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, | 577 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, |
| 577 global_state_.num_resources_limit); | 578 global_state_.num_resources_limit); |
| 578 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), | 579 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), |
| 579 resource_pool_->acquired_resource_count()); | 580 resource_pool_->acquired_resource_count()); |
| 580 | 581 |
| 581 eviction_priority_queue_is_up_to_date_ = false; | 582 eviction_priority_queue_is_up_to_date_ = false; |
| 582 client_->BuildRasterQueue(&raster_priority_queue_, | 583 client_->BuildRasterQueue(&raster_priority_queue_, |
| 583 global_state_.tree_priority); | 584 global_state_.tree_priority); |
| 584 | 585 |
| 585 while (!raster_priority_queue_.IsEmpty()) { | 586 while (!raster_priority_queue_.IsEmpty()) { |
| 586 Tile* tile = raster_priority_queue_.Top(); | 587 Tile* tile = raster_priority_queue_.Top(); |
| 588 |
| 589 // TODO(vmpstr): Remove this when the iterator returns the correct tiles |
| 590 // to draw for GPU rasterization. |
| 591 if (required_for_draw_only) { |
| 592 if (!tile->required_for_draw()) { |
| 593 raster_priority_queue_.Pop(); |
| 594 continue; |
| 595 } |
| 596 } |
| 587 TilePriority priority = tile->combined_priority(); | 597 TilePriority priority = tile->combined_priority(); |
| 588 | 598 |
| 589 if (TilePriorityViolatesMemoryPolicy(priority)) { | 599 if (TilePriorityViolatesMemoryPolicy(priority)) { |
| 590 TRACE_EVENT_INSTANT0( | 600 TRACE_EVENT_INSTANT0( |
| 591 "cc", "TileManager::AssignGpuMemory tile violates memory policy", | 601 "cc", "TileManager::AssignGpuMemory tile violates memory policy", |
| 592 TRACE_EVENT_SCOPE_THREAD); | 602 TRACE_EVENT_SCOPE_THREAD); |
| 593 break; | 603 break; |
| 594 } | 604 } |
| 595 | 605 |
| 596 // We won't be able to schedule this tile, so break out early. | 606 // We won't be able to schedule this tile, so break out early. |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 } | 944 } |
| 935 | 945 |
| 936 void TileManager::CheckIfMoreTilesNeedToBePrepared() { | 946 void TileManager::CheckIfMoreTilesNeedToBePrepared() { |
| 937 tile_task_runner_->CheckForCompletedTasks(); | 947 tile_task_runner_->CheckForCompletedTasks(); |
| 938 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 948 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 939 | 949 |
| 940 // When OOM, keep re-assigning memory until we reach a steady state | 950 // When OOM, keep re-assigning memory until we reach a steady state |
| 941 // where top-priority tiles are initialized. | 951 // where top-priority tiles are initialized. |
| 942 TileVector tiles_that_need_to_be_rasterized; | 952 TileVector tiles_that_need_to_be_rasterized; |
| 943 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, | 953 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized, |
| 944 scheduled_raster_task_limit_); | 954 scheduled_raster_task_limit_, false); |
| 945 | 955 |
| 946 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 956 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 947 // steady memory state. Keep scheduling tasks until we reach this state. | 957 // steady memory state. Keep scheduling tasks until we reach this state. |
| 948 if (!tiles_that_need_to_be_rasterized.empty()) { | 958 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 949 ScheduleTasks(tiles_that_need_to_be_rasterized); | 959 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 950 return; | 960 return; |
| 951 } | 961 } |
| 952 | 962 |
| 953 FreeResourcesForReleasedTiles(); | 963 FreeResourcesForReleasedTiles(); |
| 954 | 964 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 result -= other; | 1050 result -= other; |
| 1041 return result; | 1051 return result; |
| 1042 } | 1052 } |
| 1043 | 1053 |
| 1044 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1054 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 1045 return memory_bytes_ > limit.memory_bytes_ || | 1055 return memory_bytes_ > limit.memory_bytes_ || |
| 1046 resource_count_ > limit.resource_count_; | 1056 resource_count_ > limit.resource_count_; |
| 1047 } | 1057 } |
| 1048 | 1058 |
| 1049 } // namespace cc | 1059 } // namespace cc |
| OLD | NEW |