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 16 matching lines...) Expand all Loading... |
27 #include "cc/trees/layer_tree_host.h" | 27 #include "cc/trees/layer_tree_host.h" |
28 #include "cc/trees/layer_tree_impl.h" | 28 #include "cc/trees/layer_tree_impl.h" |
29 #include "third_party/skia/include/core/SkImageFilter.h" | 29 #include "third_party/skia/include/core/SkImageFilter.h" |
30 #include "ui/gfx/geometry/rect_conversions.h" | 30 #include "ui/gfx/geometry/rect_conversions.h" |
31 #include "ui/gfx/geometry/vector2d_conversions.h" | 31 #include "ui/gfx/geometry/vector2d_conversions.h" |
32 | 32 |
33 namespace cc { | 33 namespace cc { |
34 | 34 |
35 base::StaticAtomicSequenceNumber g_next_layer_id; | 35 base::StaticAtomicSequenceNumber g_next_layer_id; |
36 | 36 |
37 scoped_refptr<Layer> Layer::Create() { | 37 scoped_refptr<Layer> Layer::Create(const LayerSettings& settings) { |
38 return make_scoped_refptr(new Layer()); | 38 return make_scoped_refptr(new Layer(settings)); |
39 } | 39 } |
40 | 40 |
41 Layer::Layer() | 41 Layer::Layer(const LayerSettings& settings) |
42 : needs_push_properties_(false), | 42 : needs_push_properties_(false), |
43 num_dependents_need_push_properties_(false), | 43 num_dependents_need_push_properties_(false), |
44 stacking_order_changed_(false), | 44 stacking_order_changed_(false), |
45 // Layer IDs start from 1. | 45 // Layer IDs start from 1. |
46 layer_id_(g_next_layer_id.GetNext() + 1), | 46 layer_id_(g_next_layer_id.GetNext() + 1), |
47 ignore_set_needs_commit_(false), | 47 ignore_set_needs_commit_(false), |
48 sorting_context_id_(0), | 48 sorting_context_id_(0), |
49 parent_(nullptr), | 49 parent_(nullptr), |
50 layer_tree_host_(nullptr), | 50 layer_tree_host_(nullptr), |
51 scroll_clip_layer_id_(INVALID_ID), | 51 scroll_clip_layer_id_(INVALID_ID), |
(...skipping 24 matching lines...) Expand all 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_); | 86 if (!settings.use_compositor_animation_timelines) { |
87 layer_animation_controller_->AddValueObserver(this); | 87 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); |
88 layer_animation_controller_->set_value_provider(this); | 88 layer_animation_controller_->AddValueObserver(this); |
| 89 layer_animation_controller_->set_value_provider(this); |
| 90 } |
89 } | 91 } |
90 | 92 |
91 Layer::~Layer() { | 93 Layer::~Layer() { |
92 // Our parent should be holding a reference to us so there should be no | 94 // 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. | 95 // way for us to be destroyed while we still have a parent. |
94 DCHECK(!parent()); | 96 DCHECK(!parent()); |
95 // Similarly we shouldn't have a layer tree host since it also keeps a | 97 // Similarly we shouldn't have a layer tree host since it also keeps a |
96 // reference to us. | 98 // reference to us. |
97 DCHECK(!layer_tree_host()); | 99 DCHECK(!layer_tree_host()); |
98 | 100 |
99 layer_animation_controller_->RemoveValueObserver(this); | 101 if (layer_animation_controller_) { |
100 layer_animation_controller_->remove_value_provider(this); | 102 layer_animation_controller_->RemoveValueObserver(this); |
| 103 layer_animation_controller_->remove_value_provider(this); |
| 104 } |
101 | 105 |
102 RemoveFromScrollTree(); | 106 RemoveFromScrollTree(); |
103 RemoveFromClipTree(); | 107 RemoveFromClipTree(); |
104 | 108 |
105 // Remove the parent reference from all children and dependents. | 109 // Remove the parent reference from all children and dependents. |
106 RemoveAllChildren(); | 110 RemoveAllChildren(); |
107 if (mask_layer_.get()) { | 111 if (mask_layer_.get()) { |
108 DCHECK_EQ(this, mask_layer_->parent()); | 112 DCHECK_EQ(this, mask_layer_->parent()); |
109 mask_layer_->RemoveFromParent(); | 113 mask_layer_->RemoveFromParent(); |
110 } | 114 } |
(...skipping 18 matching lines...) Expand all Loading... |
129 | 133 |
130 for (size_t i = 0; i < children_.size(); ++i) | 134 for (size_t i = 0; i < children_.size(); ++i) |
131 children_[i]->SetLayerTreeHost(host); | 135 children_[i]->SetLayerTreeHost(host); |
132 | 136 |
133 if (mask_layer_.get()) | 137 if (mask_layer_.get()) |
134 mask_layer_->SetLayerTreeHost(host); | 138 mask_layer_->SetLayerTreeHost(host); |
135 if (replica_layer_.get()) | 139 if (replica_layer_.get()) |
136 replica_layer_->SetLayerTreeHost(host); | 140 replica_layer_->SetLayerTreeHost(host); |
137 | 141 |
138 if (host) { | 142 if (host) { |
139 layer_animation_controller_->SetAnimationRegistrar( | 143 RegisterForAnimations(host->animation_registrar()); |
140 host->animation_registrar()); | |
141 | |
142 if (host->settings().layer_transforms_should_scale_layer_contents) | 144 if (host->settings().layer_transforms_should_scale_layer_contents) |
143 reset_raster_scale_to_unknown(); | 145 reset_raster_scale_to_unknown(); |
144 } | 146 } |
145 | 147 |
146 if (host && layer_animation_controller_->has_any_animation()) | 148 if (host && layer_animation_controller_->has_any_animation()) |
147 host->SetNeedsCommit(); | 149 host->SetNeedsCommit(); |
148 } | 150 } |
149 | 151 |
150 void Layer::SetNeedsUpdate() { | 152 void Layer::SetNeedsUpdate() { |
151 if (layer_tree_host_ && !ignore_set_needs_commit_) | 153 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() { | 1345 void Layer::OnAnimationWaitingForDeletion() { |
1344 // Animations are only deleted during PushProperties. | 1346 // Animations are only deleted during PushProperties. |
1345 SetNeedsPushProperties(); | 1347 SetNeedsPushProperties(); |
1346 } | 1348 } |
1347 | 1349 |
1348 bool Layer::IsActive() const { | 1350 bool Layer::IsActive() const { |
1349 return true; | 1351 return true; |
1350 } | 1352 } |
1351 | 1353 |
1352 bool Layer::AddAnimation(scoped_ptr <Animation> animation) { | 1354 bool Layer::AddAnimation(scoped_ptr <Animation> animation) { |
| 1355 DCHECK(layer_animation_controller_); |
1353 if (!layer_animation_controller_->animation_registrar()) | 1356 if (!layer_animation_controller_->animation_registrar()) |
1354 return false; | 1357 return false; |
1355 | 1358 |
1356 if (animation->target_property() == Animation::SCROLL_OFFSET && | 1359 if (animation->target_property() == Animation::SCROLL_OFFSET && |
1357 !layer_animation_controller_->animation_registrar() | 1360 !layer_animation_controller_->animation_registrar() |
1358 ->supports_scroll_animations()) | 1361 ->supports_scroll_animations()) |
1359 return false; | 1362 return false; |
1360 | 1363 |
1361 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", | 1364 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", |
1362 !layer_tree_host_); | 1365 !layer_tree_host_); |
(...skipping 24 matching lines...) Expand all Loading... |
1387 layer_animation_controller_->RemoveValueObserver(this); | 1390 layer_animation_controller_->RemoveValueObserver(this); |
1388 layer_animation_controller_ = controller; | 1391 layer_animation_controller_ = controller; |
1389 layer_animation_controller_->AddValueObserver(this); | 1392 layer_animation_controller_->AddValueObserver(this); |
1390 SetNeedsCommit(); | 1393 SetNeedsCommit(); |
1391 } | 1394 } |
1392 | 1395 |
1393 bool Layer::HasActiveAnimation() const { | 1396 bool Layer::HasActiveAnimation() const { |
1394 return layer_animation_controller_->HasActiveAnimation(); | 1397 return layer_animation_controller_->HasActiveAnimation(); |
1395 } | 1398 } |
1396 | 1399 |
| 1400 void Layer::RegisterForAnimations(AnimationRegistrar* registrar) { |
| 1401 if (layer_animation_controller_) |
| 1402 layer_animation_controller_->SetAnimationRegistrar(registrar); |
| 1403 } |
| 1404 |
1397 void Layer::AddLayerAnimationEventObserver( | 1405 void Layer::AddLayerAnimationEventObserver( |
1398 LayerAnimationEventObserver* animation_observer) { | 1406 LayerAnimationEventObserver* animation_observer) { |
| 1407 DCHECK(layer_animation_controller_); |
1399 layer_animation_controller_->AddEventObserver(animation_observer); | 1408 layer_animation_controller_->AddEventObserver(animation_observer); |
1400 } | 1409 } |
1401 | 1410 |
1402 void Layer::RemoveLayerAnimationEventObserver( | 1411 void Layer::RemoveLayerAnimationEventObserver( |
1403 LayerAnimationEventObserver* animation_observer) { | 1412 LayerAnimationEventObserver* animation_observer) { |
| 1413 DCHECK(layer_animation_controller_); |
1404 layer_animation_controller_->RemoveEventObserver(animation_observer); | 1414 layer_animation_controller_->RemoveEventObserver(animation_observer); |
1405 } | 1415 } |
1406 | 1416 |
1407 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { | 1417 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { |
1408 if (contents_opaque()) | 1418 if (contents_opaque()) |
1409 return SimpleEnclosedRegion(visible_content_rect()); | 1419 return SimpleEnclosedRegion(visible_content_rect()); |
1410 return SimpleEnclosedRegion(); | 1420 return SimpleEnclosedRegion(); |
1411 } | 1421 } |
1412 | 1422 |
1413 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { | 1423 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 | 1478 |
1469 void Layer::DidBeginTracing() { | 1479 void Layer::DidBeginTracing() { |
1470 // We'll be dumping layer trees as part of trace, so make sure | 1480 // We'll be dumping layer trees as part of trace, so make sure |
1471 // PushPropertiesTo() propagates layer debug info to the impl | 1481 // PushPropertiesTo() propagates layer debug info to the impl |
1472 // side -- otherwise this won't happen for the the layers that | 1482 // side -- otherwise this won't happen for the the layers that |
1473 // remain unchanged since tracing started. | 1483 // remain unchanged since tracing started. |
1474 SetNeedsPushProperties(); | 1484 SetNeedsPushProperties(); |
1475 } | 1485 } |
1476 | 1486 |
1477 } // namespace cc | 1487 } // namespace cc |
OLD | NEW |