OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 last_scroll_did_bubble_(false), | 201 last_scroll_did_bubble_(false), |
202 wheel_scrolling_(false), | 202 wheel_scrolling_(false), |
203 scroll_layer_id_when_mouse_over_scrollbar_(0), | 203 scroll_layer_id_when_mouse_over_scrollbar_(0), |
204 tile_priorities_dirty_(false), | 204 tile_priorities_dirty_(false), |
205 root_layer_scroll_offset_delegate_(NULL), | 205 root_layer_scroll_offset_delegate_(NULL), |
206 settings_(settings), | 206 settings_(settings), |
207 visible_(true), | 207 visible_(true), |
208 cached_managed_memory_policy_( | 208 cached_managed_memory_policy_( |
209 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), | 209 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), |
210 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, | 210 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, |
211 0, | |
212 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING, | |
213 ManagedMemoryPolicy::kDefaultNumResourcesLimit), | 211 ManagedMemoryPolicy::kDefaultNumResourcesLimit), |
214 pinch_gesture_active_(false), | 212 pinch_gesture_active_(false), |
215 pinch_gesture_end_should_clear_scrolling_layer_(false), | 213 pinch_gesture_end_should_clear_scrolling_layer_(false), |
216 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), | 214 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), |
217 paint_time_counter_(PaintTimeCounter::Create()), | 215 paint_time_counter_(PaintTimeCounter::Create()), |
218 memory_history_(MemoryHistory::Create()), | 216 memory_history_(MemoryHistory::Create()), |
219 debug_rect_history_(DebugRectHistory::Create()), | 217 debug_rect_history_(DebugRectHistory::Create()), |
220 texture_mailbox_deleter_(new TextureMailboxDeleter), | 218 texture_mailbox_deleter_(new TextureMailboxDeleter), |
221 max_memory_needed_bytes_(0), | 219 max_memory_needed_bytes_(0), |
222 last_sent_memory_visible_bytes_(0), | 220 last_sent_memory_visible_bytes_(0), |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 } | 1057 } |
1060 | 1058 |
1061 void LayerTreeHostImpl::DidInitializeVisibleTileForTesting() { | 1059 void LayerTreeHostImpl::DidInitializeVisibleTileForTesting() { |
1062 DidInitializeVisibleTile(); | 1060 DidInitializeVisibleTile(); |
1063 } | 1061 } |
1064 | 1062 |
1065 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( | 1063 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( |
1066 const ManagedMemoryPolicy& policy) { | 1064 const ManagedMemoryPolicy& policy) { |
1067 | 1065 |
1068 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread( | 1066 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread( |
1069 visible_ ? policy.bytes_limit_when_visible | 1067 visible_ ? policy.bytes_limit_when_visible : 0, |
1070 : policy.bytes_limit_when_not_visible, | |
1071 ManagedMemoryPolicy::PriorityCutoffToValue( | 1068 ManagedMemoryPolicy::PriorityCutoffToValue( |
1072 visible_ ? policy.priority_cutoff_when_visible | 1069 visible_ ? policy.priority_cutoff_when_visible |
1073 : policy.priority_cutoff_when_not_visible)); | 1070 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING)); |
1074 if (evicted_resources) { | 1071 if (evicted_resources) { |
1075 active_tree_->SetContentsTexturesPurged(); | 1072 active_tree_->SetContentsTexturesPurged(); |
1076 if (pending_tree_) | 1073 if (pending_tree_) |
1077 pending_tree_->SetContentsTexturesPurged(); | 1074 pending_tree_->SetContentsTexturesPurged(); |
1078 client_->SetNeedsCommitOnImplThread(); | 1075 client_->SetNeedsCommitOnImplThread(); |
1079 client_->OnCanDrawStateChanged(CanDraw()); | 1076 client_->OnCanDrawStateChanged(CanDraw()); |
1080 client_->RenewTreePriority(); | 1077 client_->RenewTreePriority(); |
1081 } | 1078 } |
1082 client_->SendManagedMemoryStats(); | 1079 client_->SendManagedMemoryStats(); |
1083 | 1080 |
1084 UpdateTileManagerMemoryPolicy(policy); | 1081 UpdateTileManagerMemoryPolicy(policy); |
1085 } | 1082 } |
1086 | 1083 |
1087 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( | 1084 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( |
1088 const ManagedMemoryPolicy& policy) { | 1085 const ManagedMemoryPolicy& policy) { |
1089 if (!tile_manager_) | 1086 if (!tile_manager_) |
1090 return; | 1087 return; |
1091 | 1088 |
1092 // TODO(reveman): We should avoid keeping around unused resources if | 1089 // TODO(reveman): We should avoid keeping around unused resources if |
1093 // possible. crbug.com/224475 | 1090 // possible. crbug.com/224475 |
1094 global_tile_state_.memory_limit_in_bytes = | 1091 global_tile_state_.memory_limit_in_bytes = |
1095 visible_ ? | 1092 visible_ ? |
1096 policy.bytes_limit_when_visible : | 1093 policy.bytes_limit_when_visible : 0; |
1097 policy.bytes_limit_when_not_visible; | |
1098 global_tile_state_.unused_memory_limit_in_bytes = static_cast<size_t>( | 1094 global_tile_state_.unused_memory_limit_in_bytes = static_cast<size_t>( |
1099 (static_cast<int64>(global_tile_state_.memory_limit_in_bytes) * | 1095 (static_cast<int64>(global_tile_state_.memory_limit_in_bytes) * |
1100 settings_.max_unused_resource_memory_percentage) / 100); | 1096 settings_.max_unused_resource_memory_percentage) / 100); |
1101 global_tile_state_.memory_limit_policy = | 1097 global_tile_state_.memory_limit_policy = |
1102 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( | 1098 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( |
1103 visible_ ? | 1099 visible_ ? |
1104 policy.priority_cutoff_when_visible : | 1100 policy.priority_cutoff_when_visible : |
1105 policy.priority_cutoff_when_not_visible); | 1101 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); |
1106 global_tile_state_.num_resources_limit = policy.num_resources_limit; | 1102 global_tile_state_.num_resources_limit = policy.num_resources_limit; |
1107 | 1103 |
1108 DidModifyTilePriorities(); | 1104 DidModifyTilePriorities(); |
1109 } | 1105 } |
1110 | 1106 |
1111 void LayerTreeHostImpl::DidModifyTilePriorities() { | 1107 void LayerTreeHostImpl::DidModifyTilePriorities() { |
1112 DCHECK(settings_.impl_side_painting); | 1108 DCHECK(settings_.impl_side_painting); |
1113 // Mark priorities as dirty and schedule a ManageTiles(). | 1109 // Mark priorities as dirty and schedule a ManageTiles(). |
1114 tile_priorities_dirty_ = true; | 1110 tile_priorities_dirty_ = true; |
1115 client_->SetNeedsManageTilesOnImplThread(); | 1111 client_->SetNeedsManageTilesOnImplThread(); |
1116 } | 1112 } |
1117 | 1113 |
1118 void LayerTreeHostImpl::DidInitializeVisibleTile() { | 1114 void LayerTreeHostImpl::DidInitializeVisibleTile() { |
1119 // TODO(reveman): Determine tiles that changed and only damage | 1115 // TODO(reveman): Determine tiles that changed and only damage |
1120 // what's necessary. | 1116 // what's necessary. |
1121 SetFullRootLayerDamage(); | 1117 SetFullRootLayerDamage(); |
1122 if (client_ && !client_->IsInsideDraw()) | 1118 if (client_ && !client_->IsInsideDraw()) |
1123 client_->DidInitializeVisibleTileOnImplThread(); | 1119 client_->DidInitializeVisibleTileOnImplThread(); |
1124 } | 1120 } |
1125 | 1121 |
1126 void LayerTreeHostImpl::NotifyReadyToActivate() { | 1122 void LayerTreeHostImpl::NotifyReadyToActivate() { |
1127 client_->NotifyReadyToActivate(); | 1123 client_->NotifyReadyToActivate(); |
1128 } | 1124 } |
1129 | 1125 |
1130 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { | 1126 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { |
1131 SetManagedMemoryPolicy(policy, zero_budget_); | 1127 SetManagedMemoryPolicy(policy, zero_budget_); |
1132 } | 1128 } |
1133 | 1129 |
1134 void LayerTreeHostImpl::SetDiscardBackBufferWhenNotVisible(bool discard) { | |
1135 DCHECK(renderer_); | |
1136 renderer_->SetDiscardBackBufferWhenNotVisible(discard); | |
1137 } | |
1138 | |
1139 void LayerTreeHostImpl::SetTreeActivationCallback( | 1130 void LayerTreeHostImpl::SetTreeActivationCallback( |
1140 const base::Closure& callback) { | 1131 const base::Closure& callback) { |
1141 DCHECK(proxy_->IsImplThread()); | 1132 DCHECK(proxy_->IsImplThread()); |
1142 DCHECK(settings_.impl_side_painting || callback.is_null()); | 1133 DCHECK(settings_.impl_side_painting || callback.is_null()); |
1143 tree_activation_callback_ = callback; | 1134 tree_activation_callback_ = callback; |
1144 } | 1135 } |
1145 | 1136 |
1146 void LayerTreeHostImpl::SetManagedMemoryPolicy( | 1137 void LayerTreeHostImpl::SetManagedMemoryPolicy( |
1147 const ManagedMemoryPolicy& policy, bool zero_budget) { | 1138 const ManagedMemoryPolicy& policy, bool zero_budget) { |
1148 if (cached_managed_memory_policy_ == policy && zero_budget_ == zero_budget) | 1139 if (cached_managed_memory_policy_ == policy && zero_budget_ == zero_budget) |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 | 1544 |
1554 if (!renderer_) | 1545 if (!renderer_) |
1555 return; | 1546 return; |
1556 | 1547 |
1557 renderer_->SetVisible(visible); | 1548 renderer_->SetVisible(visible); |
1558 } | 1549 } |
1559 | 1550 |
1560 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { | 1551 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { |
1561 ManagedMemoryPolicy actual = cached_managed_memory_policy_; | 1552 ManagedMemoryPolicy actual = cached_managed_memory_policy_; |
1562 if (debug_state_.rasterize_only_visible_content) { | 1553 if (debug_state_.rasterize_only_visible_content) { |
1563 actual.priority_cutoff_when_not_visible = | |
1564 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING; | |
1565 actual.priority_cutoff_when_visible = | 1554 actual.priority_cutoff_when_visible = |
1566 gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY; | 1555 gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY; |
1567 } | 1556 } |
1568 | 1557 |
1569 if (zero_budget_) { | 1558 if (zero_budget_) { |
1570 actual.bytes_limit_when_visible = 0; | 1559 actual.bytes_limit_when_visible = 0; |
1571 actual.bytes_limit_when_not_visible = 0; | |
1572 } | 1560 } |
1573 | 1561 |
1574 return actual; | 1562 return actual; |
1575 } | 1563 } |
1576 | 1564 |
1577 size_t LayerTreeHostImpl::memory_allocation_limit_bytes() const { | 1565 size_t LayerTreeHostImpl::memory_allocation_limit_bytes() const { |
1578 return ActualManagedMemoryPolicy().bytes_limit_when_visible; | 1566 return ActualManagedMemoryPolicy().bytes_limit_when_visible; |
1579 } | 1567 } |
1580 | 1568 |
1581 int LayerTreeHostImpl::memory_allocation_priority_cutoff() const { | 1569 int LayerTreeHostImpl::memory_allocation_priority_cutoff() const { |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2813 std::set<UIResourceId>::iterator found_in_evicted = | 2801 std::set<UIResourceId>::iterator found_in_evicted = |
2814 evicted_ui_resources_.find(uid); | 2802 evicted_ui_resources_.find(uid); |
2815 if (found_in_evicted == evicted_ui_resources_.end()) | 2803 if (found_in_evicted == evicted_ui_resources_.end()) |
2816 return; | 2804 return; |
2817 evicted_ui_resources_.erase(found_in_evicted); | 2805 evicted_ui_resources_.erase(found_in_evicted); |
2818 if (evicted_ui_resources_.empty()) | 2806 if (evicted_ui_resources_.empty()) |
2819 client_->OnCanDrawStateChanged(CanDraw()); | 2807 client_->OnCanDrawStateChanged(CanDraw()); |
2820 } | 2808 } |
2821 | 2809 |
2822 } // namespace cc | 2810 } // namespace cc |
OLD | NEW |