Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Unified Diff: cc/trees/layer_tree_host_impl.cc

Issue 23548022: [cc] Evict UIResources when the renderer is not visible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typos Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_impl.cc
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 08e4ac16366b7a4e3b1de129cd5b81d1c7a994d1..d158a86f8b746673187ecde13c9c9627188f7ea5 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -311,6 +311,12 @@ bool LayerTreeHostImpl::CanDraw() const {
TRACE_EVENT_SCOPE_THREAD);
return false;
}
+ if (EvictedUIResourcesExist()) {
+ TRACE_EVENT_INSTANT0(
+ "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated",
+ TRACE_EVENT_SCOPE_THREAD);
+ return false;
+ }
return true;
}
@@ -1558,6 +1564,9 @@ void LayerTreeHostImpl::SetVisible(bool visible) {
DidVisibilityChange(this, visible_);
EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
+ if (!visible_)
+ EvictAllUIResources();
+
// Evict tiles immediately if invisible since this tab may never get another
// draw or timer tick.
if (!visible_)
@@ -1598,7 +1607,7 @@ void LayerTreeHostImpl::ReleaseTreeResources() {
if (recycle_tree_ && recycle_tree_->root_layer())
SendReleaseResourcesRecursive(recycle_tree_->root_layer());
- DeleteAllUIResources();
+ EvictAllUIResources();
}
void LayerTreeHostImpl::CreateAndSetRenderer(
@@ -2628,6 +2637,7 @@ void LayerTreeHostImpl::CreateUIResource(
gfx::Rect(bitmap->GetSize()),
gfx::Rect(bitmap->GetSize()),
gfx::Vector2d(0, 0));
+ MarkUIResourceNotEvicted(uid);
}
void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) {
@@ -2636,15 +2646,24 @@ void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) {
resource_provider_->DeleteResource(id);
ui_resource_map_.erase(uid);
}
+ MarkUIResourceNotEvicted(uid);
}
-void LayerTreeHostImpl::DeleteAllUIResources() {
+void LayerTreeHostImpl::EvictAllUIResources() {
+ if (ui_resource_map_.empty())
+ return;
+
for (UIResourceMap::const_iterator iter = ui_resource_map_.begin();
iter != ui_resource_map_.end();
++iter) {
+ evicted_ui_resources_.insert(iter->first);
resource_provider_->DeleteResource(iter->second);
}
ui_resource_map_.clear();
+
+ client_->SetNeedsCommitOnImplThread();
+ client_->OnCanDrawStateChanged(CanDraw());
+ client_->RenewTreePriority();
}
ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource(
@@ -2655,4 +2674,18 @@ ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource(
return 0;
}
+bool LayerTreeHostImpl::EvictedUIResourcesExist() const {
+ return !evicted_ui_resources_.empty();
+}
+
+void LayerTreeHostImpl::MarkUIResourceNotEvicted(UIResourceId uid) {
+ std::set<UIResourceId>::iterator found_in_evicted =
+ evicted_ui_resources_.find(uid);
+ if (found_in_evicted == evicted_ui_resources_.end())
+ return;
+ evicted_ui_resources_.erase(found_in_evicted);
+ if (evicted_ui_resources_.empty())
+ client_->OnCanDrawStateChanged(CanDraw());
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698