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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/animation/animation_delegate.h" | 9 #include "cc/animation/animation_delegate.h" |
10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
11 #include "cc/animation/animation_timeline.h" | 11 #include "cc/animation/animation_timeline.h" |
12 #include "cc/animation/element_animations.h" | 12 #include "cc/animation/element_animations.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { | 16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { |
17 return make_scoped_refptr(new AnimationPlayer(id)); | 17 return make_scoped_refptr(new AnimationPlayer(id)); |
18 } | 18 } |
19 | 19 |
20 AnimationPlayer::AnimationPlayer(int id) | 20 AnimationPlayer::AnimationPlayer(int id) |
21 : animation_host_(), | 21 : animation_host_(), |
22 animation_timeline_(), | 22 animation_timeline_(), |
23 element_animations_(), | 23 element_animations_(), |
24 animation_delegate_(), | 24 animation_delegate_(), |
25 id_(id) { | 25 id_(id), |
| 26 needs_push_properties_(false) { |
26 DCHECK(id_); | 27 DCHECK(id_); |
27 } | 28 } |
28 | 29 |
29 AnimationPlayer::~AnimationPlayer() { | 30 AnimationPlayer::~AnimationPlayer() { |
30 DCHECK(!animation_timeline_); | 31 DCHECK(!animation_timeline_); |
31 DCHECK(!element_animations_); | 32 DCHECK(!element_animations_); |
32 } | 33 } |
33 | 34 |
34 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { | 35 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { |
35 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); | 36 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 animation_host_->UnregisterPlayerForElement(element_id_, this); | 98 animation_host_->UnregisterPlayerForElement(element_id_, this); |
98 } | 99 } |
99 | 100 |
100 void AnimationPlayer::BindElementAnimations() { | 101 void AnimationPlayer::BindElementAnimations() { |
101 DCHECK(!element_animations_); | 102 DCHECK(!element_animations_); |
102 element_animations_ = | 103 element_animations_ = |
103 animation_host_->GetElementAnimationsForElementId(element_id_); | 104 animation_host_->GetElementAnimationsForElementId(element_id_); |
104 DCHECK(element_animations_); | 105 DCHECK(element_animations_); |
105 | 106 |
106 // Pass all accumulated animations to ElementAnimations. | 107 // Pass all accumulated animations to ElementAnimations. |
107 for (auto& animation : animations_) { | 108 for (auto& animation : animations_) |
108 element_animations_->AddAnimation(std::move(animation)); | 109 element_animations_->AddAnimation(std::move(animation)); |
109 } | 110 |
110 if (!animations_.empty()) | 111 if (!animations_.empty()) |
111 SetNeedsCommit(); | 112 SetNeedsCommit(); |
| 113 SetNeedsPushProperties(); |
| 114 |
112 animations_.clear(); | 115 animations_.clear(); |
113 } | 116 } |
114 | 117 |
115 void AnimationPlayer::UnbindElementAnimations() { | 118 void AnimationPlayer::UnbindElementAnimations() { |
| 119 SetNeedsPushProperties(); |
| 120 |
116 element_animations_ = nullptr; | 121 element_animations_ = nullptr; |
117 DCHECK(animations_.empty()); | 122 DCHECK(animations_.empty()); |
118 } | 123 } |
119 | 124 |
120 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { | 125 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { |
121 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || | 126 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || |
122 (animation_host_ && animation_host_->SupportsScrollAnimations())); | 127 (animation_host_ && animation_host_->SupportsScrollAnimations())); |
123 | 128 |
124 if (element_animations_) { | 129 if (element_animations_) { |
125 element_animations_->AddAnimation(std::move(animation)); | 130 element_animations_->AddAnimation(std::move(animation)); |
126 SetNeedsCommit(); | 131 SetNeedsCommit(); |
| 132 SetNeedsPushProperties(); |
127 } else { | 133 } else { |
128 animations_.push_back(std::move(animation)); | 134 animations_.push_back(std::move(animation)); |
129 } | 135 } |
130 } | 136 } |
131 | 137 |
132 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { | 138 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { |
133 DCHECK(element_animations_); | 139 DCHECK(element_animations_); |
134 element_animations_->PauseAnimation( | 140 element_animations_->PauseAnimation( |
135 animation_id, base::TimeDelta::FromSecondsD(time_offset)); | 141 animation_id, base::TimeDelta::FromSecondsD(time_offset)); |
136 SetNeedsCommit(); | 142 SetNeedsCommit(); |
| 143 SetNeedsPushProperties(); |
137 } | 144 } |
138 | 145 |
139 void AnimationPlayer::RemoveAnimation(int animation_id) { | 146 void AnimationPlayer::RemoveAnimation(int animation_id) { |
140 if (element_animations_) { | 147 if (element_animations_) { |
141 element_animations_->RemoveAnimation(animation_id); | 148 element_animations_->RemoveAnimation(animation_id); |
142 SetNeedsCommit(); | 149 SetNeedsCommit(); |
| 150 SetNeedsPushProperties(); |
143 } else { | 151 } else { |
144 auto animations_to_remove = std::remove_if( | 152 auto animations_to_remove = std::remove_if( |
145 animations_.begin(), animations_.end(), | 153 animations_.begin(), animations_.end(), |
146 [animation_id](const std::unique_ptr<Animation>& animation) { | 154 [animation_id](const std::unique_ptr<Animation>& animation) { |
147 return animation->id() == animation_id; | 155 return animation->id() == animation_id; |
148 }); | 156 }); |
149 animations_.erase(animations_to_remove, animations_.end()); | 157 animations_.erase(animations_to_remove, animations_.end()); |
150 } | 158 } |
151 } | 159 } |
152 | 160 |
153 void AnimationPlayer::AbortAnimation(int animation_id) { | 161 void AnimationPlayer::AbortAnimation(int animation_id) { |
154 DCHECK(element_animations_); | 162 DCHECK(element_animations_); |
155 element_animations_->AbortAnimation(animation_id); | 163 element_animations_->AbortAnimation(animation_id); |
156 SetNeedsCommit(); | 164 SetNeedsCommit(); |
| 165 SetNeedsPushProperties(); |
157 } | 166 } |
158 | 167 |
159 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, | 168 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, |
160 bool needs_completion) { | 169 bool needs_completion) { |
161 if (element_animations_) { | 170 if (element_animations_) { |
162 element_animations_->AbortAnimations(target_property, needs_completion); | 171 element_animations_->AbortAnimations(target_property, needs_completion); |
163 SetNeedsCommit(); | 172 SetNeedsCommit(); |
| 173 SetNeedsPushProperties(); |
164 } else { | 174 } else { |
165 auto animations_to_remove = std::remove_if( | 175 auto animations_to_remove = std::remove_if( |
166 animations_.begin(), animations_.end(), | 176 animations_.begin(), animations_.end(), |
167 [target_property](const std::unique_ptr<Animation>& animation) { | 177 [target_property](const std::unique_ptr<Animation>& animation) { |
168 return animation->target_property() == target_property; | 178 return animation->target_property() == target_property; |
169 }); | 179 }); |
170 animations_.erase(animations_to_remove, animations_.end()); | 180 animations_.erase(animations_to_remove, animations_.end()); |
171 } | 181 } |
172 } | 182 } |
173 | 183 |
174 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { | 184 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { |
| 185 if (!needs_push_properties_) |
| 186 return; |
| 187 needs_push_properties_ = false; |
| 188 |
175 if (element_id_ != player_impl->element_id()) { | 189 if (element_id_ != player_impl->element_id()) { |
176 if (player_impl->element_id()) | 190 if (player_impl->element_id()) |
177 player_impl->DetachElement(); | 191 player_impl->DetachElement(); |
178 if (element_id_) | 192 if (element_id_) |
179 player_impl->AttachElement(element_id_); | 193 player_impl->AttachElement(element_id_); |
180 } | 194 } |
181 } | 195 } |
182 | 196 |
183 void AnimationPlayer::NotifyAnimationStarted( | 197 void AnimationPlayer::NotifyAnimationStarted( |
184 base::TimeTicks monotonic_time, | 198 base::TimeTicks monotonic_time, |
(...skipping 15 matching lines...) Expand all Loading... |
200 | 214 |
201 void AnimationPlayer::NotifyAnimationAborted( | 215 void AnimationPlayer::NotifyAnimationAborted( |
202 base::TimeTicks monotonic_time, | 216 base::TimeTicks monotonic_time, |
203 TargetProperty::Type target_property, | 217 TargetProperty::Type target_property, |
204 int group) { | 218 int group) { |
205 if (animation_delegate_) | 219 if (animation_delegate_) |
206 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property, | 220 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property, |
207 group); | 221 group); |
208 } | 222 } |
209 | 223 |
| 224 void AnimationPlayer::NotifyAnimationWaitingForDeletion() { |
| 225 // We need to purge animations marked for deletion. |
| 226 SetNeedsPushProperties(); |
| 227 } |
| 228 |
210 void AnimationPlayer::NotifyAnimationTakeover( | 229 void AnimationPlayer::NotifyAnimationTakeover( |
211 base::TimeTicks monotonic_time, | 230 base::TimeTicks monotonic_time, |
212 TargetProperty::Type target_property, | 231 TargetProperty::Type target_property, |
213 double animation_start_time, | 232 double animation_start_time, |
214 std::unique_ptr<AnimationCurve> curve) { | 233 std::unique_ptr<AnimationCurve> curve) { |
| 234 // We need to purge animations marked for deletion on CT. |
| 235 SetNeedsPushProperties(); |
| 236 |
215 if (animation_delegate_) { | 237 if (animation_delegate_) { |
216 DCHECK(curve); | 238 DCHECK(curve); |
217 animation_delegate_->NotifyAnimationTakeover( | 239 animation_delegate_->NotifyAnimationTakeover( |
218 monotonic_time, target_property, animation_start_time, | 240 monotonic_time, target_property, animation_start_time, |
219 std::move(curve)); | 241 std::move(curve)); |
220 } | 242 } |
221 } | 243 } |
222 | 244 |
223 void AnimationPlayer::SetNeedsCommit() { | 245 void AnimationPlayer::SetNeedsCommit() { |
224 DCHECK(animation_host_); | 246 DCHECK(animation_host_); |
225 animation_host_->SetNeedsCommit(); | 247 animation_host_->SetNeedsCommit(); |
226 animation_host_->SetNeedsRebuildPropertyTrees(); | 248 } |
| 249 |
| 250 void AnimationPlayer::SetNeedsPushProperties() { |
| 251 needs_push_properties_ = true; |
| 252 |
| 253 DCHECK(animation_timeline_); |
| 254 animation_timeline_->SetNeedsPushProperties(); |
| 255 |
| 256 DCHECK(element_animations_); |
| 257 element_animations_->SetNeedsPushProperties(); |
227 } | 258 } |
228 | 259 |
229 } // namespace cc | 260 } // namespace cc |
OLD | NEW |