| 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/location.h" | 10 #include "base/location.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE), | 76 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE), |
| 77 background_color_(0), | 77 background_color_(0), |
| 78 opacity_(1.f), | 78 opacity_(1.f), |
| 79 blend_mode_(SkXfermode::kSrcOver_Mode), | 79 blend_mode_(SkXfermode::kSrcOver_Mode), |
| 80 scroll_parent_(nullptr), | 80 scroll_parent_(nullptr), |
| 81 clip_parent_(nullptr), | 81 clip_parent_(nullptr), |
| 82 replica_layer_(nullptr), | 82 replica_layer_(nullptr), |
| 83 raster_scale_(0.f), | 83 raster_scale_(0.f), |
| 84 client_(nullptr), | 84 client_(nullptr), |
| 85 frame_timing_requests_dirty_(false) { | 85 frame_timing_requests_dirty_(false) { |
| 86 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); | |
| 87 layer_animation_controller_->AddValueObserver(this); | |
| 88 layer_animation_controller_->set_value_provider(this); | |
| 89 } | 86 } |
| 90 | 87 |
| 91 Layer::~Layer() { | 88 Layer::~Layer() { |
| 92 // Our parent should be holding a reference to us so there should be no | 89 // Our parent should be holding a reference to us so there should be no |
| 93 // way for us to be destroyed while we still have a parent. | 90 // way for us to be destroyed while we still have a parent. |
| 94 DCHECK(!parent()); | 91 DCHECK(!parent()); |
| 95 // Similarly we shouldn't have a layer tree host since it also keeps a | 92 // Similarly we shouldn't have a layer tree host since it also keeps a |
| 96 // reference to us. | 93 // reference to us. |
| 97 DCHECK(!layer_tree_host()); | 94 DCHECK(!layer_tree_host()); |
| 98 | 95 |
| 99 layer_animation_controller_->RemoveValueObserver(this); | 96 if (layer_animation_controller_) { |
| 100 layer_animation_controller_->remove_value_provider(this); | 97 layer_animation_controller_->RemoveValueObserver(this); |
| 98 layer_animation_controller_->remove_value_provider(this); |
| 99 } |
| 101 | 100 |
| 102 RemoveFromScrollTree(); | 101 RemoveFromScrollTree(); |
| 103 RemoveFromClipTree(); | 102 RemoveFromClipTree(); |
| 104 | 103 |
| 105 // Remove the parent reference from all children and dependents. | 104 // Remove the parent reference from all children and dependents. |
| 106 RemoveAllChildren(); | 105 RemoveAllChildren(); |
| 107 if (mask_layer_.get()) { | 106 if (mask_layer_.get()) { |
| 108 DCHECK_EQ(this, mask_layer_->parent()); | 107 DCHECK_EQ(this, mask_layer_->parent()); |
| 109 mask_layer_->RemoveFromParent(); | 108 mask_layer_->RemoveFromParent(); |
| 110 } | 109 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 | 128 |
| 130 for (size_t i = 0; i < children_.size(); ++i) | 129 for (size_t i = 0; i < children_.size(); ++i) |
| 131 children_[i]->SetLayerTreeHost(host); | 130 children_[i]->SetLayerTreeHost(host); |
| 132 | 131 |
| 133 if (mask_layer_.get()) | 132 if (mask_layer_.get()) |
| 134 mask_layer_->SetLayerTreeHost(host); | 133 mask_layer_->SetLayerTreeHost(host); |
| 135 if (replica_layer_.get()) | 134 if (replica_layer_.get()) |
| 136 replica_layer_->SetLayerTreeHost(host); | 135 replica_layer_->SetLayerTreeHost(host); |
| 137 | 136 |
| 138 if (host) { | 137 if (host) { |
| 139 layer_animation_controller_->SetAnimationRegistrar( | 138 RegisterForAnimations(host->animation_registrar(), host->settings()); |
| 140 host->animation_registrar()); | |
| 141 | |
| 142 if (host->settings().layer_transforms_should_scale_layer_contents) | 139 if (host->settings().layer_transforms_should_scale_layer_contents) |
| 143 reset_raster_scale_to_unknown(); | 140 reset_raster_scale_to_unknown(); |
| 144 } | 141 } |
| 145 | 142 |
| 146 if (host && layer_animation_controller_->has_any_animation()) | 143 if (host && layer_animation_controller_->has_any_animation()) |
| 147 host->SetNeedsCommit(); | 144 host->SetNeedsCommit(); |
| 148 } | 145 } |
| 149 | 146 |
| 150 void Layer::SetNeedsUpdate() { | 147 void Layer::SetNeedsUpdate() { |
| 151 if (layer_tree_host_ && !ignore_set_needs_commit_) | 148 if (layer_tree_host_ && !ignore_set_needs_commit_) |
| (...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 void Layer::OnAnimationWaitingForDeletion() { | 1340 void Layer::OnAnimationWaitingForDeletion() { |
| 1344 // Animations are only deleted during PushProperties. | 1341 // Animations are only deleted during PushProperties. |
| 1345 SetNeedsPushProperties(); | 1342 SetNeedsPushProperties(); |
| 1346 } | 1343 } |
| 1347 | 1344 |
| 1348 bool Layer::IsActive() const { | 1345 bool Layer::IsActive() const { |
| 1349 return true; | 1346 return true; |
| 1350 } | 1347 } |
| 1351 | 1348 |
| 1352 bool Layer::AddAnimation(scoped_ptr <Animation> animation) { | 1349 bool Layer::AddAnimation(scoped_ptr <Animation> animation) { |
| 1353 if (!layer_animation_controller_->animation_registrar()) | 1350 if (!layer_animation_controller_ || |
| 1351 !layer_animation_controller_->animation_registrar()) |
| 1354 return false; | 1352 return false; |
| 1355 | 1353 |
| 1356 if (animation->target_property() == Animation::SCROLL_OFFSET && | 1354 if (animation->target_property() == Animation::SCROLL_OFFSET && |
| 1357 !layer_animation_controller_->animation_registrar() | 1355 !layer_animation_controller_->animation_registrar() |
| 1358 ->supports_scroll_animations()) | 1356 ->supports_scroll_animations()) |
| 1359 return false; | 1357 return false; |
| 1360 | 1358 |
| 1361 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", | 1359 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", |
| 1362 !layer_tree_host_); | 1360 !layer_tree_host_); |
| 1363 layer_animation_controller_->AddAnimation(animation.Pass()); | 1361 layer_animation_controller_->AddAnimation(animation.Pass()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1387 layer_animation_controller_->RemoveValueObserver(this); | 1385 layer_animation_controller_->RemoveValueObserver(this); |
| 1388 layer_animation_controller_ = controller; | 1386 layer_animation_controller_ = controller; |
| 1389 layer_animation_controller_->AddValueObserver(this); | 1387 layer_animation_controller_->AddValueObserver(this); |
| 1390 SetNeedsCommit(); | 1388 SetNeedsCommit(); |
| 1391 } | 1389 } |
| 1392 | 1390 |
| 1393 bool Layer::HasActiveAnimation() const { | 1391 bool Layer::HasActiveAnimation() const { |
| 1394 return layer_animation_controller_->HasActiveAnimation(); | 1392 return layer_animation_controller_->HasActiveAnimation(); |
| 1395 } | 1393 } |
| 1396 | 1394 |
| 1395 void Layer::RegisterForAnimations(AnimationRegistrar* registrar, |
| 1396 const LayerTreeSettings& settings) { |
| 1397 if (!layer_animation_controller_) { |
| 1398 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); |
| 1399 layer_animation_controller_->AddValueObserver(this); |
| 1400 layer_animation_controller_->set_value_provider(this); |
| 1401 } |
| 1402 |
| 1403 layer_animation_controller_->SetAnimationRegistrar(registrar); |
| 1404 } |
| 1405 |
| 1397 void Layer::AddLayerAnimationEventObserver( | 1406 void Layer::AddLayerAnimationEventObserver( |
| 1398 LayerAnimationEventObserver* animation_observer) { | 1407 LayerAnimationEventObserver* animation_observer) { |
| 1408 DCHECK(layer_animation_controller_); |
| 1399 layer_animation_controller_->AddEventObserver(animation_observer); | 1409 layer_animation_controller_->AddEventObserver(animation_observer); |
| 1400 } | 1410 } |
| 1401 | 1411 |
| 1402 void Layer::RemoveLayerAnimationEventObserver( | 1412 void Layer::RemoveLayerAnimationEventObserver( |
| 1403 LayerAnimationEventObserver* animation_observer) { | 1413 LayerAnimationEventObserver* animation_observer) { |
| 1414 DCHECK(layer_animation_controller_); |
| 1404 layer_animation_controller_->RemoveEventObserver(animation_observer); | 1415 layer_animation_controller_->RemoveEventObserver(animation_observer); |
| 1405 } | 1416 } |
| 1406 | 1417 |
| 1407 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { | 1418 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { |
| 1408 if (contents_opaque()) | 1419 if (contents_opaque()) |
| 1409 return SimpleEnclosedRegion(visible_content_rect()); | 1420 return SimpleEnclosedRegion(visible_content_rect()); |
| 1410 return SimpleEnclosedRegion(); | 1421 return SimpleEnclosedRegion(); |
| 1411 } | 1422 } |
| 1412 | 1423 |
| 1413 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { | 1424 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 | 1479 |
| 1469 void Layer::DidBeginTracing() { | 1480 void Layer::DidBeginTracing() { |
| 1470 // We'll be dumping layer trees as part of trace, so make sure | 1481 // We'll be dumping layer trees as part of trace, so make sure |
| 1471 // PushPropertiesTo() propagates layer debug info to the impl | 1482 // PushPropertiesTo() propagates layer debug info to the impl |
| 1472 // side -- otherwise this won't happen for the the layers that | 1483 // side -- otherwise this won't happen for the the layers that |
| 1473 // remain unchanged since tracing started. | 1484 // remain unchanged since tracing started. |
| 1474 SetNeedsPushProperties(); | 1485 SetNeedsPushProperties(); |
| 1475 } | 1486 } |
| 1476 | 1487 |
| 1477 } // namespace cc | 1488 } // namespace cc |
| OLD | NEW |