Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: cc/animation/animation_player.cc

Issue 2554773002: CC Animation: Rename Active Players to Ticking Players. (Closed)
Patch Set: Rename the argument. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/animation/animation_player.h ('k') | cc/animation/animation_player_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_events.h" 10 #include "cc/animation/animation_events.h"
11 #include "cc/animation/animation_host.h" 11 #include "cc/animation/animation_host.h"
12 #include "cc/animation/animation_timeline.h" 12 #include "cc/animation/animation_timeline.h"
13 #include "cc/animation/scroll_offset_animation_curve.h" 13 #include "cc/animation/scroll_offset_animation_curve.h"
14 #include "cc/trees/property_animation_state.h" 14 #include "cc/trees/property_animation_state.h"
15 15
16 namespace cc { 16 namespace cc {
17 17
18 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { 18 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) {
19 return make_scoped_refptr(new AnimationPlayer(id)); 19 return make_scoped_refptr(new AnimationPlayer(id));
20 } 20 }
21 21
22 AnimationPlayer::AnimationPlayer(int id) 22 AnimationPlayer::AnimationPlayer(int id)
23 : animation_host_(), 23 : animation_host_(),
24 animation_timeline_(), 24 animation_timeline_(),
25 element_animations_(), 25 element_animations_(),
26 animation_delegate_(), 26 animation_delegate_(),
27 id_(id), 27 id_(id),
28 needs_push_properties_(false), 28 needs_push_properties_(false),
29 needs_to_start_animations_(false), 29 needs_to_start_animations_(false),
30 is_active_(false), 30 is_ticking_(false),
31 scroll_offset_animation_was_interrupted_(false) { 31 scroll_offset_animation_was_interrupted_(false) {
32 DCHECK(id_); 32 DCHECK(id_);
33 } 33 }
34 34
35 AnimationPlayer::~AnimationPlayer() { 35 AnimationPlayer::~AnimationPlayer() {
36 DCHECK(!animation_timeline_); 36 DCHECK(!animation_timeline_);
37 DCHECK(!element_animations_); 37 DCHECK(!element_animations_);
38 } 38 }
39 39
40 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { 40 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 SetNeedsPushProperties(); 132 SetNeedsPushProperties();
133 } 133 }
134 } 134 }
135 135
136 void AnimationPlayer::AnimationAdded() { 136 void AnimationPlayer::AnimationAdded() {
137 DCHECK(element_animations_); 137 DCHECK(element_animations_);
138 138
139 SetNeedsCommit(); 139 SetNeedsCommit();
140 needs_to_start_animations_ = true; 140 needs_to_start_animations_ = true;
141 141
142 UpdateActivation(ActivationType::NORMAL); 142 UpdateTickingState(UpdateTickingType::NORMAL);
143 element_animations_->UpdateClientAnimationState(); 143 element_animations_->UpdateClientAnimationState();
144 } 144 }
145 145
146 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { 146 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) {
147 const base::TimeDelta time_delta = base::TimeDelta::FromSecondsD(time_offset); 147 const base::TimeDelta time_delta = base::TimeDelta::FromSecondsD(time_offset);
148 148
149 for (size_t i = 0; i < animations_.size(); ++i) { 149 for (size_t i = 0; i < animations_.size(); ++i) {
150 if (animations_[i]->id() == animation_id) { 150 if (animations_[i]->id() == animation_id) {
151 animations_[i]->SetRunState(Animation::PAUSED, 151 animations_[i]->SetRunState(Animation::PAUSED,
152 time_delta + animations_[i]->start_time() + 152 time_delta + animations_[i]->start_time() +
(...skipping 23 matching lines...) Expand all
176 if (element_animations_) 176 if (element_animations_)
177 scroll_offset_animation_was_interrupted_ = true; 177 scroll_offset_animation_was_interrupted_ = true;
178 } else if (!(*it)->is_finished()) { 178 } else if (!(*it)->is_finished()) {
179 animation_removed = true; 179 animation_removed = true;
180 } 180 }
181 } 181 }
182 182
183 animations_.erase(animations_to_remove, animations_.end()); 183 animations_.erase(animations_to_remove, animations_.end());
184 184
185 if (element_animations_) { 185 if (element_animations_) {
186 UpdateActivation(ActivationType::NORMAL); 186 UpdateTickingState(UpdateTickingType::NORMAL);
187 if (animation_removed) 187 if (animation_removed)
188 element_animations_->UpdateClientAnimationState(); 188 element_animations_->UpdateClientAnimationState();
189 SetNeedsCommit(); 189 SetNeedsCommit();
190 SetNeedsPushProperties(); 190 SetNeedsPushProperties();
191 } 191 }
192 } 192 }
193 193
194 void AnimationPlayer::AbortAnimation(int animation_id) { 194 void AnimationPlayer::AbortAnimation(int animation_id) {
195 if (Animation* animation = GetAnimationById(animation_id)) { 195 if (Animation* animation = GetAnimationById(animation_id)) {
196 if (!animation->is_finished()) { 196 if (!animation->is_finished()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 PurgeAnimationsMarkedForDeletion(); 255 PurgeAnimationsMarkedForDeletion();
256 PushNewAnimationsToImplThread(player_impl); 256 PushNewAnimationsToImplThread(player_impl);
257 257
258 // Remove finished impl side animations only after pushing, 258 // Remove finished impl side animations only after pushing,
259 // and only after the animations are deleted on the main thread 259 // and only after the animations are deleted on the main thread
260 // this insures we will never push an animation twice. 260 // this insures we will never push an animation twice.
261 RemoveAnimationsCompletedOnMainThread(player_impl); 261 RemoveAnimationsCompletedOnMainThread(player_impl);
262 262
263 PushPropertiesToImplThread(player_impl); 263 PushPropertiesToImplThread(player_impl);
264 264
265 player_impl->UpdateActivation(ActivationType::NORMAL); 265 player_impl->UpdateTickingState(UpdateTickingType::NORMAL);
266 } 266 }
267 267
268 void AnimationPlayer::Animate(base::TimeTicks monotonic_time) { 268 void AnimationPlayer::Tick(base::TimeTicks monotonic_time) {
269 DCHECK(!monotonic_time.is_null()); 269 DCHECK(!monotonic_time.is_null());
270 DCHECK(element_animations_); 270 DCHECK(element_animations_);
271 271
272 if (!element_animations_->has_element_in_any_list()) 272 if (!element_animations_->has_element_in_any_list())
273 return; 273 return;
274 274
275 if (needs_to_start_animations()) 275 if (needs_to_start_animations())
276 StartAnimations(monotonic_time); 276 StartAnimations(monotonic_time);
277 277
278 TickAnimations(monotonic_time); 278 TickAnimations(monotonic_time);
(...skipping 19 matching lines...) Expand all
298 MarkFinishedAnimations(last_tick_time_); 298 MarkFinishedAnimations(last_tick_time_);
299 MarkAnimationsForDeletion(last_tick_time_, events); 299 MarkAnimationsForDeletion(last_tick_time_, events);
300 300
301 if (start_ready_animations) { 301 if (start_ready_animations) {
302 if (needs_to_start_animations()) { 302 if (needs_to_start_animations()) {
303 StartAnimations(last_tick_time_); 303 StartAnimations(last_tick_time_);
304 PromoteStartedAnimations(last_tick_time_, events); 304 PromoteStartedAnimations(last_tick_time_, events);
305 } 305 }
306 } 306 }
307 307
308 UpdateActivation(ActivationType::NORMAL); 308 UpdateTickingState(UpdateTickingType::NORMAL);
309 } 309 }
310 310
311 void AnimationPlayer::UpdateActivation(ActivationType type) { 311 void AnimationPlayer::UpdateTickingState(UpdateTickingType type) {
312 bool force = type == ActivationType::FORCE; 312 bool force = type == UpdateTickingType::FORCE;
313 if (animation_host_) { 313 if (animation_host_) {
314 bool was_active = is_active_; 314 bool was_ticking = is_ticking_;
315 is_active_ = HasNonDeletedAnimation(); 315 is_ticking_ = HasNonDeletedAnimation();
316 316
317 bool has_element_in_any_list = 317 bool has_element_in_any_list =
318 element_animations_->has_element_in_any_list(); 318 element_animations_->has_element_in_any_list();
319 319
320 if (is_active_ && ((!was_active && has_element_in_any_list) || force)) { 320 if (is_ticking_ && ((!was_ticking && has_element_in_any_list) || force)) {
321 animation_host_->ActivateAnimationPlayer(this); 321 animation_host_->AddToTicking(this);
322 } else if (!is_active_ && (was_active || force)) { 322 } else if (!is_ticking_ && (was_ticking || force)) {
323 Deactivate(); 323 RemoveFromTicking();
324 } 324 }
325 } 325 }
326 } 326 }
327 327
328 void AnimationPlayer::Deactivate() { 328 void AnimationPlayer::RemoveFromTicking() {
329 DCHECK(animation_host_); 329 DCHECK(animation_host_);
330 // Resetting last_tick_time_ here ensures that calling ::UpdateState 330 // Resetting last_tick_time_ here ensures that calling ::UpdateState
331 // before ::Animate doesn't start an animation. 331 // before ::Animate doesn't start an animation.
332 last_tick_time_ = base::TimeTicks(); 332 last_tick_time_ = base::TimeTicks();
333 animation_host_->DeactivateAnimationPlayer(this); 333 animation_host_->RemoveFromTicking(this);
334 } 334 }
335 335
336 bool AnimationPlayer::NotifyAnimationStarted(const AnimationEvent& event) { 336 bool AnimationPlayer::NotifyAnimationStarted(const AnimationEvent& event) {
337 DCHECK(!event.is_impl_only); 337 DCHECK(!event.is_impl_only);
338 338
339 for (size_t i = 0; i < animations_.size(); ++i) { 339 for (size_t i = 0; i < animations_.size(); ++i) {
340 if (animations_[i]->group() == event.group_id && 340 if (animations_[i]->group() == event.group_id &&
341 animations_[i]->target_property() == event.target_property && 341 animations_[i]->target_property() == event.target_property &&
342 animations_[i]->needs_synchronized_start_time()) { 342 animations_[i]->needs_synchronized_start_time()) {
343 animations_[i]->set_needs_synchronized_start_time(false); 343 animations_[i]->set_needs_synchronized_start_time(false);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 void AnimationPlayer::SetNeedsPushProperties() { 425 void AnimationPlayer::SetNeedsPushProperties() {
426 needs_push_properties_ = true; 426 needs_push_properties_ = true;
427 427
428 DCHECK(animation_timeline_); 428 DCHECK(animation_timeline_);
429 animation_timeline_->SetNeedsPushProperties(); 429 animation_timeline_->SetNeedsPushProperties();
430 430
431 DCHECK(element_animations_); 431 DCHECK(element_animations_);
432 element_animations_->SetNeedsPushProperties(); 432 element_animations_->SetNeedsPushProperties();
433 } 433 }
434 434
435 bool AnimationPlayer::HasActiveAnimation() const { 435 bool AnimationPlayer::HasTickingAnimation() const {
436 for (size_t i = 0; i < animations_.size(); ++i) { 436 for (size_t i = 0; i < animations_.size(); ++i) {
437 if (!animations_[i]->is_finished()) 437 if (!animations_[i]->is_finished())
438 return true; 438 return true;
439 } 439 }
440 return false; 440 return false;
441 } 441 }
442 442
443 bool AnimationPlayer::HasNonDeletedAnimation() const { 443 bool AnimationPlayer::HasNonDeletedAnimation() const {
444 for (size_t i = 0; i < animations_.size(); ++i) { 444 for (size_t i = 0; i < animations_.size(); ++i) {
445 if (animations_[i]->run_state() != Animation::WAITING_FOR_DELETION) 445 if (animations_[i]->run_state() != Animation::WAITING_FOR_DELETION)
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 !animation->affects_pending_elements(); 816 !animation->affects_pending_elements();
817 }; 817 };
818 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), 818 animations_.erase(std::remove_if(animations_.begin(), animations_.end(),
819 affects_no_elements), 819 affects_no_elements),
820 animations_.end()); 820 animations_.end());
821 821
822 if (animation_activated) 822 if (animation_activated)
823 element_animations_->UpdateClientAnimationState(); 823 element_animations_->UpdateClientAnimationState();
824 824
825 scroll_offset_animation_was_interrupted_ = false; 825 scroll_offset_animation_was_interrupted_ = false;
826 UpdateActivation(ActivationType::NORMAL); 826 UpdateTickingState(UpdateTickingType::NORMAL);
827 } 827 }
828 828
829 bool AnimationPlayer::HasFilterAnimationThatInflatesBounds() const { 829 bool AnimationPlayer::HasFilterAnimationThatInflatesBounds() const {
830 for (size_t i = 0; i < animations_.size(); ++i) { 830 for (size_t i = 0; i < animations_.size(); ++i) {
831 if (!animations_[i]->is_finished() && 831 if (!animations_[i]->is_finished() &&
832 animations_[i]->target_property() == TargetProperty::FILTER && 832 animations_[i]->target_property() == TargetProperty::FILTER &&
833 animations_[i] 833 animations_[i]
834 ->curve() 834 ->curve()
835 ->ToFilterAnimationCurve() 835 ->ToFilterAnimationCurve()
836 ->HasFilterThatMovesPixels()) 836 ->HasFilterThatMovesPixels())
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 if (current_impl) 1193 if (current_impl)
1194 animations_[i]->PushPropertiesTo(current_impl); 1194 animations_[i]->PushPropertiesTo(current_impl);
1195 } 1195 }
1196 1196
1197 animation_player_impl->scroll_offset_animation_was_interrupted_ = 1197 animation_player_impl->scroll_offset_animation_was_interrupted_ =
1198 scroll_offset_animation_was_interrupted_; 1198 scroll_offset_animation_was_interrupted_;
1199 scroll_offset_animation_was_interrupted_ = false; 1199 scroll_offset_animation_was_interrupted_ = false;
1200 } 1200 }
1201 1201
1202 } // namespace cc 1202 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_player.h ('k') | cc/animation/animation_player_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698