OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/animation/animation_player.h" | 5 #include "cc/animation/animation_player.h" |
6 | 6 |
7 #include "cc/animation/animation_delegate.h" | 7 #include "cc/animation/animation_delegate.h" |
8 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
9 #include "cc/animation/animation_timeline.h" | 9 #include "cc/animation/animation_timeline.h" |
10 #include "cc/animation/element_animations.h" | 10 #include "cc/animation/element_animations.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { | 14 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { |
15 return make_scoped_refptr(new AnimationPlayer(id)); | 15 return make_scoped_refptr(new AnimationPlayer(id)); |
16 } | 16 } |
17 | 17 |
18 AnimationPlayer::AnimationPlayer(int id) | 18 AnimationPlayer::AnimationPlayer(int id) |
19 : animation_host_(), | 19 : animation_host_(), |
20 animation_timeline_(), | 20 animation_timeline_(), |
21 element_animations_(), | 21 element_animations_(), |
22 layer_animation_delegate_(), | 22 layer_animation_delegate_(), |
23 id_(id), | 23 id_(id), |
24 layer_id_(0) { | 24 element_id_(0) { |
25 DCHECK(id_); | 25 DCHECK(id_); |
26 } | 26 } |
27 | 27 |
28 AnimationPlayer::~AnimationPlayer() { | 28 AnimationPlayer::~AnimationPlayer() { |
29 DCHECK(!animation_timeline_); | 29 DCHECK(!animation_timeline_); |
30 DCHECK(!element_animations_); | 30 DCHECK(!element_animations_); |
31 } | 31 } |
32 | 32 |
33 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { | 33 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { |
34 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); | 34 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); |
35 return player; | 35 return player; |
36 } | 36 } |
37 | 37 |
38 void AnimationPlayer::SetAnimationHost(AnimationHost* animation_host) { | 38 void AnimationPlayer::SetAnimationHost(AnimationHost* animation_host) { |
39 animation_host_ = animation_host; | 39 animation_host_ = animation_host; |
40 } | 40 } |
41 | 41 |
42 void AnimationPlayer::SetAnimationTimeline(AnimationTimeline* timeline) { | 42 void AnimationPlayer::SetAnimationTimeline(AnimationTimeline* timeline) { |
43 if (animation_timeline_ == timeline) | 43 if (animation_timeline_ == timeline) |
44 return; | 44 return; |
45 | 45 |
46 // We need to unregister player to manage ElementAnimations and observers | 46 // We need to unregister player to manage ElementAnimations and observers |
47 // properly. | 47 // properly. |
48 if (layer_id_ && element_animations_) | 48 if (element_id_ && element_animations_) |
49 UnregisterPlayer(); | 49 UnregisterPlayer(); |
50 | 50 |
51 animation_timeline_ = timeline; | 51 animation_timeline_ = timeline; |
52 | 52 |
53 // Register player only if layer AND host attached. | 53 // Register player only if layer AND host attached. |
54 if (layer_id_ && animation_host_) | 54 if (element_id_ && animation_host_) |
55 RegisterPlayer(); | 55 RegisterPlayer(); |
56 } | 56 } |
57 | 57 |
58 void AnimationPlayer::AttachLayer(int layer_id) { | 58 void AnimationPlayer::AttachLayer(ElementId element_id) { |
59 DCHECK_EQ(layer_id_, 0); | 59 DCHECK_EQ(element_id_, 0); |
60 DCHECK(layer_id); | 60 DCHECK(element_id); |
61 | 61 |
62 layer_id_ = layer_id; | 62 element_id_ = element_id; |
63 | 63 |
64 // Register player only if layer AND host attached. | 64 // Register player only if layer AND host attached. |
65 if (animation_host_) | 65 if (animation_host_) |
66 RegisterPlayer(); | 66 RegisterPlayer(); |
67 } | 67 } |
68 | 68 |
69 void AnimationPlayer::DetachLayer() { | 69 void AnimationPlayer::DetachLayer() { |
70 DCHECK(layer_id_); | 70 DCHECK(element_id_); |
71 | 71 |
72 if (animation_host_) | 72 if (animation_host_) |
73 UnregisterPlayer(); | 73 UnregisterPlayer(); |
74 | 74 |
75 layer_id_ = 0; | 75 element_id_ = 0; |
76 } | 76 } |
77 | 77 |
78 void AnimationPlayer::RegisterPlayer() { | 78 void AnimationPlayer::RegisterPlayer() { |
79 DCHECK(layer_id_); | 79 DCHECK(element_id_); |
80 DCHECK(animation_host_); | 80 DCHECK(animation_host_); |
81 DCHECK(!element_animations_); | 81 DCHECK(!element_animations_); |
82 | 82 |
83 // Create ElementAnimations or re-use existing. | 83 // Create ElementAnimations or re-use existing. |
84 animation_host_->RegisterPlayerForLayer(layer_id_, this); | 84 animation_host_->RegisterPlayerForLayer(element_id_, this); |
85 // Get local reference to shared ElementAnimations. | 85 // Get local reference to shared ElementAnimations. |
86 BindElementAnimations(); | 86 BindElementAnimations(); |
87 } | 87 } |
88 | 88 |
89 void AnimationPlayer::UnregisterPlayer() { | 89 void AnimationPlayer::UnregisterPlayer() { |
90 DCHECK(layer_id_); | 90 DCHECK(element_id_); |
91 DCHECK(animation_host_); | 91 DCHECK(animation_host_); |
92 DCHECK(element_animations_); | 92 DCHECK(element_animations_); |
93 | 93 |
94 UnbindElementAnimations(); | 94 UnbindElementAnimations(); |
95 // Destroy ElementAnimations or release it if it's still needed. | 95 // Destroy ElementAnimations or release it if it's still needed. |
96 animation_host_->UnregisterPlayerForLayer(layer_id_, this); | 96 animation_host_->UnregisterPlayerForLayer(element_id_, this); |
97 } | 97 } |
98 | 98 |
99 void AnimationPlayer::BindElementAnimations() { | 99 void AnimationPlayer::BindElementAnimations() { |
100 DCHECK(!element_animations_); | 100 DCHECK(!element_animations_); |
101 element_animations_ = | 101 element_animations_ = |
102 animation_host_->GetElementAnimationsForLayerId(layer_id_); | 102 animation_host_->GetElementAnimationsForLayerId(element_id_); |
103 DCHECK(element_animations_); | 103 DCHECK(element_animations_); |
104 | 104 |
105 // Pass all accumulated animations to ElementAnimations. | 105 // Pass all accumulated animations to ElementAnimations. |
106 for (auto& animation : animations_) { | 106 for (auto& animation : animations_) { |
107 element_animations_->AddAnimation(std::move(animation)); | 107 element_animations_->AddAnimation(std::move(animation)); |
108 } | 108 } |
109 if (!animations_.empty()) | 109 if (!animations_.empty()) |
110 SetNeedsCommit(); | 110 SetNeedsCommit(); |
111 animations_.clear(); | 111 animations_.clear(); |
112 } | 112 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 auto animations_to_remove = std::remove_if( | 164 auto animations_to_remove = std::remove_if( |
165 animations_.begin(), animations_.end(), | 165 animations_.begin(), animations_.end(), |
166 [target_property](const std::unique_ptr<Animation>& animation) { | 166 [target_property](const std::unique_ptr<Animation>& animation) { |
167 return animation->target_property() == target_property; | 167 return animation->target_property() == target_property; |
168 }); | 168 }); |
169 animations_.erase(animations_to_remove, animations_.end()); | 169 animations_.erase(animations_to_remove, animations_.end()); |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { | 173 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { |
174 if (layer_id_ != player_impl->layer_id()) { | 174 if (element_id_ != player_impl->element_id()) { |
175 if (player_impl->layer_id()) | 175 if (player_impl->element_id()) |
176 player_impl->DetachLayer(); | 176 player_impl->DetachLayer(); |
177 if (layer_id_) | 177 if (element_id_) |
178 player_impl->AttachLayer(layer_id_); | 178 player_impl->AttachLayer(element_id_); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void AnimationPlayer::NotifyAnimationStarted( | 182 void AnimationPlayer::NotifyAnimationStarted( |
183 base::TimeTicks monotonic_time, | 183 base::TimeTicks monotonic_time, |
184 TargetProperty::Type target_property, | 184 TargetProperty::Type target_property, |
185 int group) { | 185 int group) { |
186 if (layer_animation_delegate_) | 186 if (layer_animation_delegate_) |
187 layer_animation_delegate_->NotifyAnimationStarted(monotonic_time, | 187 layer_animation_delegate_->NotifyAnimationStarted(monotonic_time, |
188 target_property, group); | 188 target_property, group); |
(...skipping 30 matching lines...) Expand all Loading... |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 void AnimationPlayer::SetNeedsCommit() { | 222 void AnimationPlayer::SetNeedsCommit() { |
223 DCHECK(animation_host_); | 223 DCHECK(animation_host_); |
224 animation_host_->SetNeedsCommit(); | 224 animation_host_->SetNeedsCommit(); |
225 animation_host_->SetNeedsRebuildPropertyTrees(); | 225 animation_host_->SetNeedsRebuildPropertyTrees(); |
226 } | 226 } |
227 | 227 |
228 } // namespace cc | 228 } // namespace cc |
OLD | NEW |