Chromium Code Reviews| Index: cc/layers/layer.cc |
| diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc |
| index 82978daa03633a23d52b405414b4be0ead50b08c..6dc867132a06861319237824ac0299c4613b6721 100644 |
| --- a/cc/layers/layer.cc |
| +++ b/cc/layers/layer.cc |
| @@ -47,6 +47,7 @@ Layer::Layer() |
| parent_(NULL), |
| layer_tree_host_(NULL), |
| scroll_clip_layer_id_(INVALID_ID), |
| + num_descendants_that_draw_content_(0), |
| should_scroll_on_main_thread_(false), |
| have_wheel_event_handlers_(false), |
| have_scroll_event_handlers_(false), |
| @@ -55,6 +56,7 @@ Layer::Layer() |
| is_root_for_isolated_group_(false), |
| is_container_for_fixed_position_layers_(false), |
| is_drawable_(false), |
| + draws_content_(false), |
| hide_layer_and_subtree_(false), |
| masks_to_bounds_(false), |
| contents_opaque_(false), |
| @@ -250,6 +252,8 @@ void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) { |
| index = std::min(index, children_.size()); |
| children_.insert(children_.begin() + index, child); |
| + AddDrawableDescendants(child->NumDescendantsThatDrawContent() + |
| + (child->DrawsContent() ? 1 : 0)); |
| SetNeedsFullTreeSync(); |
| } |
| @@ -280,6 +284,8 @@ void Layer::RemoveChildOrDependent(Layer* child) { |
| continue; |
| child->SetParent(NULL); |
| + RemoveDrawableDescendants(child->NumDescendantsThatDrawContent() + |
| + (child->DrawsContent() ? 1 : 0)); |
| children_.erase(iter); |
| SetNeedsFullTreeSync(); |
| return; |
| @@ -779,6 +785,7 @@ void Layer::SetIsDrawable(bool is_drawable) { |
| return; |
| is_drawable_ = is_drawable; |
| + UpdateDrawsContent(true); |
| SetNeedsCommit(); |
| } |
| @@ -900,6 +907,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { |
| layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
| DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| layer->Set3dSortingContextId(sorting_context_id_); |
| + layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
| layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| @@ -1006,7 +1014,28 @@ scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| } |
| bool Layer::DrawsContent() const { |
| - return is_drawable_; |
| + return draws_content_; |
| +} |
| + |
| +void Layer::SetDrawsContent(bool draws_content) { |
| + if (draws_content == draws_content_) |
| + return; |
| + if (parent()) { |
| + if (draws_content) { |
| + parent()->AddDrawableDescendants(1); |
| + } else { |
| + parent()->RemoveDrawableDescendants(1); |
| + } |
| + } |
| + draws_content_ = draws_content; |
| +} |
| + |
| +void Layer::UpdateDrawsContent(bool draws_content) { |
|
danakj
2014/07/14 15:49:23
I like your idea about splitting this, how about t
awoloszyn
2014/07/14 19:38:33
Done.
|
| + SetDrawsContent(draws_content && is_drawable_); |
| +} |
| + |
| +int Layer::NumDescendantsThatDrawContent() const { |
| + return num_descendants_that_draw_content_; |
| } |
| void Layer::SavePaintProperties() { |
| @@ -1189,6 +1218,28 @@ void Layer::RemoveFromClipTree() { |
| clip_parent_ = NULL; |
| } |
| +void Layer::AddDrawableDescendants(int num) { |
|
danakj
2014/07/14 15:49:23
You only need one method here, the only difference
awoloszyn
2014/07/14 19:38:33
Done.
|
| + DCHECK_GE(num, 0); |
| + DCHECK_GE(num_descendants_that_draw_content_, 0); |
| + if (num == 0) |
| + return; |
| + num_descendants_that_draw_content_ += num; |
| + SetNeedsCommit(); |
| + if (parent()) |
| + parent()->AddDrawableDescendants(num); |
| +} |
| + |
| +void Layer::RemoveDrawableDescendants(int num) { |
| + DCHECK_GE(num, 0); |
| + if (num == 0) |
| + return; |
| + num_descendants_that_draw_content_ -= num; |
| + DCHECK_GE(num_descendants_that_draw_content_, 0); |
| + SetNeedsCommit(); |
| + if (parent()) |
| + parent()->RemoveDrawableDescendants(num); |
| +} |
| + |
| void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| benchmark->RunOnLayer(this); |
| } |