| 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 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 Layer::Layer() | 40 Layer::Layer() |
| 41 : needs_push_properties_(false), | 41 : needs_push_properties_(false), |
| 42 num_dependents_need_push_properties_(false), | 42 num_dependents_need_push_properties_(false), |
| 43 stacking_order_changed_(false), | 43 stacking_order_changed_(false), |
| 44 // Layer IDs start from 1. | 44 // Layer IDs start from 1. |
| 45 layer_id_(g_next_layer_id.GetNext() + 1), | 45 layer_id_(g_next_layer_id.GetNext() + 1), |
| 46 ignore_set_needs_commit_(false), | 46 ignore_set_needs_commit_(false), |
| 47 sorting_context_id_(0), | 47 sorting_context_id_(0), |
| 48 parent_(NULL), | 48 parent_(nullptr), |
| 49 layer_tree_host_(NULL), | 49 layer_tree_host_(nullptr), |
| 50 scroll_clip_layer_id_(INVALID_ID), | 50 scroll_clip_layer_id_(INVALID_ID), |
| 51 num_descendants_that_draw_content_(0), | 51 num_descendants_that_draw_content_(0), |
| 52 should_scroll_on_main_thread_(false), | 52 should_scroll_on_main_thread_(false), |
| 53 have_wheel_event_handlers_(false), | 53 have_wheel_event_handlers_(false), |
| 54 have_scroll_event_handlers_(false), | 54 have_scroll_event_handlers_(false), |
| 55 user_scrollable_horizontal_(true), | 55 user_scrollable_horizontal_(true), |
| 56 user_scrollable_vertical_(true), | 56 user_scrollable_vertical_(true), |
| 57 is_root_for_isolated_group_(false), | 57 is_root_for_isolated_group_(false), |
| 58 is_container_for_fixed_position_layers_(false), | 58 is_container_for_fixed_position_layers_(false), |
| 59 is_drawable_(false), | 59 is_drawable_(false), |
| 60 draws_content_(false), | 60 draws_content_(false), |
| 61 hide_layer_and_subtree_(false), | 61 hide_layer_and_subtree_(false), |
| 62 masks_to_bounds_(false), | 62 masks_to_bounds_(false), |
| 63 contents_opaque_(false), | 63 contents_opaque_(false), |
| 64 double_sided_(true), | 64 double_sided_(true), |
| 65 should_flatten_transform_(true), | 65 should_flatten_transform_(true), |
| 66 use_parent_backface_visibility_(false), | 66 use_parent_backface_visibility_(false), |
| 67 draw_checkerboard_for_missing_tiles_(false), | 67 draw_checkerboard_for_missing_tiles_(false), |
| 68 force_render_surface_(false), | 68 force_render_surface_(false), |
| 69 transform_is_invertible_(true), | 69 transform_is_invertible_(true), |
| 70 background_color_(0), | 70 background_color_(0), |
| 71 opacity_(1.f), | 71 opacity_(1.f), |
| 72 blend_mode_(SkXfermode::kSrcOver_Mode), | 72 blend_mode_(SkXfermode::kSrcOver_Mode), |
| 73 scroll_parent_(NULL), | 73 scroll_parent_(nullptr), |
| 74 clip_parent_(NULL), | 74 clip_parent_(nullptr), |
| 75 replica_layer_(NULL), | 75 replica_layer_(nullptr), |
| 76 raster_scale_(0.f), | 76 raster_scale_(0.f), |
| 77 client_(NULL) { | 77 client_(nullptr) { |
| 78 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); | 78 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); |
| 79 layer_animation_controller_->AddValueObserver(this); | 79 layer_animation_controller_->AddValueObserver(this); |
| 80 layer_animation_controller_->set_value_provider(this); | 80 layer_animation_controller_->set_value_provider(this); |
| 81 } | 81 } |
| 82 | 82 |
| 83 Layer::~Layer() { | 83 Layer::~Layer() { |
| 84 // Our parent should be holding a reference to us so there should be no | 84 // Our parent should be holding a reference to us so there should be no |
| 85 // way for us to be destroyed while we still have a parent. | 85 // way for us to be destroyed while we still have a parent. |
| 86 DCHECK(!parent()); | 86 DCHECK(!parent()); |
| 87 // Similarly we shouldn't have a layer tree host since it also keeps a | 87 // Similarly we shouldn't have a layer tree host since it also keeps a |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 DCHECK(!layer || !layer->HasAncestor(this)); | 219 DCHECK(!layer || !layer->HasAncestor(this)); |
| 220 | 220 |
| 221 if (parent_should_know_need_push_properties()) { | 221 if (parent_should_know_need_push_properties()) { |
| 222 if (parent_) | 222 if (parent_) |
| 223 parent_->RemoveDependentNeedsPushProperties(); | 223 parent_->RemoveDependentNeedsPushProperties(); |
| 224 if (layer) | 224 if (layer) |
| 225 layer->AddDependentNeedsPushProperties(); | 225 layer->AddDependentNeedsPushProperties(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 parent_ = layer; | 228 parent_ = layer; |
| 229 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : NULL); | 229 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); |
| 230 | 230 |
| 231 if (!layer_tree_host_) | 231 if (!layer_tree_host_) |
| 232 return; | 232 return; |
| 233 const LayerTreeSettings& settings = layer_tree_host_->settings(); | 233 const LayerTreeSettings& settings = layer_tree_host_->settings(); |
| 234 if (!settings.layer_transforms_should_scale_layer_contents) | 234 if (!settings.layer_transforms_should_scale_layer_contents) |
| 235 return; | 235 return; |
| 236 | 236 |
| 237 reset_raster_scale_to_unknown(); | 237 reset_raster_scale_to_unknown(); |
| 238 if (mask_layer_.get()) | 238 if (mask_layer_.get()) |
| 239 mask_layer_->reset_raster_scale_to_unknown(); | 239 mask_layer_->reset_raster_scale_to_unknown(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 259 } | 259 } |
| 260 | 260 |
| 261 void Layer::RemoveFromParent() { | 261 void Layer::RemoveFromParent() { |
| 262 DCHECK(IsPropertyChangeAllowed()); | 262 DCHECK(IsPropertyChangeAllowed()); |
| 263 if (parent_) | 263 if (parent_) |
| 264 parent_->RemoveChildOrDependent(this); | 264 parent_->RemoveChildOrDependent(this); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void Layer::RemoveChildOrDependent(Layer* child) { | 267 void Layer::RemoveChildOrDependent(Layer* child) { |
| 268 if (mask_layer_.get() == child) { | 268 if (mask_layer_.get() == child) { |
| 269 mask_layer_->SetParent(NULL); | 269 mask_layer_->SetParent(nullptr); |
| 270 mask_layer_ = NULL; | 270 mask_layer_ = nullptr; |
| 271 SetNeedsFullTreeSync(); | 271 SetNeedsFullTreeSync(); |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 if (replica_layer_.get() == child) { | 274 if (replica_layer_.get() == child) { |
| 275 replica_layer_->SetParent(NULL); | 275 replica_layer_->SetParent(nullptr); |
| 276 replica_layer_ = NULL; | 276 replica_layer_ = nullptr; |
| 277 SetNeedsFullTreeSync(); | 277 SetNeedsFullTreeSync(); |
| 278 return; | 278 return; |
| 279 } | 279 } |
| 280 | 280 |
| 281 for (LayerList::iterator iter = children_.begin(); | 281 for (LayerList::iterator iter = children_.begin(); |
| 282 iter != children_.end(); | 282 iter != children_.end(); |
| 283 ++iter) { | 283 ++iter) { |
| 284 if (iter->get() != child) | 284 if (iter->get() != child) |
| 285 continue; | 285 continue; |
| 286 | 286 |
| 287 child->SetParent(NULL); | 287 child->SetParent(nullptr); |
| 288 AddDrawableDescendants(-child->NumDescendantsThatDrawContent() - | 288 AddDrawableDescendants(-child->NumDescendantsThatDrawContent() - |
| 289 (child->DrawsContent() ? 1 : 0)); | 289 (child->DrawsContent() ? 1 : 0)); |
| 290 children_.erase(iter); | 290 children_.erase(iter); |
| 291 SetNeedsFullTreeSync(); | 291 SetNeedsFullTreeSync(); |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { | 296 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { |
| 297 DCHECK(reference); | 297 DCHECK(reference); |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 905 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
| 906 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 906 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
| 907 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 907 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| 908 layer->Set3dSortingContextId(sorting_context_id_); | 908 layer->Set3dSortingContextId(sorting_context_id_); |
| 909 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | 909 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
| 910 | 910 |
| 911 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 911 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 912 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 912 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 913 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 913 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 914 | 914 |
| 915 LayerImpl* scroll_parent = NULL; | 915 LayerImpl* scroll_parent = nullptr; |
| 916 if (scroll_parent_) { | 916 if (scroll_parent_) { |
| 917 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 917 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 918 DCHECK(scroll_parent); | 918 DCHECK(scroll_parent); |
| 919 } | 919 } |
| 920 | 920 |
| 921 layer->SetScrollParent(scroll_parent); | 921 layer->SetScrollParent(scroll_parent); |
| 922 if (scroll_children_) { | 922 if (scroll_children_) { |
| 923 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 923 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
| 924 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 924 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
| 925 it != scroll_children_->end(); | 925 it != scroll_children_->end(); |
| 926 ++it) { | 926 ++it) { |
| 927 DCHECK_EQ((*it)->scroll_parent(), this); | 927 DCHECK_EQ((*it)->scroll_parent(), this); |
| 928 LayerImpl* scroll_child = | 928 LayerImpl* scroll_child = |
| 929 layer->layer_tree_impl()->LayerById((*it)->id()); | 929 layer->layer_tree_impl()->LayerById((*it)->id()); |
| 930 DCHECK(scroll_child); | 930 DCHECK(scroll_child); |
| 931 scroll_children->insert(scroll_child); | 931 scroll_children->insert(scroll_child); |
| 932 } | 932 } |
| 933 layer->SetScrollChildren(scroll_children); | 933 layer->SetScrollChildren(scroll_children); |
| 934 } else { | 934 } else { |
| 935 layer->SetScrollChildren(NULL); | 935 layer->SetScrollChildren(nullptr); |
| 936 } | 936 } |
| 937 | 937 |
| 938 LayerImpl* clip_parent = NULL; | 938 LayerImpl* clip_parent = nullptr; |
| 939 if (clip_parent_) { | 939 if (clip_parent_) { |
| 940 clip_parent = | 940 clip_parent = |
| 941 layer->layer_tree_impl()->LayerById(clip_parent_->id()); | 941 layer->layer_tree_impl()->LayerById(clip_parent_->id()); |
| 942 DCHECK(clip_parent); | 942 DCHECK(clip_parent); |
| 943 } | 943 } |
| 944 | 944 |
| 945 layer->SetClipParent(clip_parent); | 945 layer->SetClipParent(clip_parent); |
| 946 if (clip_children_) { | 946 if (clip_children_) { |
| 947 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>; | 947 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>; |
| 948 for (std::set<Layer*>::iterator it = clip_children_->begin(); | 948 for (std::set<Layer*>::iterator it = clip_children_->begin(); |
| 949 it != clip_children_->end(); ++it) { | 949 it != clip_children_->end(); ++it) { |
| 950 DCHECK_EQ((*it)->clip_parent(), this); | 950 DCHECK_EQ((*it)->clip_parent(), this); |
| 951 LayerImpl* clip_child = layer->layer_tree_impl()->LayerById((*it)->id()); | 951 LayerImpl* clip_child = layer->layer_tree_impl()->LayerById((*it)->id()); |
| 952 DCHECK(clip_child); | 952 DCHECK(clip_child); |
| 953 clip_children->insert(clip_child); | 953 clip_children->insert(clip_child); |
| 954 } | 954 } |
| 955 layer->SetClipChildren(clip_children); | 955 layer->SetClipChildren(clip_children); |
| 956 } else { | 956 } else { |
| 957 layer->SetClipChildren(NULL); | 957 layer->SetClipChildren(nullptr); |
| 958 } | 958 } |
| 959 | 959 |
| 960 // Adjust the scroll delta to be just the scrolls that have happened since | 960 // Adjust the scroll delta to be just the scrolls that have happened since |
| 961 // the BeginMainFrame was sent. This happens for impl-side painting | 961 // the BeginMainFrame was sent. This happens for impl-side painting |
| 962 // in LayerImpl::ApplyScrollDeltasSinceBeginMainFrame in a separate tree walk. | 962 // in LayerImpl::ApplyScrollDeltasSinceBeginMainFrame in a separate tree walk. |
| 963 if (layer->layer_tree_impl()->settings().impl_side_painting) { | 963 if (layer->layer_tree_impl()->settings().impl_side_painting) { |
| 964 layer->SetScrollOffset(scroll_offset_); | 964 layer->SetScrollOffset(scroll_offset_); |
| 965 } else { | 965 } else { |
| 966 layer->SetScrollOffsetAndDelta( | 966 layer->SetScrollOffsetAndDelta( |
| 967 scroll_offset_, | 967 scroll_offset_, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 bool Layer::IsSuitableForGpuRasterization() const { | 1072 bool Layer::IsSuitableForGpuRasterization() const { |
| 1073 return true; | 1073 return true; |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 scoped_refptr<base::debug::ConvertableToTraceFormat> Layer::TakeDebugInfo() { | 1076 scoped_refptr<base::debug::ConvertableToTraceFormat> Layer::TakeDebugInfo() { |
| 1077 if (client_) | 1077 if (client_) |
| 1078 return client_->TakeDebugInfo(); | 1078 return client_->TakeDebugInfo(); |
| 1079 else | 1079 else |
| 1080 return NULL; | 1080 return nullptr; |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 void Layer::CreateRenderSurface() { | 1083 void Layer::CreateRenderSurface() { |
| 1084 DCHECK(!draw_properties_.render_surface); | 1084 DCHECK(!draw_properties_.render_surface); |
| 1085 draw_properties_.render_surface = make_scoped_ptr(new RenderSurface(this)); | 1085 draw_properties_.render_surface = make_scoped_ptr(new RenderSurface(this)); |
| 1086 draw_properties_.render_target = this; | 1086 draw_properties_.render_target = this; |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 void Layer::ClearRenderSurface() { | 1089 void Layer::ClearRenderSurface() { |
| 1090 draw_properties_.render_surface = nullptr; | 1090 draw_properties_.render_surface = nullptr; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 layer_animation_controller_->RemoveEventObserver(animation_observer); | 1182 layer_animation_controller_->RemoveEventObserver(animation_observer); |
| 1183 } | 1183 } |
| 1184 | 1184 |
| 1185 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { | 1185 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { |
| 1186 if (contents_opaque()) | 1186 if (contents_opaque()) |
| 1187 return SimpleEnclosedRegion(visible_content_rect()); | 1187 return SimpleEnclosedRegion(visible_content_rect()); |
| 1188 return SimpleEnclosedRegion(); | 1188 return SimpleEnclosedRegion(); |
| 1189 } | 1189 } |
| 1190 | 1190 |
| 1191 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { | 1191 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { |
| 1192 return NULL; | 1192 return nullptr; |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const { | 1195 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const { |
| 1196 return layer_tree_host_->rendering_stats_instrumentation(); | 1196 return layer_tree_host_->rendering_stats_instrumentation(); |
| 1197 } | 1197 } |
| 1198 | 1198 |
| 1199 bool Layer::SupportsLCDText() const { | 1199 bool Layer::SupportsLCDText() const { |
| 1200 return false; | 1200 return false; |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 void Layer::RemoveFromScrollTree() { | 1203 void Layer::RemoveFromScrollTree() { |
| 1204 if (scroll_children_.get()) { | 1204 if (scroll_children_.get()) { |
| 1205 std::set<Layer*> copy = *scroll_children_; | 1205 std::set<Layer*> copy = *scroll_children_; |
| 1206 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it) | 1206 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it) |
| 1207 (*it)->SetScrollParent(NULL); | 1207 (*it)->SetScrollParent(nullptr); |
| 1208 } | 1208 } |
| 1209 | 1209 |
| 1210 DCHECK(!scroll_children_); | 1210 DCHECK(!scroll_children_); |
| 1211 SetScrollParent(NULL); | 1211 SetScrollParent(nullptr); |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 void Layer::RemoveFromClipTree() { | 1214 void Layer::RemoveFromClipTree() { |
| 1215 if (clip_children_.get()) { | 1215 if (clip_children_.get()) { |
| 1216 std::set<Layer*> copy = *clip_children_; | 1216 std::set<Layer*> copy = *clip_children_; |
| 1217 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it) | 1217 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it) |
| 1218 (*it)->SetClipParent(NULL); | 1218 (*it)->SetClipParent(nullptr); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 DCHECK(!clip_children_); | 1221 DCHECK(!clip_children_); |
| 1222 SetClipParent(NULL); | 1222 SetClipParent(nullptr); |
| 1223 } | 1223 } |
| 1224 | 1224 |
| 1225 void Layer::AddDrawableDescendants(int num) { | 1225 void Layer::AddDrawableDescendants(int num) { |
| 1226 DCHECK_GE(num_descendants_that_draw_content_, 0); | 1226 DCHECK_GE(num_descendants_that_draw_content_, 0); |
| 1227 DCHECK_GE(num_descendants_that_draw_content_ + num, 0); | 1227 DCHECK_GE(num_descendants_that_draw_content_ + num, 0); |
| 1228 if (num == 0) | 1228 if (num == 0) |
| 1229 return; | 1229 return; |
| 1230 num_descendants_that_draw_content_ += num; | 1230 num_descendants_that_draw_content_ += num; |
| 1231 SetNeedsCommit(); | 1231 SetNeedsCommit(); |
| 1232 if (parent()) | 1232 if (parent()) |
| 1233 parent()->AddDrawableDescendants(num); | 1233 parent()->AddDrawableDescendants(num); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1236 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 1237 benchmark->RunOnLayer(this); | 1237 benchmark->RunOnLayer(this); |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 bool Layer::HasDelegatedContent() const { | 1240 bool Layer::HasDelegatedContent() const { |
| 1241 return false; | 1241 return false; |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 } // namespace cc | 1244 } // namespace cc |
| OLD | NEW |