| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 layer->SetPosition(position_); | 901 layer->SetPosition(position_); |
| 896 layer->SetIsContainerForFixedPositionLayers( | 902 layer->SetIsContainerForFixedPositionLayers( |
| 897 IsContainerForFixedPositionLayers()); | 903 IsContainerForFixedPositionLayers()); |
| 898 layer->SetPositionConstraint(position_constraint_); | 904 layer->SetPositionConstraint(position_constraint_); |
| 899 layer->SetShouldFlattenTransform(should_flatten_transform_); | 905 layer->SetShouldFlattenTransform(should_flatten_transform_); |
| 900 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 906 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 901 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 907 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
| 902 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 908 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
| 903 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 909 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| 904 layer->Set3dSortingContextId(sorting_context_id_); | 910 layer->Set3dSortingContextId(sorting_context_id_); |
| 911 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
| 905 | 912 |
| 906 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 913 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 907 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 914 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 908 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 915 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 909 | 916 |
| 910 LayerImpl* scroll_parent = NULL; | 917 LayerImpl* scroll_parent = NULL; |
| 911 if (scroll_parent_) { | 918 if (scroll_parent_) { |
| 912 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 919 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 913 DCHECK(scroll_parent); | 920 DCHECK(scroll_parent); |
| 914 } | 921 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1008 |
| 1002 needs_push_properties_ = false; | 1009 needs_push_properties_ = false; |
| 1003 num_dependents_need_push_properties_ = 0; | 1010 num_dependents_need_push_properties_ = 0; |
| 1004 } | 1011 } |
| 1005 | 1012 |
| 1006 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1013 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 1007 return LayerImpl::Create(tree_impl, layer_id_); | 1014 return LayerImpl::Create(tree_impl, layer_id_); |
| 1008 } | 1015 } |
| 1009 | 1016 |
| 1010 bool Layer::DrawsContent() const { | 1017 bool Layer::DrawsContent() const { |
| 1018 return draws_content_; |
| 1019 } |
| 1020 |
| 1021 bool Layer::HasDrawableContent() const { |
| 1011 return is_drawable_; | 1022 return is_drawable_; |
| 1012 } | 1023 } |
| 1013 | 1024 |
| 1025 void Layer::UpdateDrawsContent(bool has_drawable_content) { |
| 1026 bool draws_content = has_drawable_content; |
| 1027 DCHECK(is_drawable_ || !has_drawable_content); |
| 1028 if (draws_content == draws_content_) |
| 1029 return; |
| 1030 |
| 1031 if (HasDelegatedContent()) { |
| 1032 // Layers with delegated content need to be treated as if they have as |
| 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 AddDrawableDescendants(draws_content ? 1000 : -1000); |
| 1037 } |
| 1038 |
| 1039 if (parent()) |
| 1040 parent()->AddDrawableDescendants(draws_content ? 1 : -1); |
| 1041 |
| 1042 draws_content_ = draws_content; |
| 1043 SetNeedsCommit(); |
| 1044 } |
| 1045 |
| 1046 int Layer::NumDescendantsThatDrawContent() const { |
| 1047 return num_descendants_that_draw_content_; |
| 1048 } |
| 1049 |
| 1014 void Layer::SavePaintProperties() { | 1050 void Layer::SavePaintProperties() { |
| 1015 DCHECK(layer_tree_host_); | 1051 DCHECK(layer_tree_host_); |
| 1016 | 1052 |
| 1017 // TODO(reveman): Save all layer properties that we depend on not | 1053 // TODO(reveman): Save all layer properties that we depend on not |
| 1018 // changing until PushProperties() has been called. crbug.com/231016 | 1054 // changing until PushProperties() has been called. crbug.com/231016 |
| 1019 paint_properties_.bounds = bounds_; | 1055 paint_properties_.bounds = bounds_; |
| 1020 paint_properties_.source_frame_number = | 1056 paint_properties_.source_frame_number = |
| 1021 layer_tree_host_->source_frame_number(); | 1057 layer_tree_host_->source_frame_number(); |
| 1022 } | 1058 } |
| 1023 | 1059 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 it != clip_children_->end(); ++it) | 1220 it != clip_children_->end(); ++it) |
| 1185 (*it)->clip_parent_ = NULL; | 1221 (*it)->clip_parent_ = NULL; |
| 1186 } | 1222 } |
| 1187 | 1223 |
| 1188 if (clip_parent_) | 1224 if (clip_parent_) |
| 1189 clip_parent_->RemoveClipChild(this); | 1225 clip_parent_->RemoveClipChild(this); |
| 1190 | 1226 |
| 1191 clip_parent_ = NULL; | 1227 clip_parent_ = NULL; |
| 1192 } | 1228 } |
| 1193 | 1229 |
| 1230 void Layer::AddDrawableDescendants(int num) { |
| 1231 DCHECK_GE(num_descendants_that_draw_content_, 0); |
| 1232 DCHECK_GE(num_descendants_that_draw_content_ + num, 0); |
| 1233 if (num == 0) |
| 1234 return; |
| 1235 num_descendants_that_draw_content_ += num; |
| 1236 SetNeedsCommit(); |
| 1237 if (parent()) |
| 1238 parent()->AddDrawableDescendants(num); |
| 1239 } |
| 1240 |
| 1194 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1241 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 1195 benchmark->RunOnLayer(this); | 1242 benchmark->RunOnLayer(this); |
| 1196 } | 1243 } |
| 1244 |
| 1245 bool Layer::HasDelegatedContent() const { |
| 1246 return false; |
| 1247 } |
| 1248 |
| 1197 } // namespace cc | 1249 } // namespace cc |
| OLD | NEW |