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 RemoveDrawableDescendants(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; |
788 UpdateDrawsContent(true); | |
782 SetNeedsCommit(); | 789 SetNeedsCommit(); |
783 } | 790 } |
784 | 791 |
785 void Layer::SetHideLayerAndSubtree(bool hide) { | 792 void Layer::SetHideLayerAndSubtree(bool hide) { |
786 DCHECK(IsPropertyChangeAllowed()); | 793 DCHECK(IsPropertyChangeAllowed()); |
787 if (hide_layer_and_subtree_ == hide) | 794 if (hide_layer_and_subtree_ == hide) |
788 return; | 795 return; |
789 | 796 |
790 hide_layer_and_subtree_ = hide; | 797 hide_layer_and_subtree_ = hide; |
791 SetNeedsCommit(); | 798 SetNeedsCommit(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 layer->SetPosition(position_); | 900 layer->SetPosition(position_); |
894 layer->SetIsContainerForFixedPositionLayers( | 901 layer->SetIsContainerForFixedPositionLayers( |
895 IsContainerForFixedPositionLayers()); | 902 IsContainerForFixedPositionLayers()); |
896 layer->SetPositionConstraint(position_constraint_); | 903 layer->SetPositionConstraint(position_constraint_); |
897 layer->SetShouldFlattenTransform(should_flatten_transform_); | 904 layer->SetShouldFlattenTransform(should_flatten_transform_); |
898 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 905 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
899 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 906 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
900 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 907 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
901 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 908 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
902 layer->Set3dSortingContextId(sorting_context_id_); | 909 layer->Set3dSortingContextId(sorting_context_id_); |
910 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | |
903 | 911 |
904 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 912 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
905 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 913 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
906 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 914 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
907 | 915 |
908 LayerImpl* scroll_parent = NULL; | 916 LayerImpl* scroll_parent = NULL; |
909 if (scroll_parent_) { | 917 if (scroll_parent_) { |
910 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 918 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
911 DCHECK(scroll_parent); | 919 DCHECK(scroll_parent); |
912 } | 920 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 | 1007 |
1000 needs_push_properties_ = false; | 1008 needs_push_properties_ = false; |
1001 num_dependents_need_push_properties_ = 0; | 1009 num_dependents_need_push_properties_ = 0; |
1002 } | 1010 } |
1003 | 1011 |
1004 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1012 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
1005 return LayerImpl::Create(tree_impl, layer_id_); | 1013 return LayerImpl::Create(tree_impl, layer_id_); |
1006 } | 1014 } |
1007 | 1015 |
1008 bool Layer::DrawsContent() const { | 1016 bool Layer::DrawsContent() const { |
1009 return is_drawable_; | 1017 return draws_content_; |
1018 } | |
1019 | |
1020 void Layer::SetDrawsContent(bool draws_content) { | |
1021 if (draws_content == draws_content_) | |
1022 return; | |
1023 if (parent()) { | |
1024 if (draws_content) { | |
1025 parent()->AddDrawableDescendants(1); | |
1026 } else { | |
1027 parent()->RemoveDrawableDescendants(1); | |
1028 } | |
1029 } | |
1030 draws_content_ = draws_content; | |
1031 } | |
1032 | |
1033 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.
| |
1034 SetDrawsContent(draws_content && is_drawable_); | |
1035 } | |
1036 | |
1037 int Layer::NumDescendantsThatDrawContent() const { | |
1038 return num_descendants_that_draw_content_; | |
1010 } | 1039 } |
1011 | 1040 |
1012 void Layer::SavePaintProperties() { | 1041 void Layer::SavePaintProperties() { |
1013 DCHECK(layer_tree_host_); | 1042 DCHECK(layer_tree_host_); |
1014 | 1043 |
1015 // TODO(reveman): Save all layer properties that we depend on not | 1044 // TODO(reveman): Save all layer properties that we depend on not |
1016 // changing until PushProperties() has been called. crbug.com/231016 | 1045 // changing until PushProperties() has been called. crbug.com/231016 |
1017 paint_properties_.bounds = bounds_; | 1046 paint_properties_.bounds = bounds_; |
1018 paint_properties_.source_frame_number = | 1047 paint_properties_.source_frame_number = |
1019 layer_tree_host_->source_frame_number(); | 1048 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) | 1211 it != clip_children_->end(); ++it) |
1183 (*it)->clip_parent_ = NULL; | 1212 (*it)->clip_parent_ = NULL; |
1184 } | 1213 } |
1185 | 1214 |
1186 if (clip_parent_) | 1215 if (clip_parent_) |
1187 clip_parent_->RemoveClipChild(this); | 1216 clip_parent_->RemoveClipChild(this); |
1188 | 1217 |
1189 clip_parent_ = NULL; | 1218 clip_parent_ = NULL; |
1190 } | 1219 } |
1191 | 1220 |
1221 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.
| |
1222 DCHECK_GE(num, 0); | |
1223 DCHECK_GE(num_descendants_that_draw_content_, 0); | |
1224 if (num == 0) | |
1225 return; | |
1226 num_descendants_that_draw_content_ += num; | |
1227 SetNeedsCommit(); | |
1228 if (parent()) | |
1229 parent()->AddDrawableDescendants(num); | |
1230 } | |
1231 | |
1232 void Layer::RemoveDrawableDescendants(int num) { | |
1233 DCHECK_GE(num, 0); | |
1234 if (num == 0) | |
1235 return; | |
1236 num_descendants_that_draw_content_ -= num; | |
1237 DCHECK_GE(num_descendants_that_draw_content_, 0); | |
1238 SetNeedsCommit(); | |
1239 if (parent()) | |
1240 parent()->RemoveDrawableDescendants(num); | |
1241 } | |
1242 | |
1192 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1243 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1193 benchmark->RunOnLayer(this); | 1244 benchmark->RunOnLayer(this); |
1194 } | 1245 } |
1195 } // namespace cc | 1246 } // namespace cc |
OLD | NEW |