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) + | |
257 (child->HasDelegatedContent() ? 1000 : 0)); | |
253 SetNeedsFullTreeSync(); | 258 SetNeedsFullTreeSync(); |
254 } | 259 } |
255 | 260 |
256 void Layer::RemoveFromParent() { | 261 void Layer::RemoveFromParent() { |
257 DCHECK(IsPropertyChangeAllowed()); | 262 DCHECK(IsPropertyChangeAllowed()); |
258 if (parent_) | 263 if (parent_) |
259 parent_->RemoveChildOrDependent(this); | 264 parent_->RemoveChildOrDependent(this); |
260 } | 265 } |
261 | 266 |
262 void Layer::RemoveChildOrDependent(Layer* child) { | 267 void Layer::RemoveChildOrDependent(Layer* child) { |
(...skipping 10 matching lines...) Expand all Loading... | |
273 return; | 278 return; |
274 } | 279 } |
275 | 280 |
276 for (LayerList::iterator iter = children_.begin(); | 281 for (LayerList::iterator iter = children_.begin(); |
277 iter != children_.end(); | 282 iter != children_.end(); |
278 ++iter) { | 283 ++iter) { |
279 if (iter->get() != child) | 284 if (iter->get() != child) |
280 continue; | 285 continue; |
281 | 286 |
282 child->SetParent(NULL); | 287 child->SetParent(NULL); |
288 AddDrawableDescendants(-child->NumDescendantsThatDrawContent() - | |
289 (child->DrawsContent() ? 1 : 0) - | |
290 (child->HasDelegatedContent() ? 1000 : 0)); | |
danakj
2014/07/14 20:22:02
i don't think you need to do this here after you a
awoloszyn
2014/07/16 20:44:19
Done.
| |
283 children_.erase(iter); | 291 children_.erase(iter); |
284 SetNeedsFullTreeSync(); | 292 SetNeedsFullTreeSync(); |
285 return; | 293 return; |
286 } | 294 } |
287 } | 295 } |
288 | 296 |
289 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { | 297 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { |
290 DCHECK(reference); | 298 DCHECK(reference); |
291 DCHECK_EQ(reference->parent(), this); | 299 DCHECK_EQ(reference->parent(), this); |
292 DCHECK(IsPropertyChangeAllowed()); | 300 DCHECK(IsPropertyChangeAllowed()); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 should_flatten_transform_ = should_flatten; | 780 should_flatten_transform_ = should_flatten; |
773 SetNeedsCommit(); | 781 SetNeedsCommit(); |
774 } | 782 } |
775 | 783 |
776 void Layer::SetIsDrawable(bool is_drawable) { | 784 void Layer::SetIsDrawable(bool is_drawable) { |
777 DCHECK(IsPropertyChangeAllowed()); | 785 DCHECK(IsPropertyChangeAllowed()); |
778 if (is_drawable_ == is_drawable) | 786 if (is_drawable_ == is_drawable) |
779 return; | 787 return; |
780 | 788 |
781 is_drawable_ = is_drawable; | 789 is_drawable_ = is_drawable; |
790 UpdateDrawsContent(); | |
782 SetNeedsCommit(); | 791 SetNeedsCommit(); |
783 } | 792 } |
784 | 793 |
785 void Layer::SetHideLayerAndSubtree(bool hide) { | 794 void Layer::SetHideLayerAndSubtree(bool hide) { |
786 DCHECK(IsPropertyChangeAllowed()); | 795 DCHECK(IsPropertyChangeAllowed()); |
787 if (hide_layer_and_subtree_ == hide) | 796 if (hide_layer_and_subtree_ == hide) |
788 return; | 797 return; |
789 | 798 |
790 hide_layer_and_subtree_ = hide; | 799 hide_layer_and_subtree_ = hide; |
791 SetNeedsCommit(); | 800 SetNeedsCommit(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 layer->SetPosition(position_); | 902 layer->SetPosition(position_); |
894 layer->SetIsContainerForFixedPositionLayers( | 903 layer->SetIsContainerForFixedPositionLayers( |
895 IsContainerForFixedPositionLayers()); | 904 IsContainerForFixedPositionLayers()); |
896 layer->SetPositionConstraint(position_constraint_); | 905 layer->SetPositionConstraint(position_constraint_); |
897 layer->SetShouldFlattenTransform(should_flatten_transform_); | 906 layer->SetShouldFlattenTransform(should_flatten_transform_); |
898 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 907 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
899 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 908 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
900 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 909 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
901 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 910 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
902 layer->Set3dSortingContextId(sorting_context_id_); | 911 layer->Set3dSortingContextId(sorting_context_id_); |
912 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | |
903 | 913 |
904 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 914 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
905 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 915 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
906 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 916 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
907 | 917 |
908 LayerImpl* scroll_parent = NULL; | 918 LayerImpl* scroll_parent = NULL; |
909 if (scroll_parent_) { | 919 if (scroll_parent_) { |
910 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 920 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
911 DCHECK(scroll_parent); | 921 DCHECK(scroll_parent); |
912 } | 922 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 | 1009 |
1000 needs_push_properties_ = false; | 1010 needs_push_properties_ = false; |
1001 num_dependents_need_push_properties_ = 0; | 1011 num_dependents_need_push_properties_ = 0; |
1002 } | 1012 } |
1003 | 1013 |
1004 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1014 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
1005 return LayerImpl::Create(tree_impl, layer_id_); | 1015 return LayerImpl::Create(tree_impl, layer_id_); |
1006 } | 1016 } |
1007 | 1017 |
1008 bool Layer::DrawsContent() const { | 1018 bool Layer::DrawsContent() const { |
1009 return is_drawable_; | 1019 return draws_content_; |
1020 } | |
1021 | |
1022 bool Layer::HasDrawableContent() const { | |
1023 return true; | |
1024 } | |
1025 | |
1026 void Layer::UpdateDrawsContent() { | |
1027 bool draws_content = is_drawable_ && HasDrawableContent(); | |
1028 if (draws_content == draws_content_) | |
1029 return; | |
1030 // As per the comment that was originally in | |
1031 // LayerTreeHost::PrecalculateMetaInformation: | |
1032 // Layers with delegated content need to be treated as if they have as | |
danakj
2014/07/14 20:22:02
This isn't quite what we're doing yet. Right now y
awoloszyn
2014/07/16 20:44:19
I moved this into NumDescendantsThatDrawContent().
| |
1033 // many children as the number of layers they own delegated quads for. | |
1034 // Since we don't know this number right now, we choose one that acts like | |
1035 // infinity for our purposes. | |
1036 | |
1037 if (parent()) { | |
1038 if (draws_content) { | |
1039 parent()->AddDrawableDescendants(1 + (HasDelegatedContent() ? 1000 : 0)); | |
1040 } else { | |
1041 parent()->AddDrawableDescendants(-1 - (HasDelegatedContent() ? 1000 : 0)); | |
1042 } | |
1043 } | |
1044 draws_content_ = draws_content; | |
danakj
2014/07/14 20:22:02
SetNeedsCommit in here, please add this to the tes
awoloszyn
2014/07/16 20:44:20
Done.
| |
1045 } | |
1046 | |
1047 int Layer::NumDescendantsThatDrawContent() const { | |
1048 return num_descendants_that_draw_content_; | |
1010 } | 1049 } |
1011 | 1050 |
1012 void Layer::SavePaintProperties() { | 1051 void Layer::SavePaintProperties() { |
1013 DCHECK(layer_tree_host_); | 1052 DCHECK(layer_tree_host_); |
1014 | 1053 |
1015 // TODO(reveman): Save all layer properties that we depend on not | 1054 // TODO(reveman): Save all layer properties that we depend on not |
1016 // changing until PushProperties() has been called. crbug.com/231016 | 1055 // changing until PushProperties() has been called. crbug.com/231016 |
1017 paint_properties_.bounds = bounds_; | 1056 paint_properties_.bounds = bounds_; |
1018 paint_properties_.source_frame_number = | 1057 paint_properties_.source_frame_number = |
1019 layer_tree_host_->source_frame_number(); | 1058 layer_tree_host_->source_frame_number(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1182 it != clip_children_->end(); ++it) | 1221 it != clip_children_->end(); ++it) |
1183 (*it)->clip_parent_ = NULL; | 1222 (*it)->clip_parent_ = NULL; |
1184 } | 1223 } |
1185 | 1224 |
1186 if (clip_parent_) | 1225 if (clip_parent_) |
1187 clip_parent_->RemoveClipChild(this); | 1226 clip_parent_->RemoveClipChild(this); |
1188 | 1227 |
1189 clip_parent_ = NULL; | 1228 clip_parent_ = NULL; |
1190 } | 1229 } |
1191 | 1230 |
1231 void Layer::AddDrawableDescendants(int num) { | |
1232 DCHECK_GE(num_descendants_that_draw_content_, 0); | |
1233 DCHECK_GE(num_descendants_that_draw_content_ + num, 0); | |
1234 if (num == 0) | |
1235 return; | |
1236 num_descendants_that_draw_content_ += num; | |
1237 SetNeedsCommit(); | |
1238 if (parent()) | |
1239 parent()->AddDrawableDescendants(num); | |
1240 } | |
1241 | |
1192 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1242 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1193 benchmark->RunOnLayer(this); | 1243 benchmark->RunOnLayer(this); |
1194 } | 1244 } |
1245 | |
1246 bool Layer::HasDelegatedContent() const { | |
1247 return false; | |
1248 } | |
1195 } // namespace cc | 1249 } // namespace cc |
danakj
2014/07/14 20:22:02
blank line above
awoloszyn
2014/07/16 20:44:20
Done.
| |
OLD | NEW |