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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 ResourcePool* resource_pool, | 364 ResourcePool* resource_pool, |
365 Rasterizer* rasterizer, | 365 Rasterizer* rasterizer, |
366 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 366 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
367 : client_(client), | 367 : client_(client), |
368 task_runner_(task_runner), | 368 task_runner_(task_runner), |
369 resource_pool_(resource_pool), | 369 resource_pool_(resource_pool), |
370 rasterizer_(rasterizer), | 370 rasterizer_(rasterizer), |
371 prioritized_tiles_dirty_(false), | 371 prioritized_tiles_dirty_(false), |
372 all_tiles_that_need_to_be_rasterized_have_memory_(true), | 372 all_tiles_that_need_to_be_rasterized_have_memory_(true), |
373 all_tiles_required_for_activation_have_memory_(true), | 373 all_tiles_required_for_activation_have_memory_(true), |
374 memory_required_bytes_(0), | |
375 memory_nice_to_have_bytes_(0), | |
376 bytes_releasable_(0), | 374 bytes_releasable_(0), |
377 resources_releasable_(0), | 375 resources_releasable_(0), |
378 ever_exceeded_memory_budget_(false), | 376 ever_exceeded_memory_budget_(false), |
379 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 377 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
380 did_initialize_visible_tile_(false), | 378 did_initialize_visible_tile_(false), |
381 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 379 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
382 ready_to_activate_check_notifier_( | 380 ready_to_activate_check_notifier_( |
383 task_runner_, | 381 task_runner_, |
384 base::Bind(&TileManager::CheckIfReadyToActivate, | 382 base::Bind(&TileManager::CheckIfReadyToActivate, |
385 base::Unretained(this))) { | 383 base::Unretained(this))) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // required for activation are OOM. | 523 // required for activation are OOM. |
526 if (!all_tiles_required_for_activation_have_memory_) | 524 if (!all_tiles_required_for_activation_have_memory_) |
527 return; | 525 return; |
528 | 526 |
529 ready_to_activate_check_notifier_.Schedule(); | 527 ready_to_activate_check_notifier_.Schedule(); |
530 } | 528 } |
531 | 529 |
532 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { | 530 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { |
533 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); | 531 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); |
534 | 532 |
535 // Compute new stats to be return by GetMemoryStats(). | |
536 memory_required_bytes_ = 0; | |
537 memory_nice_to_have_bytes_ = 0; | |
538 | |
539 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; | 533 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; |
540 const TreePriority tree_priority = global_state_.tree_priority; | 534 const TreePriority tree_priority = global_state_.tree_priority; |
541 | 535 |
542 // For each tree, bin into different categories of tiles. | 536 // For each tree, bin into different categories of tiles. |
543 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 537 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
544 Tile* tile = it->second; | 538 Tile* tile = it->second; |
545 ManagedTileState& mts = tile->managed_state(); | 539 ManagedTileState& mts = tile->managed_state(); |
546 | 540 |
547 const ManagedTileState::TileVersion& tile_version = | 541 const ManagedTileState::TileVersion& tile_version = |
548 tile->GetTileVersionForDrawing(); | 542 tile->GetTileVersionForDrawing(); |
(...skipping 23 matching lines...) Expand all Loading... |
572 active_bin = kBinIsActiveMap[tile_is_active][active_bin]; | 566 active_bin = kBinIsActiveMap[tile_is_active][active_bin]; |
573 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; | 567 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; |
574 | 568 |
575 // We never want to paint new non-ideal tiles, as we always have | 569 // We never want to paint new non-ideal tiles, as we always have |
576 // a high-res tile covering that content (paint that instead). | 570 // a high-res tile covering that content (paint that instead). |
577 if (!tile_is_ready_to_draw && active_is_non_ideal) | 571 if (!tile_is_ready_to_draw && active_is_non_ideal) |
578 active_bin = NEVER_BIN; | 572 active_bin = NEVER_BIN; |
579 if (!tile_is_ready_to_draw && pending_is_non_ideal) | 573 if (!tile_is_ready_to_draw && pending_is_non_ideal) |
580 pending_bin = NEVER_BIN; | 574 pending_bin = NEVER_BIN; |
581 | 575 |
582 if (!tile_is_ready_to_draw || tile_version.requires_resource()) { | |
583 // The bin that the tile would have if the GPU memory manager had | |
584 // a maximally permissive policy, send to the GPU memory manager | |
585 // to determine policy. | |
586 ManagedTileBin gpu_memmgr_stats_bin = std::min(active_bin, pending_bin); | |
587 if ((gpu_memmgr_stats_bin == NOW_BIN) || | |
588 (gpu_memmgr_stats_bin == NOW_AND_READY_TO_DRAW_BIN)) | |
589 memory_required_bytes_ += BytesConsumedIfAllocated(tile); | |
590 if (gpu_memmgr_stats_bin != NEVER_BIN) | |
591 memory_nice_to_have_bytes_ += BytesConsumedIfAllocated(tile); | |
592 } | |
593 | |
594 ManagedTileBin tree_bin[NUM_TREES]; | 576 ManagedTileBin tree_bin[NUM_TREES]; |
595 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; | 577 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; |
596 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; | 578 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; |
597 | 579 |
598 // Adjust pending bin state for low res tiles. This prevents pending tree | 580 // Adjust pending bin state for low res tiles. This prevents pending tree |
599 // low-res tiles from being initialized before high-res tiles. | 581 // low-res tiles from being initialized before high-res tiles. |
600 if (pending_is_low_res) | 582 if (pending_is_low_res) |
601 tree_bin[PENDING_TREE] = std::max(tree_bin[PENDING_TREE], EVENTUALLY_BIN); | 583 tree_bin[PENDING_TREE] = std::max(tree_bin[PENDING_TREE], EVENTUALLY_BIN); |
602 | 584 |
603 TilePriority tile_priority; | 585 TilePriority tile_priority; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 "stats", | 687 "stats", |
706 TracedValue::FromValue(RasterTaskCompletionStatsAsValue( | 688 TracedValue::FromValue(RasterTaskCompletionStatsAsValue( |
707 update_visible_tiles_stats_).release())); | 689 update_visible_tiles_stats_).release())); |
708 update_visible_tiles_stats_ = RasterTaskCompletionStats(); | 690 update_visible_tiles_stats_ = RasterTaskCompletionStats(); |
709 | 691 |
710 bool did_initialize_visible_tile = did_initialize_visible_tile_; | 692 bool did_initialize_visible_tile = did_initialize_visible_tile_; |
711 did_initialize_visible_tile_ = false; | 693 did_initialize_visible_tile_ = false; |
712 return did_initialize_visible_tile; | 694 return did_initialize_visible_tile; |
713 } | 695 } |
714 | 696 |
715 void TileManager::GetMemoryStats(size_t* memory_required_bytes, | |
716 size_t* memory_nice_to_have_bytes, | |
717 size_t* memory_allocated_bytes, | |
718 size_t* memory_used_bytes) const { | |
719 *memory_required_bytes = memory_required_bytes_; | |
720 *memory_nice_to_have_bytes = memory_nice_to_have_bytes_; | |
721 *memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); | |
722 *memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); | |
723 } | |
724 | |
725 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { | 697 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { |
726 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 698 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
727 state->SetInteger("tile_count", tiles_.size()); | 699 state->SetInteger("tile_count", tiles_.size()); |
728 state->Set("global_state", global_state_.AsValue().release()); | 700 state->Set("global_state", global_state_.AsValue().release()); |
729 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); | |
730 return state.PassAs<base::Value>(); | 701 return state.PassAs<base::Value>(); |
731 } | 702 } |
732 | 703 |
733 scoped_ptr<base::Value> TileManager::AllTilesAsValue() const { | 704 scoped_ptr<base::Value> TileManager::AllTilesAsValue() const { |
734 scoped_ptr<base::ListValue> state(new base::ListValue()); | 705 scoped_ptr<base::ListValue> state(new base::ListValue()); |
735 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 706 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
736 state->Append(it->second->AsValue().release()); | 707 state->Append(it->second->AsValue().release()); |
737 | 708 |
738 return state.PassAs<base::Value>(); | 709 return state.PassAs<base::Value>(); |
739 } | 710 } |
740 | 711 |
741 scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const { | |
742 scoped_ptr<base::DictionaryValue> requirements(new base::DictionaryValue()); | |
743 | |
744 size_t memory_required_bytes; | |
745 size_t memory_nice_to_have_bytes; | |
746 size_t memory_allocated_bytes; | |
747 size_t memory_used_bytes; | |
748 GetMemoryStats(&memory_required_bytes, | |
749 &memory_nice_to_have_bytes, | |
750 &memory_allocated_bytes, | |
751 &memory_used_bytes); | |
752 requirements->SetInteger("memory_required_bytes", memory_required_bytes); | |
753 requirements->SetInteger("memory_nice_to_have_bytes", | |
754 memory_nice_to_have_bytes); | |
755 requirements->SetInteger("memory_allocated_bytes", memory_allocated_bytes); | |
756 requirements->SetInteger("memory_used_bytes", memory_used_bytes); | |
757 return requirements.PassAs<base::Value>(); | |
758 } | |
759 | |
760 void TileManager::AssignGpuMemoryToTiles( | 712 void TileManager::AssignGpuMemoryToTiles( |
761 PrioritizedTileSet* tiles, | 713 PrioritizedTileSet* tiles, |
762 TileVector* tiles_that_need_to_be_rasterized) { | 714 TileVector* tiles_that_need_to_be_rasterized) { |
763 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 715 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
764 | 716 |
765 // Maintain the list of released resources that can potentially be re-used | 717 // Maintain the list of released resources that can potentially be re-used |
766 // or deleted. | 718 // or deleted. |
767 // If this operation becomes expensive too, only do this after some | 719 // If this operation becomes expensive too, only do this after some |
768 // resource(s) was returned. Note that in that case, one also need to | 720 // resource(s) was returned. Note that in that case, one also need to |
769 // invalidate when releasing some resource from the pool. | 721 // invalidate when releasing some resource from the pool. |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 1576 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
1625 | 1577 |
1626 rasterizer_->CheckForCompletedTasks(); | 1578 rasterizer_->CheckForCompletedTasks(); |
1627 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1579 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
1628 | 1580 |
1629 if (IsReadyToActivate()) | 1581 if (IsReadyToActivate()) |
1630 client_->NotifyReadyToActivate(); | 1582 client_->NotifyReadyToActivate(); |
1631 } | 1583 } |
1632 | 1584 |
1633 } // namespace cc | 1585 } // namespace cc |
OLD | NEW |