From 1cdf6668b7665cbc984d1f7eb75548ec4b8af3b0 Mon Sep 17 00:00:00 2001 From: "vollick@chromium.org" Date: Thu, 10 Oct 2013 01:18:33 +0000 Subject: Improve perf of CalculateDrawPropertiesInternal when there are no scroll parents. When we have scroll parents/children, we have to, potentially, reorder the children. Previously, we had incurred a portion of this cost, even if we didn't have any scroll parents/children in the tree. We would still populate a vector of pointers to the children (representing the order that they would be visited in). Of course, this order was the same as visiting layer->children() in order, so this work is wasted. This patch stores a bool on a layer's draw properties indicating that it has a child with a scroll parent. If this value is false, the reordering work may be safely skipped. BUG=305565 Review URL: https://codereview.chromium.org/26685002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227852 0039d316-1c4b-4281-b951-d872f2087c98 --- cc/layers/draw_properties.h | 7 +++++++ cc/trees/layer_tree_host_common.cc | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'cc') diff --git a/cc/layers/draw_properties.h b/cc/layers/draw_properties.h index bb8dcc0..b81bec7 100644 --- a/cc/layers/draw_properties.h +++ b/cc/layers/draw_properties.h @@ -30,6 +30,7 @@ struct CC_EXPORT DrawProperties { num_unclipped_descendants(0), can_draw_directly_to_backbuffer(false), layer_or_descendant_has_copy_request(false), + has_child_with_a_scroll_parent(false), sorted_for_recursion(false), index_of_first_descendants_addition(0), num_descendants_added(0), @@ -103,6 +104,12 @@ struct CC_EXPORT DrawProperties { // present on it. bool layer_or_descendant_has_copy_request; + // This is true if the layer has any direct child that has a scroll parent. + // This layer will not be the scroll parent in this case. This information + // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our + // children have scroll parents, we will not need to recur out of order. + bool has_child_with_a_scroll_parent; + // This is true if the order (wrt to its siblings in the tree) in which the // layer will be visited while computing draw properties has been determined. bool sorted_for_recursion; diff --git a/cc/trees/layer_tree_host_common.cc b/cc/trees/layer_tree_host_common.cc index 2e62f8d..c9d453f 100644 --- a/cc/trees/layer_tree_host_common.cc +++ b/cc/trees/layer_tree_host_common.cc @@ -1063,6 +1063,7 @@ static void PreCalculateMetaInformation( } layer->draw_properties().sorted_for_recursion = false; + layer->draw_properties().has_child_with_a_scroll_parent = false; if (layer->clip_parent()) recursive_data->num_unclipped_descendants++; @@ -1078,6 +1079,8 @@ static void PreCalculateMetaInformation( num_descendants_that_draw_content += child_layer->draw_properties().num_descendants_that_draw_content; + if (child_layer->scroll_parent()) + layer->draw_properties().has_child_with_a_scroll_parent = true; recursive_data->Merge(data_for_child); } @@ -1209,6 +1212,7 @@ static void AddScrollParentChain(std::vector* out, template static bool SortChildrenForRecursion(std::vector* out, const LayerType& parent) { + out->reserve(parent.children().size()); bool order_changed = false; for (size_t i = 0; i < parent.children().size(); ++i) { LayerType* current = @@ -1901,7 +1905,10 @@ static void CalculateDrawPropertiesInternal( scoped_ptr unsorted_descendants; std::vector sorted_children; - bool child_order_changed = SortChildrenForRecursion(&sorted_children, *layer); + bool child_order_changed = false; + if (layer_draw_properties.has_child_with_a_scroll_parent) + child_order_changed = SortChildrenForRecursion(&sorted_children, *layer); + if (child_order_changed) { // We'll be visiting our children out of order; use the temporary lists. unsorted_render_surface_layer_list.reset(new LayerListType); @@ -1911,8 +1918,15 @@ static void CalculateDrawPropertiesInternal( descendants_for_children = unsorted_descendants.get(); } - for (size_t i = 0; i < sorted_children.size(); ++i) { - LayerType* child = sorted_children[i]; + for (size_t i = 0; i < layer->children().size(); ++i) { + // If one of layer's children has a scroll parent, then we may have to + // visit the children out of order. The new order is stored in + // sorted_children. Otherwise, we'll grab the child directly from the + // layer's list of children. + LayerType* child = + layer_draw_properties.has_child_with_a_scroll_parent + ? sorted_children[i] + : LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i); child->draw_properties().index_of_first_descendants_addition = descendants_for_children->size(); -- cgit v1.1