diff options
author | jaydasika <jaydasika@chromium.org> | 2016-03-21 13:44:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-21 20:45:22 +0000 |
commit | 9234e405c7089c47ca9d30b34846f54b1fd9b8fd (patch) | |
tree | c338cb228c148d32e26bf08f30e965904d14ab6a /cc | |
parent | 8b23772eff902cf5df76414e1998826e87fc8444 (diff) | |
download | chromium_src-9234e405c7089c47ca9d30b34846f54b1fd9b8fd.zip chromium_src-9234e405c7089c47ca9d30b34846f54b1fd9b8fd.tar.gz chromium_src-9234e405c7089c47ca9d30b34846f54b1fd9b8fd.tar.bz2 |
cc : Make tree synchronization independent of layer tree hierarchy (2)
This CL :
* Stores layers that need to push properties in LayerTreeHost(layer_set)
* Deletes bools needs_push_properties and dependants_needs_push_properties
from Layer.
* Iterate the layer_set tp push properties during commit.
* Changes what layers are serialized (Both dirty layers and their ancestors
are serialized currently. With this CL, only dirty layers serialize).
BUG=568874
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1808373002
Cr-Commit-Position: refs/heads/master@{#382379}
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layers/layer.cc | 70 | ||||
-rw-r--r-- | cc/layers/layer.h | 43 | ||||
-rw-r--r-- | cc/layers/layer_proto_converter.cc | 24 | ||||
-rw-r--r-- | cc/layers/layer_proto_converter.h | 10 | ||||
-rw-r--r-- | cc/layers/layer_proto_converter_unittest.cc | 271 | ||||
-rw-r--r-- | cc/layers/layer_unittest.cc | 208 | ||||
-rw-r--r-- | cc/proto/layer.proto | 4 | ||||
-rw-r--r-- | cc/proto/layer_tree_host.proto | 1 | ||||
-rw-r--r-- | cc/test/fake_layer_tree_host.cc | 6 | ||||
-rw-r--r-- | cc/trees/layer_tree_host.cc | 33 | ||||
-rw-r--r-- | cc/trees/layer_tree_host.h | 10 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 8 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest.cc | 403 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest_scroll.cc | 8 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest_serialization.cc | 7 | ||||
-rw-r--r-- | cc/trees/tree_synchronizer.cc | 82 | ||||
-rw-r--r-- | cc/trees/tree_synchronizer.h | 16 | ||||
-rw-r--r-- | cc/trees/tree_synchronizer_unittest.cc | 50 |
18 files changed, 470 insertions, 784 deletions
diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc index b820387..7f1dd1d 100644 --- a/cc/layers/layer.cc +++ b/cc/layers/layer.cc @@ -45,9 +45,7 @@ scoped_refptr<Layer> Layer::Create() { } Layer::Layer() - : needs_push_properties_(false), - num_dependents_need_push_properties_(0), - // Layer IDs start from 1. + : // Layer IDs start from 1. layer_id_(g_next_layer_id.GetNext() + 1), ignore_set_needs_commit_(false), sorting_context_id_(0), @@ -134,9 +132,8 @@ void Layer::SetLayerTreeHost(LayerTreeHost* host) { host->RegisterLayer(this); } - InvalidatePropertyTreesIndices(); - layer_tree_host_ = host; + InvalidatePropertyTreesIndices(); // When changing hosts, the layer needs to commit its properties to the impl // side for the new host. @@ -202,28 +199,12 @@ void Layer::SetNextCommitWaitsForActivation() { } void Layer::SetNeedsPushProperties() { - if (needs_push_properties_) - return; - if (!parent_should_know_need_push_properties() && parent_) - parent_->AddDependentNeedsPushProperties(); - needs_push_properties_ = true; -} - -void Layer::AddDependentNeedsPushProperties() { - DCHECK_GE(num_dependents_need_push_properties_, 0); - - if (!parent_should_know_need_push_properties() && parent_) - parent_->AddDependentNeedsPushProperties(); - - num_dependents_need_push_properties_++; + if (layer_tree_host_) + layer_tree_host_->AddLayerShouldPushProperties(this); } -void Layer::RemoveDependentNeedsPushProperties() { - num_dependents_need_push_properties_--; - DCHECK_GE(num_dependents_need_push_properties_, 0); - - if (!parent_should_know_need_push_properties() && parent_) - parent_->RemoveDependentNeedsPushProperties(); +void Layer::ResetNeedsPushPropertiesForTesting() { + layer_tree_host_->RemoveLayerShouldPushProperties(this); } bool Layer::IsPropertyChangeAllowed() const { @@ -243,13 +224,6 @@ skia::RefPtr<SkPicture> Layer::GetPicture() const { void Layer::SetParent(Layer* layer) { DCHECK(!layer || !layer->HasAncestor(this)); - if (parent_should_know_need_push_properties()) { - if (parent_) - parent_->RemoveDependentNeedsPushProperties(); - if (layer) - layer->AddDependentNeedsPushProperties(); - } - parent_ = layer; SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); @@ -1310,8 +1284,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { subtree_property_changed_ = false; update_rect_ = gfx::Rect(); - needs_push_properties_ = false; - num_dependents_need_push_properties_ = 0; + layer_tree_host()->RemoveLayerShouldPushProperties(this); } void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { @@ -1401,41 +1374,16 @@ void Layer::FromLayerNodeProto(const proto::LayerNode& proto, } } -bool Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { - if (!needs_push_properties_ && num_dependents_need_push_properties_ == 0) - return false; - +void Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { // Always set properties metadata for serialized layers. proto::LayerProperties* proto = layer_update->add_layers(); proto->set_id(layer_id_); - proto->set_needs_push_properties(needs_push_properties_); - proto->set_num_dependents_need_push_properties( - num_dependents_need_push_properties_); - - if (needs_push_properties_) - LayerSpecificPropertiesToProto(proto); - - needs_push_properties_ = false; - - bool descendant_needs_push_properties = - num_dependents_need_push_properties_ > 0; - num_dependents_need_push_properties_ = 0; - - return descendant_needs_push_properties; + LayerSpecificPropertiesToProto(proto); } void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) { DCHECK(proto.has_id()); DCHECK_EQ(layer_id_, proto.id()); - DCHECK(proto.has_needs_push_properties()); - needs_push_properties_ = proto.needs_push_properties(); - DCHECK(proto.has_num_dependents_need_push_properties()); - num_dependents_need_push_properties_ = - proto.num_dependents_need_push_properties(); - - if (!needs_push_properties_) - return; - FromLayerSpecificPropertiesProto(proto); } diff --git a/cc/layers/layer.h b/cc/layers/layer.h index 64540492..3005401 100644 --- a/cc/layers/layer.h +++ b/cc/layers/layer.h @@ -384,14 +384,10 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { const LayerIdMap& layer_map); // This method is similar to PushPropertiesTo, but instead of pushing to - // a LayerImpl, it pushes the properties to proto::LayerProperties. It adds - // this layer to the proto::LayerUpdate if it or any of its descendants - // have changed properties. If this layer contains changed properties, the - // properties themselves will also be pushed the proto::LayerProperties. - // Similarly to PushPropertiesTo, this method also resets - // |needs_push_properties_| and |num_dependents_need_push_properties_|. - // Returns whether any of the descendants have changed properties. - bool ToLayerPropertiesProto(proto::LayerUpdate* layer_update); + // a LayerImpl, it pushes the properties to proto::LayerProperties. It is + // called only on layers that have changed properties. The properties + // themselves are pushed to proto::LayerProperties. + void ToLayerPropertiesProto(proto::LayerUpdate* layer_update); // Read all property values from the given LayerProperties object and update // the current layer. The values for |needs_push_properties_| and @@ -419,13 +415,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { } void SetNeedsPushProperties(); - bool needs_push_properties() const { return needs_push_properties_; } - bool descendant_needs_push_properties() const { - return num_dependents_need_push_properties_ > 0; - } - void reset_needs_push_properties_for_testing() { - needs_push_properties_ = false; - } + void ResetNeedsPushPropertiesForTesting(); virtual void RunMicroBenchmark(MicroBenchmark* benchmark); @@ -562,39 +552,20 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { void AddDependentNeedsPushProperties(); void RemoveDependentNeedsPushProperties(); - bool parent_should_know_need_push_properties() const { - return needs_push_properties() || descendant_needs_push_properties(); - } bool IsPropertyChangeAllowed() const; // Serialize all the necessary properties to be able to reconstruct this Layer - // into proto::LayerProperties. This function must not set values for - // |needs_push_properties_| or |num_dependents_need_push_properties_| as they - // are dealt with at a higher level. This is only called if - // |needs_push_properties_| is set. For descendants of Layer, implementations - // must first call their parent class. This method is not marked as const + // into proto::LayerProperties. This method is not marked as const // as some implementations need reset member fields, similarly to // PushPropertiesTo(). virtual void LayerSpecificPropertiesToProto(proto::LayerProperties* proto); // Deserialize all the necessary properties from proto::LayerProperties into - // this Layer. This function must not set values for |needs_push_properties_| - // or |num_dependents_need_push_properties_| as they are dealt with at a - // higher level. This is only called if |needs_push_properties_| is set. For - // descendants of Layer, implementations must first call their parent class. + // this Layer. virtual void FromLayerSpecificPropertiesProto( const proto::LayerProperties& proto); - // This flag is set when the layer needs to push properties to the impl - // side. - bool needs_push_properties_; - - // The number of direct children or dependent layers that need to be recursed - // to in order for them or a descendent of them to push properties to the impl - // side. - int num_dependents_need_push_properties_; - // The update rect is the region of the compositor resource that was // actually updated by the compositor. For layers that may do updating // outside the compositor's control (i.e. plugin layers), this information diff --git a/cc/layers/layer_proto_converter.cc b/cc/layers/layer_proto_converter.cc index 27c76ae..626380d 100644 --- a/cc/layers/layer_proto_converter.cc +++ b/cc/layers/layer_proto_converter.cc @@ -10,6 +10,7 @@ #include "cc/layers/layer.h" #include "cc/layers/picture_layer.h" #include "cc/proto/layer.pb.h" +#include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_settings.h" @@ -47,9 +48,11 @@ scoped_refptr<Layer> LayerProtoConverter::DeserializeLayerHierarchy( // static void LayerProtoConverter::SerializeLayerProperties( - Layer* root_layer, + LayerTreeHost* host, proto::LayerUpdate* layer_update) { - RecursivelySerializeLayerProperties(root_layer, layer_update); + for (auto layer : host->LayersThatShouldPushProperties()) + layer->ToLayerPropertiesProto(layer_update); + host->LayersThatShouldPushProperties().clear(); } // static @@ -72,23 +75,6 @@ void LayerProtoConverter::DeserializeLayerProperties( } // static -void LayerProtoConverter::RecursivelySerializeLayerProperties( - Layer* layer, - proto::LayerUpdate* layer_update) { - bool serialize_descendants = layer->ToLayerPropertiesProto(layer_update); - if (!serialize_descendants) - return; - - for (const auto& child : layer->children()) { - RecursivelySerializeLayerProperties(child.get(), layer_update); - } - if (layer->mask_layer()) - RecursivelySerializeLayerProperties(layer->mask_layer(), layer_update); - if (layer->replica_layer()) - RecursivelySerializeLayerProperties(layer->replica_layer(), layer_update); -} - -// static void LayerProtoConverter::RecursivelyFindAllLayers(Layer* root_layer, LayerIdMap* layer_id_map) { LayerTreeHostCommon::CallFunctionForSubtree( diff --git a/cc/layers/layer_proto_converter.h b/cc/layers/layer_proto_converter.h index b0af34a..92a4b54 100644 --- a/cc/layers/layer_proto_converter.h +++ b/cc/layers/layer_proto_converter.h @@ -35,11 +35,11 @@ class CC_EXPORT LayerProtoConverter { const scoped_refptr<Layer> existing_root, const proto::LayerNode& root_node); - // Starting at |root_layer|, serializes the properties of all the dirty nodes - // in the Layer hierarchy. The proto::LayerUpdate will contain all nodes that - // either are dirty or have dirty descendants. Only nodes that are dirty will - // contain the list of dirty properties. - static void SerializeLayerProperties(Layer* root_layer, + // Serializes the properties of all the dirty nodes in the Layer hierarchy. + // The proto::LayerUpdate will contain all nodes that are dirty. These nodes + // will contain the list of dirty properties. This function also resets the + // layers that need push properties set. + static void SerializeLayerProperties(LayerTreeHost* host, proto::LayerUpdate* layer_update); // Iterate over all updated layers from the LayerUpdate, and update the diff --git a/cc/layers/layer_proto_converter_unittest.cc b/cc/layers/layer_proto_converter_unittest.cc index fd88da4..2de7f7d 100644 --- a/cc/layers/layer_proto_converter_unittest.cc +++ b/cc/layers/layer_proto_converter_unittest.cc @@ -181,6 +181,7 @@ TEST_F(LayerProtoConverterTest, RecursivePropertiesSerialization) { scoped_refptr<Layer> layer_src_b_replica = Layer::Create(); scoped_refptr<Layer> layer_src_c = Layer::Create(); scoped_refptr<Layer> layer_src_d = Layer::Create(); + layer_src_root->SetLayerTreeHost(layer_tree_host_.get()); layer_src_root->AddChild(layer_src_a); layer_src_root->AddChild(layer_src_b); layer_src_a->AddChild(layer_src_c); @@ -189,97 +190,78 @@ TEST_F(LayerProtoConverterTest, RecursivePropertiesSerialization) { layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); proto::LayerUpdate layer_update; - LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), - &layer_update); + LayerProtoConverter::SerializeLayerProperties( + layer_src_root->layer_tree_host(), &layer_update); // All flags for pushing properties should have been cleared. - EXPECT_FALSE(layer_src_root->needs_push_properties()); - EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_a->needs_push_properties()); - EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b->needs_push_properties()); - EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_c->needs_push_properties()); - EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_d->needs_push_properties()); - EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); - - // AddChild changes the stacking order of child and it needs to push - // properties. - ASSERT_EQ(5, layer_update.layers_size()); - EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); - proto::LayerProperties dest_root = layer_update.layers(0); - EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id()); - proto::LayerProperties dest_a = layer_update.layers(1); - EXPECT_EQ(layer_src_c->id(), layer_update.layers(2).id()); - proto::LayerProperties dest_c = layer_update.layers(2); - EXPECT_EQ(layer_src_b->id(), layer_update.layers(3).id()); - proto::LayerProperties dest_b = layer_update.layers(3); - EXPECT_EQ(layer_src_d->id(), layer_update.layers(4).id()); - proto::LayerProperties dest_d = layer_update.layers(4); + EXPECT_FALSE( + layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_root.get())); + EXPECT_FALSE( + layer_src_a->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_a.get())); + EXPECT_FALSE( + layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_b.get())); + EXPECT_FALSE( + layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_b_mask.get())); + EXPECT_FALSE( + layer_src_b_replica->layer_tree_host() + ->LayerNeedsPushPropertiesForTesting(layer_src_b_replica.get())); + EXPECT_FALSE( + layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_c.get())); + EXPECT_FALSE( + layer_src_d->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_d.get())); + + // All layers needs to push properties as their layer tree host changed. + ASSERT_EQ(7, layer_update.layers_size()); layer_update.Clear(); + std::unordered_set<int> dirty_layer_ids; layer_src_a->SetNeedsPushProperties(); + dirty_layer_ids.insert(layer_src_a->id()); layer_src_b->SetNeedsPushProperties(); + dirty_layer_ids.insert(layer_src_b->id()); layer_src_b_mask->SetNeedsPushProperties(); + dirty_layer_ids.insert(layer_src_b_mask->id()); layer_src_d->SetNeedsPushProperties(); + dirty_layer_ids.insert(layer_src_d->id()); - LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), - &layer_update); + LayerProtoConverter::SerializeLayerProperties( + layer_src_root->layer_tree_host(), &layer_update); // All flags for pushing properties should have been cleared. - EXPECT_FALSE(layer_src_root->needs_push_properties()); - EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_a->needs_push_properties()); - EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b->needs_push_properties()); - EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_c->needs_push_properties()); - EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_d->needs_push_properties()); - EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); - - // Only 5 of the layers should have been serialized. - ASSERT_EQ(5, layer_update.layers_size()); - EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); - dest_root = layer_update.layers(0); - EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id()); - dest_a = layer_update.layers(1); - EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id()); - dest_b = layer_update.layers(2); - EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id()); - dest_d = layer_update.layers(3); - EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id()); - proto::LayerProperties dest_b_mask = layer_update.layers(4); - - // Ensure the properties and dependants metadata is correctly serialized. - EXPECT_FALSE(dest_root.needs_push_properties()); - EXPECT_EQ(2, dest_root.num_dependents_need_push_properties()); - EXPECT_FALSE(dest_root.has_base()); - - EXPECT_TRUE(dest_a.needs_push_properties()); - EXPECT_EQ(0, dest_a.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_a.has_base()); - - EXPECT_TRUE(dest_b.needs_push_properties()); - EXPECT_EQ(2, dest_b.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b.has_base()); - - EXPECT_TRUE(dest_d.needs_push_properties()); - EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_d.has_base()); - - EXPECT_TRUE(dest_b_mask.needs_push_properties()); - EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b_mask.has_base()); + EXPECT_FALSE( + layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_root.get())); + EXPECT_FALSE( + layer_src_a->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_a.get())); + EXPECT_FALSE( + layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_b.get())); + EXPECT_FALSE( + layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_b_mask.get())); + EXPECT_FALSE( + layer_src_b_replica->layer_tree_host() + ->LayerNeedsPushPropertiesForTesting(layer_src_b_replica.get())); + EXPECT_FALSE( + layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_c.get())); + EXPECT_FALSE( + layer_src_d->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_d.get())); + + // Only 4 of the layers should have been serialized. + ASSERT_EQ(4, layer_update.layers_size()); + for (int index = 0; index < layer_update.layers_size(); index++) + EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()), + dirty_layer_ids.end()); + layer_src_root->SetLayerTreeHost(nullptr); } TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) { @@ -300,115 +282,44 @@ TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) { layer_src_root->AddChild(layer_src_b); layer_src_b->AddChild(layer_src_c); layer_src_b->SetMaskLayer(layer_src_b_mask.get()); + layer_src_root->SetLayerTreeHost(layer_tree_host_.get()); proto::LayerUpdate layer_update; - LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), - &layer_update); - // AddChild changes stacking order of child and we need to push proeprties of - // child. - ASSERT_EQ(3, layer_update.layers_size()); + LayerProtoConverter::SerializeLayerProperties( + layer_src_root->layer_tree_host(), &layer_update); + // All layers need to push properties as their layer tree host changed. + ASSERT_EQ(4, layer_update.layers_size()); layer_update.Clear(); + std::unordered_set<int> dirty_layer_ids; layer_src_b->SetNeedsPushProperties(); + dirty_layer_ids.insert(layer_src_b->id()); layer_src_b_mask->SetNeedsPushProperties(); + dirty_layer_ids.insert(layer_src_b_mask->id()); - LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), - &layer_update); + LayerProtoConverter::SerializeLayerProperties( + layer_src_root->layer_tree_host(), &layer_update); // All flags for pushing properties should have been cleared. - EXPECT_FALSE(layer_src_root->needs_push_properties()); - EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b->needs_push_properties()); - EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_c->needs_push_properties()); - EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); - - // Only 3 of the layers should have been serialized. - ASSERT_EQ(3, layer_update.layers_size()); - EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); - proto::LayerProperties dest_root = layer_update.layers(0); - EXPECT_EQ(layer_src_b->id(), layer_update.layers(1).id()); - proto::LayerProperties dest_b = layer_update.layers(1); - EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(2).id()); - proto::LayerProperties dest_b_mask = layer_update.layers(2); - - // Ensure the properties and dependants metadata is correctly serialized. - EXPECT_FALSE(dest_root.needs_push_properties()); - EXPECT_EQ(1, dest_root.num_dependents_need_push_properties()); - EXPECT_FALSE(dest_root.has_base()); - - EXPECT_TRUE(dest_b.needs_push_properties()); - EXPECT_EQ(1, dest_b.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b.has_base()); - - EXPECT_TRUE(dest_b_mask.needs_push_properties()); - EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b_mask.has_base()); -} - -TEST_F(LayerProtoConverterTest, DeserializeLayerProperties) { - /* Testing deserialization of properties for a tree that looks like this: - root*+ - / \ - a b+ - \ - c* - Layers marked with * have changed properties. - Layers marked with + have descendants with changed properties. - */ - proto::LayerUpdate updates; - - scoped_refptr<Layer> root = Layer::Create(); - root->SetLayerTreeHost(layer_tree_host_.get()); - proto::LayerProperties* root_props = updates.add_layers(); - root_props->set_id(root->id()); - root_props->set_needs_push_properties(true); - root_props->set_num_dependents_need_push_properties(1); - root_props->mutable_base(); - - scoped_refptr<Layer> a = Layer::Create(); - a->SetLayerTreeHost(layer_tree_host_.get()); - proto::LayerProperties* a_props = updates.add_layers(); - a_props->set_id(a->id()); - a_props->set_needs_push_properties(false); - a_props->set_num_dependents_need_push_properties(0); - root->AddChild(a); - - scoped_refptr<Layer> b = Layer::Create(); - b->SetLayerTreeHost(layer_tree_host_.get()); - proto::LayerProperties* b_props = updates.add_layers(); - b_props->set_id(b->id()); - b_props->set_needs_push_properties(false); - b_props->set_num_dependents_need_push_properties(1); - root->AddChild(b); - - scoped_refptr<Layer> c = Layer::Create(); - c->SetLayerTreeHost(layer_tree_host_.get()); - proto::LayerProperties* c_props = updates.add_layers(); - c_props->set_id(c->id()); - c_props->set_needs_push_properties(true); - c_props->set_num_dependents_need_push_properties(0); - c_props->mutable_base(); - b->AddChild(c); - - LayerProtoConverter::DeserializeLayerProperties(root.get(), updates); - - EXPECT_TRUE(root->needs_push_properties()); - EXPECT_TRUE(root->descendant_needs_push_properties()); - - EXPECT_FALSE(a->needs_push_properties()); - EXPECT_FALSE(a->descendant_needs_push_properties()); - - EXPECT_FALSE(b->needs_push_properties()); - EXPECT_TRUE(b->descendant_needs_push_properties()); - - EXPECT_TRUE(c->needs_push_properties()); - EXPECT_FALSE(c->descendant_needs_push_properties()); - - // Recursively clear out LayerTreeHost. - root->SetLayerTreeHost(nullptr); + EXPECT_FALSE( + layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_root.get())); + EXPECT_FALSE( + layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_b.get())); + EXPECT_FALSE( + layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_b_mask.get())); + EXPECT_FALSE( + layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + layer_src_c.get())); + + // Only 2 of the layers should have been serialized. + ASSERT_EQ(2, layer_update.layers_size()); + for (int index = 0; index < layer_update.layers_size(); index++) + EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()), + dirty_layer_ids.end()); + layer_src_root->SetLayerTreeHost(nullptr); } TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) { diff --git a/cc/layers/layer_unittest.cc b/cc/layers/layer_unittest.cc index 73aebe9..c403f1a 100644 --- a/cc/layers/layer_unittest.cc +++ b/cc/layers/layer_unittest.cc @@ -52,24 +52,32 @@ using ::testing::_; Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ } while (false) -#define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ - code_to_test; \ - root->layer_tree_host()->BuildPropertyTreesForTesting(); \ - EXPECT_TRUE(root->subtree_property_changed()); \ - EXPECT_TRUE(root->needs_push_properties()); \ - EXPECT_TRUE(child->subtree_property_changed()); \ - EXPECT_TRUE(child->needs_push_properties()); \ - EXPECT_TRUE(grand_child->subtree_property_changed()); \ - EXPECT_TRUE(grand_child->needs_push_properties()); - -#define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ - code_to_test; \ - EXPECT_FALSE(root->subtree_property_changed()); \ - EXPECT_FALSE(root->needs_push_properties()); \ - EXPECT_FALSE(child->subtree_property_changed()); \ - EXPECT_FALSE(child->needs_push_properties()); \ - EXPECT_FALSE(grand_child->subtree_property_changed()); \ - EXPECT_FALSE(grand_child->needs_push_properties()); +#define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ + code_to_test; \ + root->layer_tree_host()->BuildPropertyTreesForTesting(); \ + EXPECT_TRUE(root->subtree_property_changed()); \ + EXPECT_TRUE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + root.get())); \ + EXPECT_TRUE(child->subtree_property_changed()); \ + EXPECT_TRUE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + child.get())); \ + EXPECT_TRUE(grand_child->subtree_property_changed()); \ + EXPECT_TRUE( \ + grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + grand_child.get())); + +#define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ + code_to_test; \ + EXPECT_FALSE(root->subtree_property_changed()); \ + EXPECT_FALSE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + root.get())); \ + EXPECT_FALSE(child->subtree_property_changed()); \ + EXPECT_FALSE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + child.get())); \ + EXPECT_FALSE(grand_child->subtree_property_changed()); \ + EXPECT_FALSE( \ + grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + grand_child.get())); namespace cc { @@ -109,7 +117,7 @@ class LayerSerializationTest : public testing::Test { // LayerUpdate. There are no descendants, so the serialization // of |src| is the only entry. proto::LayerUpdate layer_update; - EXPECT_FALSE(src->ToLayerPropertiesProto(&layer_update)); + src->ToLayerPropertiesProto(&layer_update); ASSERT_EQ(1, layer_update.layers_size()); proto::LayerProperties props = layer_update.layers(0); @@ -1319,11 +1327,12 @@ TEST_F(LayerTest, DeleteRemovedScrollParent) { EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); - child1->reset_needs_push_properties_for_testing(); + child1->ResetNeedsPushPropertiesForTesting(); EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); - EXPECT_TRUE(child1->needs_push_properties()); + EXPECT_TRUE( + layer_tree_host_->LayerNeedsPushPropertiesForTesting(child1.get())); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } @@ -1348,11 +1357,12 @@ TEST_F(LayerTest, DeleteRemovedScrollChild) { EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child1->RemoveFromParent()); - child2->reset_needs_push_properties_for_testing(); + child2->ResetNeedsPushPropertiesForTesting(); EXPECT_SET_NEEDS_COMMIT(1, child1 = nullptr); - EXPECT_TRUE(child2->needs_push_properties()); + EXPECT_TRUE( + layer_tree_host_->LayerNeedsPushPropertiesForTesting(child2.get())); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } @@ -2443,158 +2453,6 @@ TEST_F(LayerSerializationTest, RunNonDestructiveDeserializationMoveChildLaterTest(); } -TEST_F(LayerTest, SimplePropertiesSerialization) { - /* Testing serialization of properties for a tree that looks like this: - root+ - / \ - a* b*+[mask:*,replica] - / \ - c d* - Layers marked with * have changed properties. - Layers marked with + have descendants with changed properties. - Layer b also has a mask layer and a replica layer. - */ - scoped_refptr<Layer> layer_src_root = Layer::Create(); - scoped_refptr<Layer> layer_src_a = Layer::Create(); - scoped_refptr<Layer> layer_src_b = Layer::Create(); - scoped_refptr<Layer> layer_src_b_mask = Layer::Create(); - scoped_refptr<Layer> layer_src_b_replica = Layer::Create(); - scoped_refptr<Layer> layer_src_c = Layer::Create(); - scoped_refptr<Layer> layer_src_d = Layer::Create(); - layer_src_root->AddChild(layer_src_a); - layer_src_root->AddChild(layer_src_b); - layer_src_a->AddChild(layer_src_c); - layer_src_b->AddChild(layer_src_d); - layer_src_b->SetMaskLayer(layer_src_b_mask.get()); - layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); - - proto::LayerUpdate layer_update_root; - // Only layers with descendants that require pushing properties will - // return true from ToLayerPropertiesProto and AddChild will change the - // stacking order of child which will make it push properties. - EXPECT_TRUE(layer_src_root->ToLayerPropertiesProto(&layer_update_root)); - proto::LayerUpdate layer_update_a; - EXPECT_TRUE(layer_src_a->ToLayerPropertiesProto(&layer_update_a)); - proto::LayerUpdate layer_update_b; - EXPECT_TRUE(layer_src_b->ToLayerPropertiesProto(&layer_update_b)); - proto::LayerUpdate layer_update_c; - EXPECT_FALSE(layer_src_c->ToLayerPropertiesProto(&layer_update_c)); - proto::LayerUpdate layer_update_d; - EXPECT_FALSE(layer_src_d->ToLayerPropertiesProto(&layer_update_d)); - layer_update_root.Clear(); - layer_update_a.Clear(); - layer_update_b.Clear(); - layer_update_c.Clear(); - layer_update_d.Clear(); - - layer_src_a->SetNeedsPushProperties(); - layer_src_b->SetNeedsPushProperties(); - layer_src_b_mask->SetNeedsPushProperties(); - layer_src_d->SetNeedsPushProperties(); - - // Only layers with descendants that require pushing properties will - // return true from ToLayerPropertiesProto. - EXPECT_TRUE(layer_src_root->ToLayerPropertiesProto(&layer_update_root)); - EXPECT_FALSE(layer_src_a->ToLayerPropertiesProto(&layer_update_a)); - EXPECT_TRUE(layer_src_b->ToLayerPropertiesProto(&layer_update_b)); - proto::LayerUpdate layer_update_b_mask; - EXPECT_FALSE(layer_src_b_mask->ToLayerPropertiesProto(&layer_update_b_mask)); - proto::LayerUpdate layer_update_b_replica; - EXPECT_FALSE( - layer_src_b_replica->ToLayerPropertiesProto(&layer_update_b_replica)); - EXPECT_FALSE(layer_src_c->ToLayerPropertiesProto(&layer_update_c)); - EXPECT_FALSE(layer_src_d->ToLayerPropertiesProto(&layer_update_d)); - - // All flags for pushing properties should have been cleared. - EXPECT_FALSE(layer_src_root->needs_push_properties()); - EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_a->needs_push_properties()); - EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b->needs_push_properties()); - EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_c->needs_push_properties()); - EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_d->needs_push_properties()); - EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); - - // Only 5 of the layers should have been serialized. - ASSERT_EQ(1, layer_update_root.layers_size()); - EXPECT_EQ(layer_src_root->id(), layer_update_root.layers(0).id()); - proto::LayerProperties dest_root = layer_update_root.layers(0); - ASSERT_EQ(1, layer_update_a.layers_size()); - EXPECT_EQ(layer_src_a->id(), layer_update_a.layers(0).id()); - proto::LayerProperties dest_a = layer_update_a.layers(0); - ASSERT_EQ(1, layer_update_b.layers_size()); - EXPECT_EQ(layer_src_b->id(), layer_update_b.layers(0).id()); - proto::LayerProperties dest_b = layer_update_b.layers(0); - ASSERT_EQ(1, layer_update_b_mask.layers_size()); - EXPECT_EQ(layer_src_b_mask->id(), layer_update_b_mask.layers(0).id()); - proto::LayerProperties dest_b_mask = layer_update_b_mask.layers(0); - EXPECT_EQ(0, layer_update_b_replica.layers_size()); - EXPECT_EQ(0, layer_update_c.layers_size()); - ASSERT_EQ(1, layer_update_d.layers_size()); - EXPECT_EQ(layer_src_d->id(), layer_update_d.layers(0).id()); - proto::LayerProperties dest_d = layer_update_d.layers(0); - - // Ensure the properties and dependants metadata is correctly serialized. - EXPECT_FALSE(dest_root.needs_push_properties()); - EXPECT_EQ(2, dest_root.num_dependents_need_push_properties()); - EXPECT_FALSE(dest_root.has_base()); - - EXPECT_TRUE(dest_a.needs_push_properties()); - EXPECT_EQ(0, dest_a.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_a.has_base()); - - EXPECT_TRUE(dest_b.needs_push_properties()); - EXPECT_EQ(2, dest_b.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b.has_base()); - - EXPECT_TRUE(dest_d.needs_push_properties()); - EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_d.has_base()); - - EXPECT_TRUE(dest_b_mask.needs_push_properties()); - EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b_mask.has_base()); -} - -TEST_F(LayerSerializationTest, SimplePropertiesDeserialization) { - scoped_refptr<Layer> layer = Layer::Create(); - layer->SetLayerTreeHost(layer_tree_host_.get()); - proto::LayerProperties properties; - properties.set_id(layer->id()); - - properties.set_needs_push_properties(true); - properties.set_num_dependents_need_push_properties(2); - properties.mutable_base(); - layer->FromLayerPropertiesProto(properties); - EXPECT_TRUE(layer->needs_push_properties()); - EXPECT_TRUE(layer->descendant_needs_push_properties()); - - properties.set_needs_push_properties(false); - properties.mutable_base()->Clear(); - layer->FromLayerPropertiesProto(properties); - EXPECT_FALSE(layer->needs_push_properties()); - EXPECT_TRUE(layer->descendant_needs_push_properties()); - - properties.set_num_dependents_need_push_properties(0); - layer->FromLayerPropertiesProto(properties); - EXPECT_FALSE(layer->needs_push_properties()); - EXPECT_FALSE(layer->descendant_needs_push_properties()); - - properties.set_needs_push_properties(true); - properties.mutable_base(); - layer->FromLayerPropertiesProto(properties); - EXPECT_TRUE(layer->needs_push_properties()); - EXPECT_FALSE(layer->descendant_needs_push_properties()); - - layer->SetLayerTreeHost(nullptr); -} - TEST_F(LayerSerializationTest, NoMembersChanged) { RunNoMembersChangedTest(); } diff --git a/cc/proto/layer.proto b/cc/proto/layer.proto index 160ffa7..f6f3353 100644 --- a/cc/proto/layer.proto +++ b/cc/proto/layer.proto @@ -53,10 +53,6 @@ message LayerUpdate { message LayerProperties { // required optional int32 id = 1; - // required - optional bool needs_push_properties = 3; - // required - optional int32 num_dependents_need_push_properties = 4; // The properties below are only read if |needs_push_properties| is set. // The Layer base class and each descendant have different proto messages diff --git a/cc/proto/layer_tree_host.proto b/cc/proto/layer_tree_host.proto index d1d78e7..e324d1d 100644 --- a/cc/proto/layer_tree_host.proto +++ b/cc/proto/layer_tree_host.proto @@ -56,4 +56,5 @@ message LayerTreeHost { optional uint32 wheel_event_listener_properties = 34; optional bool have_scroll_event_handlers = 35; optional uint32 touch_event_listener_properties = 36; + repeated int32 layers_that_should_push_properties = 37; } diff --git a/cc/test/fake_layer_tree_host.cc b/cc/test/fake_layer_tree_host.cc index cef4b32..b0af310 100644 --- a/cc/test/fake_layer_tree_host.cc +++ b/cc/test/fake_layer_tree_host.cc @@ -86,7 +86,8 @@ LayerImpl* FakeLayerTreeHost::CommitAndCreateLayerImplTree() { scoped_ptr<LayerImpl> layer_impl = TreeSynchronizer::SynchronizeTrees( root_layer(), std::move(old_root_layer_impl), active_tree()); active_tree()->SetPropertyTrees(*property_trees()); - TreeSynchronizer::PushProperties(root_layer(), layer_impl.get()); + TreeSynchronizer::PushLayerProperties(root_layer()->layer_tree_host(), + active_tree()); active_tree()->SetRootLayer(std::move(layer_impl)); active_tree()->UpdatePropertyTreeScrollOffset(property_trees()); @@ -110,7 +111,8 @@ LayerImpl* FakeLayerTreeHost::CommitAndCreatePendingTree() { scoped_ptr<LayerImpl> layer_impl = TreeSynchronizer::SynchronizeTrees( root_layer(), std::move(old_root_layer_impl), pending_tree()); pending_tree()->SetPropertyTrees(*property_trees()); - TreeSynchronizer::PushProperties(root_layer(), layer_impl.get()); + TreeSynchronizer::PushLayerProperties(root_layer()->layer_tree_host(), + pending_tree()); pending_tree()->SetRootLayer(std::move(layer_impl)); pending_tree()->UpdatePropertyTreeScrollOffset(property_trees()); diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index e669e27..a39d8b6 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -466,7 +466,8 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { { TRACE_EVENT0("cc", "LayerTreeHost::PushProperties"); - TreeSynchronizer::PushProperties(root_layer(), sync_tree->root_layer()); + + TreeSynchronizer::PushLayerProperties(this, sync_tree); TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties"); DCHECK(host_impl->animation_host()); @@ -1222,6 +1223,23 @@ Layer* LayerTreeHost::LayerById(int id) const { return iter != layer_id_map_.end() ? iter->second : NULL; } +void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) { + layers_that_should_push_properties_.insert(layer); +} + +void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) { + layers_that_should_push_properties_.erase(layer); +} + +std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() { + return layers_that_should_push_properties_; +} + +bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) { + return layers_that_should_push_properties_.find(layer) != + layers_that_should_push_properties_.end(); +} + void LayerTreeHost::RegisterLayer(Layer* layer) { DCHECK(!LayerById(layer->id())); DCHECK(!in_paint_layer_contents_); @@ -1233,6 +1251,7 @@ void LayerTreeHost::UnregisterLayer(Layer* layer) { DCHECK(LayerById(layer->id())); DCHECK(!in_paint_layer_contents_); animation_host_->UnregisterLayer(layer->id(), LayerTreeType::ACTIVE); + RemoveLayerShouldPushProperties(layer); layer_id_map_.erase(layer->id()); } @@ -1394,8 +1413,8 @@ bool LayerTreeHost::IsRemoteClient() const { task_runner_provider_->HasImplThread(); } -void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) const { - // Not all fields are serialized, as they are eiher not needed for a commit, +void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) { + // Not all fields are serialized, as they are either not needed for a commit, // or implementation isn't ready yet. // Unsupported items: // - animations @@ -1422,7 +1441,11 @@ void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) const { meta_information_sequence_number_); LayerProtoConverter::SerializeLayerHierarchy(root_layer_, proto->mutable_root_layer()); - LayerProtoConverter::SerializeLayerProperties(root_layer_.get(), + // layers_that_should_push_properties_ should be serialized before layer + // properties because it is cleared during the properties serialization. + for (auto layer : layers_that_should_push_properties_) + proto->add_layers_that_should_push_properties(layer->id()); + LayerProtoConverter::SerializeLayerProperties(this, proto->mutable_layer_updates()); proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); debug_state_.ToProtobuf(proto->mutable_debug_state()); @@ -1491,6 +1514,8 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { LayerTreeHostCommon::CallFunctionForSubtree( root_layer(), [this](Layer* layer) { layer_id_map_[layer->id()] = layer; }); + for (auto layer_id : proto.layers_that_should_push_properties()) + layers_that_should_push_properties_.insert(layer_id_map_[layer_id]); LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), proto.layer_updates()); diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index f80cdb4..c82e9f6 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -357,6 +357,12 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events); Layer* LayerById(int id) const; + + void AddLayerShouldPushProperties(Layer* layer); + void RemoveLayerShouldPushProperties(Layer* layer); + std::unordered_set<Layer*>& LayersThatShouldPushProperties(); + bool LayerNeedsPushPropertiesForTesting(Layer* layer); + void RegisterLayer(Layer* layer); void UnregisterLayer(Layer* layer); // LayerTreeMutatorsClient implementation. @@ -401,7 +407,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { // Serializes the parts of this LayerTreeHost that is needed for a commit to a // protobuf message. Not all members are serialized as they are not helpful // for remote usage. - void ToProtobufForCommit(proto::LayerTreeHost* proto) const; + void ToProtobufForCommit(proto::LayerTreeHost* proto); // Deserializes the protobuf into this LayerTreeHost before a commit. The // expected input is a serialized remote LayerTreeHost. After deserializing @@ -580,6 +586,8 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { using LayerIdMap = std::unordered_map<int, Layer*>; LayerIdMap layer_id_map_; + // Set of layers that need to push properties. + std::unordered_set<Layer*> layers_that_should_push_properties_; uint32_t surface_id_namespace_; uint32_t next_surface_sequence_; diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index b22de54..bf706b6 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -1974,13 +1974,7 @@ void LayerTreeHostImpl::ActivateSyncTree() { active_tree_->root_layer()->PushLayerPropertyChangedForSubtree(); } - std::unordered_set<LayerImpl*> layers_that_should_push_properties = - pending_tree_->LayersThatShouldPushProperties(); - for (auto pending_layer : layers_that_should_push_properties) { - LayerImpl* active_layer = active_tree_->LayerById(pending_layer->id()); - DCHECK(active_layer); - pending_layer->PushPropertiesTo(active_layer); - } + TreeSynchronizer::PushLayerProperties(pending_tree(), active_tree()); pending_tree_->PushPropertiesTo(active_tree_.get()); if (pending_tree_->root_layer()) pending_tree_->property_trees()->ResetAllChangeTracking( diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index 25548da..673d586 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -2737,8 +2737,9 @@ class PushPropertiesCountingLayer : public Layer { void PushPropertiesTo(LayerImpl* layer) override { Layer::PushPropertiesTo(layer); push_properties_count_++; - if (persist_needs_push_properties_) - needs_push_properties_ = true; + if (persist_needs_push_properties_) { + layer_tree_host()->AddLayerShouldPushProperties(this); + } } // Something to make this layer push properties, but no other layer. @@ -2823,32 +2824,36 @@ class LayerTreeHostTestLayersPushProperties : public LayerTreeHostTest { // The scrollbar layer always needs to be pushed. if (root_->layer_tree_host()) { - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(root_->needs_push_properties()); + EXPECT_FALSE(root_->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + root_.get())); } if (child2_->layer_tree_host()) { - EXPECT_TRUE(child2_->descendant_needs_push_properties()); - EXPECT_FALSE(child2_->needs_push_properties()); + EXPECT_FALSE( + child2_->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child2_.get())); } if (leaf_always_pushing_layer_->layer_tree_host()) { - EXPECT_FALSE( - leaf_always_pushing_layer_->descendant_needs_push_properties()); - EXPECT_TRUE(leaf_always_pushing_layer_->needs_push_properties()); + EXPECT_TRUE(leaf_always_pushing_layer_->layer_tree_host() + ->LayerNeedsPushPropertiesForTesting( + leaf_always_pushing_layer_.get())); } // child_ and grandchild_ don't persist their need to push properties. if (child_->layer_tree_host()) { - EXPECT_FALSE(child_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); + EXPECT_FALSE( + child_->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); } if (grandchild_->layer_tree_host()) { - EXPECT_FALSE(grandchild_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild_->needs_push_properties()); + EXPECT_FALSE( + grandchild_->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild_.get())); } if (other_root_->layer_tree_host()) { - EXPECT_FALSE(other_root_->descendant_needs_push_properties()); - EXPECT_FALSE(other_root_->needs_push_properties()); + EXPECT_FALSE( + other_root_->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + other_root_.get())); } switch (num_commits_) { @@ -3203,8 +3208,8 @@ class LayerTreeHostTestPropertyChangesDuringUpdateArePushed scrollbar_layer_->SetBounds(gfx::Size(30, 30)); - EXPECT_TRUE(scrollbar_layer_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + scrollbar_layer_.get())); layer_tree_host()->SetNeedsCommit(); scrollbar_layer_->reset_push_properties_count(); @@ -3248,8 +3253,10 @@ class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest { // avoid causing a second commit to be scheduled. If a property change // is made during this, however, it needs to be pushed in the upcoming // commit. - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); EXPECT_EQ(0, root_->NumDescendantsThatDrawContent()); root_->reset_push_properties_count(); child_->reset_push_properties_count(); @@ -3257,15 +3264,19 @@ class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest { EXPECT_EQ(1, root_->NumDescendantsThatDrawContent()); EXPECT_EQ(0u, root_->push_properties_count()); EXPECT_EQ(0u, child_->push_properties_count()); - EXPECT_TRUE(root_->needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); + EXPECT_TRUE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); break; } case 2: EXPECT_EQ(1u, root_->push_properties_count()); EXPECT_EQ(1u, child_->push_properties_count()); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); EndTest(); break; } @@ -3330,24 +3341,18 @@ class LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush int last_source_frame_number = layer_tree_host()->source_frame_number() - 1; switch (last_source_frame_number) { case 0: - // All layers except root will need push properties as they are added - // as a child to some other layer which changes their stacking order. - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); - + // All layers will need push properties as we set their layer tree host layer_tree_host()->SetRootLayer(root_); - - // Now, even the root will need to push properties. - EXPECT_TRUE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); + EXPECT_TRUE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); break; case 1: EndTest(); @@ -3368,71 +3373,71 @@ class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion layer_tree_host()->SetRootLayer(root_); break; case 1: - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); grandchild1_->RemoveFromParent(); grandchild1_->SetPosition(gfx::PointF(1.f, 1.f)); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); child_->AddChild(grandchild1_); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); grandchild2_->SetPosition(gfx::PointF(1.f, 1.f)); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); // grandchild2_ will still need a push properties. grandchild1_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); // grandchild3_ does not need a push properties, so recursing should // no longer be needed. grandchild2_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); EndTest(); break; } @@ -3453,33 +3458,33 @@ class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence grandchild2_->set_persist_needs_push_properties(true); break; case 1: - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); // grandchild2_ will still need a push properties. grandchild1_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); // grandchild3_ does not need a push properties, so recursing should // no longer be needed. grandchild2_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); EndTest(); break; } @@ -3499,16 +3504,16 @@ class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree layer_tree_host()->SetRootLayer(root_); break; case 1: - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); // Change grandchildren while their parent is not in the tree. child_->RemoveFromParent(); @@ -3516,37 +3521,37 @@ class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree grandchild2_->SetPosition(gfx::PointF(1.f, 1.f)); root_->AddChild(child_); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); grandchild1_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); grandchild2_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); grandchild3_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); EndTest(); break; @@ -3567,50 +3572,50 @@ class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild layer_tree_host()->SetRootLayer(root_); break; case 1: - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); child_->SetPosition(gfx::PointF(1.f, 1.f)); grandchild1_->SetPosition(gfx::PointF(1.f, 1.f)); grandchild2_->SetPosition(gfx::PointF(1.f, 1.f)); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); grandchild1_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); grandchild2_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); child_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); EndTest(); break; @@ -3631,50 +3636,50 @@ class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent layer_tree_host()->SetRootLayer(root_); break; case 1: - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); - EXPECT_FALSE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); grandchild1_->SetPosition(gfx::PointF(1.f, 1.f)); grandchild2_->SetPosition(gfx::PointF(1.f, 1.f)); child_->SetPosition(gfx::PointF(1.f, 1.f)); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild1_->needs_push_properties()); - EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); - EXPECT_TRUE(grandchild2_->needs_push_properties()); - EXPECT_FALSE(grandchild2_->descendant_needs_push_properties()); - EXPECT_FALSE(grandchild3_->needs_push_properties()); - EXPECT_FALSE(grandchild3_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild1_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild2_.get())); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + grandchild3_.get())); grandchild1_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_TRUE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); grandchild2_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_TRUE(root_->descendant_needs_push_properties()); - EXPECT_TRUE(child_->needs_push_properties()); - EXPECT_FALSE(child_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); + EXPECT_TRUE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_.get())); child_->RemoveFromParent(); - EXPECT_FALSE(root_->needs_push_properties()); - EXPECT_FALSE(root_->descendant_needs_push_properties()); + EXPECT_FALSE( + layer_tree_host()->LayerNeedsPushPropertiesForTesting(root_.get())); EndTest(); break; @@ -3858,7 +3863,8 @@ class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest { switch (layer_tree_host()->source_frame_number()) { case 1: // The layer type used does not need to push properties every frame. - EXPECT_FALSE(child_layer_->needs_push_properties()); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_layer_.get())); // Change the bounds of the child layer, but make it skipped // by CalculateDrawProperties. @@ -3867,7 +3873,8 @@ class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest { break; case 2: // The bounds of the child layer were pushed to the impl side. - EXPECT_FALSE(child_layer_->needs_push_properties()); + EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( + child_layer_.get())); EndTest(); break; diff --git a/cc/trees/layer_tree_host_unittest_scroll.cc b/cc/trees/layer_tree_host_unittest_scroll.cc index 024e65b..b056a76 100644 --- a/cc/trees/layer_tree_host_unittest_scroll.cc +++ b/cc/trees/layer_tree_host_unittest_scroll.cc @@ -949,13 +949,17 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest { Layer* scroll_layer = layer_tree_host()->outer_viewport_scroll_layer(); switch (layer_tree_host()->source_frame_number()) { case 0: - EXPECT_TRUE(scroll_layer->needs_push_properties()); + EXPECT_TRUE( + scroll_layer->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + scroll_layer)); break; case 1: // Even if this layer doesn't need push properties, it should // still pick up scrolls that happen on the active layer during // commit. - EXPECT_FALSE(scroll_layer->needs_push_properties()); + EXPECT_FALSE( + scroll_layer->layer_tree_host()->LayerNeedsPushPropertiesForTesting( + scroll_layer)); break; } } diff --git a/cc/trees/layer_tree_host_unittest_serialization.cc b/cc/trees/layer_tree_host_unittest_serialization.cc index db166ed..3e3e0a1 100644 --- a/cc/trees/layer_tree_host_unittest_serialization.cc +++ b/cc/trees/layer_tree_host_unittest_serialization.cc @@ -49,6 +49,9 @@ class LayerTreeHostSerializationTest : public testing::Test { void VerifySerializationAndDeserialization() { proto::LayerTreeHost proto; + + std::unordered_set<Layer*> layers_that_should_push_properties_src = + layer_tree_host_src_->LayersThatShouldPushProperties(); layer_tree_host_src_->ToProtobufForCommit(&proto); layer_tree_host_dst_->FromProtobufForCommit(proto); @@ -102,6 +105,10 @@ class LayerTreeHostSerializationTest : public testing::Test { EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_); EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_, layer_tree_host_dst_->next_commit_forces_redraw_); + for (auto layer : layers_that_should_push_properties_src) { + EXPECT_TRUE(layer_tree_host_dst_->LayerNeedsPushPropertiesForTesting( + layer_tree_host_dst_->LayerById(layer->id()))); + } if (layer_tree_host_src_->hud_layer_) { EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(), diff --git a/cc/trees/tree_synchronizer.cc b/cc/trees/tree_synchronizer.cc index af87056..a134bb4 100644 --- a/cc/trees/tree_synchronizer.cc +++ b/cc/trees/tree_synchronizer.cc @@ -13,6 +13,8 @@ #include "base/trace_event/trace_event.h" #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" +#include "cc/trees/layer_tree_host.h" +#include "cc/trees/layer_tree_impl.h" namespace cc { @@ -129,55 +131,6 @@ scoped_ptr<LayerImpl> SynchronizeTreesRecursive( new_layers, old_layers, layer, tree_impl); } -void TreeSynchronizer::PushPropertiesInternal( - Layer* layer, - LayerImpl* layer_impl, - int* num_dependents_need_push_properties_for_parent) { - if (!layer) { - DCHECK(!layer_impl); - return; - } - - DCHECK_EQ(layer->id(), layer_impl->id()); - - bool push_layer = layer->needs_push_properties(); - bool recurse_on_children_and_dependents = - layer->descendant_needs_push_properties(); - - if (push_layer) - layer->PushPropertiesTo(layer_impl); - - int num_dependents_need_push_properties = 0; - if (recurse_on_children_and_dependents) { - PushPropertiesInternal(layer->mask_layer(), - layer_impl->mask_layer(), - &num_dependents_need_push_properties); - PushPropertiesInternal(layer->replica_layer(), - layer_impl->replica_layer(), - &num_dependents_need_push_properties); - - const OwnedLayerImplList& impl_children = layer_impl->children(); - DCHECK_EQ(layer->children().size(), impl_children.size()); - - for (size_t i = 0; i < layer->children().size(); ++i) { - PushPropertiesInternal(layer->child_at(i), impl_children[i].get(), - &num_dependents_need_push_properties); - } - - // When PushPropertiesTo completes for a layer, it may still keep - // its needs_push_properties() state if the layer must push itself - // every PushProperties tree walk. Here we keep track of those layers, and - // ensure that their ancestors know about them for the next PushProperties - // tree walk. - layer->num_dependents_need_push_properties_ = - num_dependents_need_push_properties; - } - - bool add_self_to_parent = num_dependents_need_push_properties > 0 || - layer->needs_push_properties(); - *num_dependents_need_push_properties_for_parent += add_self_to_parent ? 1 : 0; -} - static void CheckScrollAndClipPointersRecursive(Layer* layer, LayerImpl* layer_impl) { DCHECK_EQ(!!layer, !!layer_impl); @@ -234,13 +187,32 @@ static void CheckScrollAndClipPointersRecursive(Layer* layer, } } -void TreeSynchronizer::PushProperties(Layer* layer, - LayerImpl* layer_impl) { - int num_dependents_need_push_properties = 0; - PushPropertiesInternal( - layer, layer_impl, &num_dependents_need_push_properties); +template <typename LayerType> +static void PushLayerPropertiesInternal( + std::unordered_set<LayerType*> layers_that_should_push_properties, + LayerTreeImpl* impl_tree) { + for (auto layer : layers_that_should_push_properties) { + LayerImpl* layer_impl = impl_tree->LayerById(layer->id()); + DCHECK(layer_impl); + layer->PushPropertiesTo(layer_impl); + } +} + +void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree, + LayerTreeImpl* active_tree) { + PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(), + active_tree); +} + +void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, + LayerTreeImpl* impl_tree) { + PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), + impl_tree); + #if DCHECK_IS_ON() - CheckScrollAndClipPointersRecursive(layer, layer_impl); + if (host_tree->root_layer() && impl_tree->root_layer()) + CheckScrollAndClipPointersRecursive(host_tree->root_layer(), + impl_tree->root_layer()); #endif } diff --git a/cc/trees/tree_synchronizer.h b/cc/trees/tree_synchronizer.h index 2e6e8f0..3c87374 100644 --- a/cc/trees/tree_synchronizer.h +++ b/cc/trees/tree_synchronizer.h @@ -12,6 +12,7 @@ namespace cc { class LayerImpl; +class LayerTreeHost; class LayerTreeImpl; class Layer; @@ -28,21 +29,14 @@ class CC_EXPORT TreeSynchronizer { LayerImpl* layer_root, scoped_ptr<LayerImpl> old_layer_impl_root, LayerTreeImpl* tree_impl); - - // Pushes properties from a Layer or LayerImpl tree to a structurally - // equivalent LayerImpl tree. - static void PushProperties(Layer* layer_root, - LayerImpl* layer_impl_root); - static void PushProperties(LayerImpl* layer_root, LayerImpl* layer_impl_root); + static void PushLayerProperties(LayerTreeImpl* pending_tree, + LayerTreeImpl* active_tree); + static void PushLayerProperties(LayerTreeHost* host_tree, + LayerTreeImpl* impl_tree); private: TreeSynchronizer(); // Not instantiable. - static void PushPropertiesInternal( - Layer* layer, - LayerImpl* layer_impl, - int* num_dependents_need_push_properties_for_parent); - DISALLOW_COPY_AND_ASSIGN(TreeSynchronizer); }; diff --git a/cc/trees/tree_synchronizer_unittest.cc b/cc/trees/tree_synchronizer_unittest.cc index ee4041a..4e30719 100644 --- a/cc/trees/tree_synchronizer_unittest.cc +++ b/cc/trees/tree_synchronizer_unittest.cc @@ -243,8 +243,8 @@ TEST_F(TreeSynchronizerTest, SyncSimpleTreeReusingLayers) { host_->active_tree()); // We have to push properties to pick up the destruction list pointer. - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_->active_tree()); // Add a new layer to the Layer side layer_tree_root->children()[0]->AddChild( @@ -288,7 +288,8 @@ TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndTrackStackingOrderChange) { host_->active_tree()); // We have to push properties to pick up the destruction list pointer. - TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl_tree_root); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_->active_tree()); host_->active_tree()->ResetAllChangeTracking( PropertyTrees::ResetFlags::ALL_TREES); @@ -303,7 +304,8 @@ TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndTrackStackingOrderChange) { ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, host_->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl_tree_root); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_->active_tree()); // Check that the impl thread properly tracked the change. EXPECT_FALSE(layer_impl_tree_root->LayerPropertyChanged()); @@ -338,8 +340,8 @@ TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndProperties) { layer_impl_tree_root.get(), host_->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_->active_tree()); // Check that the property values we set on the Layer tree are reflected in // the LayerImpl tree. @@ -389,8 +391,8 @@ TEST_F(TreeSynchronizerTest, ReuseLayerImplsAfterStructuralChange) { host_->active_tree()); // We have to push properties to pick up the destruction list pointer. - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_->active_tree()); // Now restructure the tree to look like this: // root --- D ---+--- A @@ -444,8 +446,8 @@ TEST_F(TreeSynchronizerTest, SyncSimpleTreeThenDestroy) { host_->active_tree()); // We have to push properties to pick up the destruction list pointer. - TreeSynchronizer::PushProperties(old_layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(old_layer_tree_root->layer_tree_host(), + host_->active_tree()); // Remove all children on the Layer side. old_layer_tree_root->RemoveAllChildren(); @@ -562,8 +564,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollParent) { scoped_ptr<LayerImpl> layer_impl_tree_root = TreeSynchronizer::SynchronizeTrees( layer_tree_root.get(), nullptr, host_impl->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_impl->active_tree()); { SCOPED_TRACE("case one"); ExpectTreesAreIdentical(layer_tree_root.get(), @@ -576,8 +578,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollParent) { layer_impl_tree_root = TreeSynchronizer::SynchronizeTrees( layer_tree_root.get(), std::move(layer_impl_tree_root), host_impl->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_impl->active_tree()); { SCOPED_TRACE("case two"); ExpectTreesAreIdentical(layer_tree_root.get(), @@ -592,8 +594,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollParent) { layer_impl_tree_root = TreeSynchronizer::SynchronizeTrees( layer_tree_root.get(), std::move(layer_impl_tree_root), host_impl->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_impl->active_tree()); { SCOPED_TRACE("case three"); ExpectTreesAreIdentical(layer_tree_root.get(), @@ -631,8 +633,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeClipParent) { scoped_ptr<LayerImpl> layer_impl_tree_root = TreeSynchronizer::SynchronizeTrees( layer_tree_root.get(), nullptr, host_impl->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_impl->active_tree()); ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root.get(), host_impl->active_tree()); @@ -644,8 +646,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeClipParent) { layer_impl_tree_root = TreeSynchronizer::SynchronizeTrees( layer_tree_root.get(), std::move(layer_impl_tree_root), host_impl->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_impl->active_tree()); ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root.get(), host_impl->active_tree()); @@ -657,8 +659,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeClipParent) { layer_impl_tree_root = TreeSynchronizer::SynchronizeTrees( layer_tree_root.get(), std::move(layer_impl_tree_root), host_impl->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_impl->active_tree()); ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root.get(), host_impl->active_tree()); @@ -669,8 +671,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeClipParent) { layer_impl_tree_root = TreeSynchronizer::SynchronizeTrees( layer_tree_root.get(), std::move(layer_impl_tree_root), host_impl->active_tree()); - TreeSynchronizer::PushProperties(layer_tree_root.get(), - layer_impl_tree_root.get()); + TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), + host_impl->active_tree()); ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root.get(), host_impl->active_tree()); |