Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/layer.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 : needs_push_properties_(false), | 40 : needs_push_properties_(false), |
| 41 num_dependents_need_push_properties_(false), | 41 num_dependents_need_push_properties_(false), |
| 42 stacking_order_changed_(false), | 42 stacking_order_changed_(false), |
| 43 // Layer IDs start from 1. | 43 // Layer IDs start from 1. |
| 44 layer_id_(g_next_layer_id.GetNext() + 1), | 44 layer_id_(g_next_layer_id.GetNext() + 1), |
| 45 ignore_set_needs_commit_(false), | 45 ignore_set_needs_commit_(false), |
| 46 sorting_context_id_(0), | 46 sorting_context_id_(0), |
| 47 parent_(NULL), | 47 parent_(NULL), |
| 48 layer_tree_host_(NULL), | 48 layer_tree_host_(NULL), |
| 49 scroll_clip_layer_id_(INVALID_ID), | 49 scroll_clip_layer_id_(INVALID_ID), |
| 50 num_descendants_that_draw_content_(0), | |
| 50 should_scroll_on_main_thread_(false), | 51 should_scroll_on_main_thread_(false), |
| 51 have_wheel_event_handlers_(false), | 52 have_wheel_event_handlers_(false), |
| 52 have_scroll_event_handlers_(false), | 53 have_scroll_event_handlers_(false), |
| 53 user_scrollable_horizontal_(true), | 54 user_scrollable_horizontal_(true), |
| 54 user_scrollable_vertical_(true), | 55 user_scrollable_vertical_(true), |
| 55 is_root_for_isolated_group_(false), | 56 is_root_for_isolated_group_(false), |
| 56 is_container_for_fixed_position_layers_(false), | 57 is_container_for_fixed_position_layers_(false), |
| 57 is_drawable_(false), | 58 is_drawable_(false), |
| 59 draws_content_(false), | |
| 58 hide_layer_and_subtree_(false), | 60 hide_layer_and_subtree_(false), |
| 59 masks_to_bounds_(false), | 61 masks_to_bounds_(false), |
| 60 contents_opaque_(false), | 62 contents_opaque_(false), |
| 61 double_sided_(true), | 63 double_sided_(true), |
| 62 should_flatten_transform_(true), | 64 should_flatten_transform_(true), |
| 63 use_parent_backface_visibility_(false), | 65 use_parent_backface_visibility_(false), |
| 64 draw_checkerboard_for_missing_tiles_(false), | 66 draw_checkerboard_for_missing_tiles_(false), |
| 65 force_render_surface_(false), | 67 force_render_surface_(false), |
| 66 transform_is_invertible_(true), | 68 transform_is_invertible_(true), |
| 67 background_color_(0), | 69 background_color_(0), |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 } | 245 } |
| 244 | 246 |
| 245 void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) { | 247 void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) { |
| 246 DCHECK(IsPropertyChangeAllowed()); | 248 DCHECK(IsPropertyChangeAllowed()); |
| 247 child->RemoveFromParent(); | 249 child->RemoveFromParent(); |
| 248 child->SetParent(this); | 250 child->SetParent(this); |
| 249 child->stacking_order_changed_ = true; | 251 child->stacking_order_changed_ = true; |
| 250 | 252 |
| 251 index = std::min(index, children_.size()); | 253 index = std::min(index, children_.size()); |
| 252 children_.insert(children_.begin() + index, child); | 254 children_.insert(children_.begin() + index, child); |
| 255 AddDrawableDescendants(child->NumDescendantsThatDrawContent() + | |
| 256 (child->DrawsContent() ? 1 : 0)); | |
| 253 SetNeedsFullTreeSync(); | 257 SetNeedsFullTreeSync(); |
| 254 } | 258 } |
| 255 | 259 |
| 256 void Layer::RemoveFromParent() { | 260 void Layer::RemoveFromParent() { |
| 257 DCHECK(IsPropertyChangeAllowed()); | 261 DCHECK(IsPropertyChangeAllowed()); |
| 258 if (parent_) | 262 if (parent_) |
| 259 parent_->RemoveChildOrDependent(this); | 263 parent_->RemoveChildOrDependent(this); |
| 260 } | 264 } |
| 261 | 265 |
| 262 void Layer::RemoveChildOrDependent(Layer* child) { | 266 void Layer::RemoveChildOrDependent(Layer* child) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 273 return; | 277 return; |
| 274 } | 278 } |
| 275 | 279 |
| 276 for (LayerList::iterator iter = children_.begin(); | 280 for (LayerList::iterator iter = children_.begin(); |
| 277 iter != children_.end(); | 281 iter != children_.end(); |
| 278 ++iter) { | 282 ++iter) { |
| 279 if (iter->get() != child) | 283 if (iter->get() != child) |
| 280 continue; | 284 continue; |
| 281 | 285 |
| 282 child->SetParent(NULL); | 286 child->SetParent(NULL); |
| 287 AddDrawableDescendants(-child->NumDescendantsThatDrawContent() - | |
| 288 (child->DrawsContent() ? 1 : 0)); | |
| 283 children_.erase(iter); | 289 children_.erase(iter); |
| 284 SetNeedsFullTreeSync(); | 290 SetNeedsFullTreeSync(); |
| 285 return; | 291 return; |
| 286 } | 292 } |
| 287 } | 293 } |
| 288 | 294 |
| 289 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { | 295 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { |
| 290 DCHECK(reference); | 296 DCHECK(reference); |
| 291 DCHECK_EQ(reference->parent(), this); | 297 DCHECK_EQ(reference->parent(), this); |
| 292 DCHECK(IsPropertyChangeAllowed()); | 298 DCHECK(IsPropertyChangeAllowed()); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 should_flatten_transform_ = should_flatten; | 778 should_flatten_transform_ = should_flatten; |
| 773 SetNeedsCommit(); | 779 SetNeedsCommit(); |
| 774 } | 780 } |
| 775 | 781 |
| 776 void Layer::SetIsDrawable(bool is_drawable) { | 782 void Layer::SetIsDrawable(bool is_drawable) { |
| 777 DCHECK(IsPropertyChangeAllowed()); | 783 DCHECK(IsPropertyChangeAllowed()); |
| 778 if (is_drawable_ == is_drawable) | 784 if (is_drawable_ == is_drawable) |
| 779 return; | 785 return; |
| 780 | 786 |
| 781 is_drawable_ = is_drawable; | 787 is_drawable_ = is_drawable; |
| 782 SetNeedsCommit(); | 788 UpdateDrawsContent(HasDrawableContent()); |
| 783 } | 789 } |
| 784 | 790 |
| 785 void Layer::SetHideLayerAndSubtree(bool hide) { | 791 void Layer::SetHideLayerAndSubtree(bool hide) { |
| 786 DCHECK(IsPropertyChangeAllowed()); | 792 DCHECK(IsPropertyChangeAllowed()); |
| 787 if (hide_layer_and_subtree_ == hide) | 793 if (hide_layer_and_subtree_ == hide) |
| 788 return; | 794 return; |
| 789 | 795 |
| 790 hide_layer_and_subtree_ = hide; | 796 hide_layer_and_subtree_ = hide; |
| 791 SetNeedsCommit(); | 797 SetNeedsCommit(); |
| 792 } | 798 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 893 layer->SetPosition(position_); | 899 layer->SetPosition(position_); |
| 894 layer->SetIsContainerForFixedPositionLayers( | 900 layer->SetIsContainerForFixedPositionLayers( |
| 895 IsContainerForFixedPositionLayers()); | 901 IsContainerForFixedPositionLayers()); |
| 896 layer->SetPositionConstraint(position_constraint_); | 902 layer->SetPositionConstraint(position_constraint_); |
| 897 layer->SetShouldFlattenTransform(should_flatten_transform_); | 903 layer->SetShouldFlattenTransform(should_flatten_transform_); |
| 898 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 904 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 899 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 905 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
| 900 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 906 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
| 901 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 907 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| 902 layer->Set3dSortingContextId(sorting_context_id_); | 908 layer->Set3dSortingContextId(sorting_context_id_); |
| 909 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | |
| 903 | 910 |
| 904 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 911 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 905 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 912 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 906 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 913 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 907 | 914 |
| 908 LayerImpl* scroll_parent = NULL; | 915 LayerImpl* scroll_parent = NULL; |
| 909 if (scroll_parent_) { | 916 if (scroll_parent_) { |
| 910 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 917 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 911 DCHECK(scroll_parent); | 918 DCHECK(scroll_parent); |
| 912 } | 919 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 | 1006 |
| 1000 needs_push_properties_ = false; | 1007 needs_push_properties_ = false; |
| 1001 num_dependents_need_push_properties_ = 0; | 1008 num_dependents_need_push_properties_ = 0; |
| 1002 } | 1009 } |
| 1003 | 1010 |
| 1004 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1011 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 1005 return LayerImpl::Create(tree_impl, layer_id_); | 1012 return LayerImpl::Create(tree_impl, layer_id_); |
| 1006 } | 1013 } |
| 1007 | 1014 |
| 1008 bool Layer::DrawsContent() const { | 1015 bool Layer::DrawsContent() const { |
| 1016 return draws_content_; | |
| 1017 } | |
| 1018 | |
| 1019 bool Layer::HasDrawableContent() const { | |
| 1009 return is_drawable_; | 1020 return is_drawable_; |
| 1010 } | 1021 } |
| 1011 | 1022 |
| 1023 void Layer::UpdateDrawsContent(bool has_drawable_content) { | |
| 1024 bool draws_content = has_drawable_content; | |
|
danakj
2014/08/06 14:57:07
can you DCHECK(is_drawable_ || !has_drawable_conte
awoloszyn
2014/08/08 15:53:20
I will DCHECK(HasDrawableContent() || !has_drawabl
danakj
2014/08/08 16:04:04
Oh I see. Can we just make HUD layer's constructor
| |
| 1025 if (draws_content == draws_content_) | |
| 1026 return; | |
| 1027 | |
| 1028 if (HasDelegatedContent()) { | |
| 1029 // As per the comment that was originally in | |
|
danakj
2014/08/06 14:57:07
I think you can drop the mention of Precalculate,
awoloszyn
2014/08/08 15:53:20
Done.
| |
| 1030 // LayerTreeHost::PrecalculateMetaInformation: | |
| 1031 // Layers with delegated content need to be treated as if they have as | |
| 1032 // many children as the number of layers they own delegated quads for. | |
| 1033 // Since we don't know this number right now, we choose one that acts like | |
| 1034 // infinity for our purposes. | |
| 1035 AddDrawableDescendants(draws_content ? 1000 : -1000); | |
| 1036 } | |
| 1037 | |
| 1038 if (parent()) { | |
| 1039 if (draws_content) { | |
| 1040 parent()->AddDrawableDescendants(1); | |
|
danakj
2014/08/06 14:57:07
draws_content ? 1 : -1 like you did above for dele
awoloszyn
2014/08/08 15:53:20
Done.
| |
| 1041 } else { | |
| 1042 parent()->AddDrawableDescendants(-1); | |
| 1043 } | |
| 1044 } | |
| 1045 draws_content_ = draws_content; | |
| 1046 SetNeedsCommit(); | |
| 1047 } | |
| 1048 | |
| 1049 int Layer::NumDescendantsThatDrawContent() const { | |
| 1050 return num_descendants_that_draw_content_; | |
| 1051 } | |
| 1052 | |
| 1012 void Layer::SavePaintProperties() { | 1053 void Layer::SavePaintProperties() { |
| 1013 DCHECK(layer_tree_host_); | 1054 DCHECK(layer_tree_host_); |
| 1014 | 1055 |
| 1015 // TODO(reveman): Save all layer properties that we depend on not | 1056 // TODO(reveman): Save all layer properties that we depend on not |
| 1016 // changing until PushProperties() has been called. crbug.com/231016 | 1057 // changing until PushProperties() has been called. crbug.com/231016 |
| 1017 paint_properties_.bounds = bounds_; | 1058 paint_properties_.bounds = bounds_; |
| 1018 paint_properties_.source_frame_number = | 1059 paint_properties_.source_frame_number = |
| 1019 layer_tree_host_->source_frame_number(); | 1060 layer_tree_host_->source_frame_number(); |
| 1020 } | 1061 } |
| 1021 | 1062 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1182 it != clip_children_->end(); ++it) | 1223 it != clip_children_->end(); ++it) |
| 1183 (*it)->clip_parent_ = NULL; | 1224 (*it)->clip_parent_ = NULL; |
| 1184 } | 1225 } |
| 1185 | 1226 |
| 1186 if (clip_parent_) | 1227 if (clip_parent_) |
| 1187 clip_parent_->RemoveClipChild(this); | 1228 clip_parent_->RemoveClipChild(this); |
| 1188 | 1229 |
| 1189 clip_parent_ = NULL; | 1230 clip_parent_ = NULL; |
| 1190 } | 1231 } |
| 1191 | 1232 |
| 1233 void Layer::AddDrawableDescendants(int num) { | |
| 1234 DCHECK_GE(num_descendants_that_draw_content_, 0); | |
| 1235 DCHECK_GE(num_descendants_that_draw_content_ + num, 0); | |
| 1236 if (num == 0) | |
| 1237 return; | |
| 1238 num_descendants_that_draw_content_ += num; | |
| 1239 SetNeedsCommit(); | |
| 1240 if (parent()) | |
| 1241 parent()->AddDrawableDescendants(num); | |
| 1242 } | |
| 1243 | |
| 1192 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1244 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 1193 benchmark->RunOnLayer(this); | 1245 benchmark->RunOnLayer(this); |
| 1194 } | 1246 } |
| 1247 | |
| 1248 bool Layer::HasDelegatedContent() const { | |
| 1249 return false; | |
| 1250 } | |
| 1251 | |
| 1195 } // namespace cc | 1252 } // namespace cc |
| OLD | NEW |