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

Side by Side Diff: cc/animation/animation_host.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_host.h ('k') | cc/animation/animation_player.h » ('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_host.h" 5 #include "cc/animation/animation_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 GetElementAnimationsForElementId(element_id); 150 GetElementAnimationsForElementId(element_id);
151 DCHECK(element_animations); 151 DCHECK(element_animations);
152 element_animations->RemovePlayer(player); 152 element_animations->RemovePlayer(player);
153 153
154 if (element_animations->IsEmpty()) { 154 if (element_animations->IsEmpty()) {
155 element_animations->ClearAffectedElementTypes(); 155 element_animations->ClearAffectedElementTypes();
156 element_to_animations_map_.erase(element_animations->element_id()); 156 element_to_animations_map_.erase(element_animations->element_id());
157 element_animations->SetAnimationHost(nullptr); 157 element_animations->SetAnimationHost(nullptr);
158 } 158 }
159 159
160 DeactivateAnimationPlayer(player); 160 RemoveFromTicking(player);
161 } 161 }
162 162
163 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { 163 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) {
164 if (mutator_host_client_ == client) 164 if (mutator_host_client_ == client)
165 return; 165 return;
166 166
167 mutator_host_client_ = client; 167 mutator_host_client_ = client;
168 168
169 if (needs_push_properties() && mutator_host_client()) 169 if (needs_push_properties() && mutator_host_client())
170 SetNeedsPushProperties(); 170 SetNeedsPushProperties();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 void AnimationHost::SetSupportsScrollAnimations( 264 void AnimationHost::SetSupportsScrollAnimations(
265 bool supports_scroll_animations) { 265 bool supports_scroll_animations) {
266 supports_scroll_animations_ = supports_scroll_animations; 266 supports_scroll_animations_ = supports_scroll_animations;
267 } 267 }
268 268
269 bool AnimationHost::SupportsScrollAnimations() const { 269 bool AnimationHost::SupportsScrollAnimations() const {
270 return supports_scroll_animations_; 270 return supports_scroll_animations_;
271 } 271 }
272 272
273 bool AnimationHost::NeedsAnimateLayers() const { 273 bool AnimationHost::NeedsTickAnimations() const {
274 return !active_players_.empty(); 274 return !ticking_players_.empty();
275 } 275 }
276 276
277 bool AnimationHost::ActivateAnimations() { 277 bool AnimationHost::ActivateAnimations() {
278 if (!NeedsAnimateLayers()) 278 if (!NeedsTickAnimations())
279 return false; 279 return false;
280 280
281 TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations"); 281 TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations");
282 PlayersList active_active_players_copy = active_players_; 282 PlayersList ticking_players_copy = ticking_players_;
283 for (auto& it : active_active_players_copy) 283 for (auto& it : ticking_players_copy)
284 it->ActivateAnimations(); 284 it->ActivateAnimations();
285 285
286 return true; 286 return true;
287 } 287 }
288 288
289 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) { 289 bool AnimationHost::TickAnimations(base::TimeTicks monotonic_time) {
290 if (!NeedsAnimateLayers()) 290 if (!NeedsTickAnimations())
291 return false; 291 return false;
292 292
293 TRACE_EVENT0("cc", "AnimationHost::AnimateLayers"); 293 TRACE_EVENT0("cc", "AnimationHost::TickAnimations");
294 PlayersList active_active_players_copy = active_players_; 294 PlayersList ticking_players_copy = ticking_players_;
295 for (auto& it : active_active_players_copy) 295 for (auto& it : ticking_players_copy)
296 it->Animate(monotonic_time); 296 it->Tick(monotonic_time);
297 297
298 return true; 298 return true;
299 } 299 }
300 300
301 bool AnimationHost::UpdateAnimationState(bool start_ready_animations, 301 bool AnimationHost::UpdateAnimationState(bool start_ready_animations,
302 MutatorEvents* mutator_events) { 302 MutatorEvents* mutator_events) {
303 if (!NeedsAnimateLayers()) 303 if (!NeedsTickAnimations())
304 return false; 304 return false;
305 305
306 auto animation_events = static_cast<AnimationEvents*>(mutator_events); 306 auto animation_events = static_cast<AnimationEvents*>(mutator_events);
307 307
308 TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState"); 308 TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState");
309 PlayersList active_active_players_copy = active_players_; 309 PlayersList ticking_players_copy = ticking_players_;
310 for (auto& it : active_active_players_copy) 310 for (auto& it : ticking_players_copy)
311 it->UpdateState(start_ready_animations, animation_events); 311 it->UpdateState(start_ready_animations, animation_events);
312 312
313 return true; 313 return true;
314 } 314 }
315 315
316 std::unique_ptr<MutatorEvents> AnimationHost::CreateEvents() { 316 std::unique_ptr<MutatorEvents> AnimationHost::CreateEvents() {
317 return base::MakeUnique<AnimationEvents>(); 317 return base::MakeUnique<AnimationEvents>();
318 } 318 }
319 319
320 void AnimationHost::SetAnimationEvents( 320 void AnimationHost::SetAnimationEvents(
321 std::unique_ptr<MutatorEvents> mutator_events) { 321 std::unique_ptr<MutatorEvents> mutator_events) {
322 auto events = 322 auto events =
323 base::WrapUnique(static_cast<AnimationEvents*>(mutator_events.release())); 323 base::WrapUnique(static_cast<AnimationEvents*>(mutator_events.release()));
324 324
325 for (size_t event_index = 0; event_index < events->events_.size(); 325 for (size_t event_index = 0; event_index < events->events_.size();
326 ++event_index) { 326 ++event_index) {
327 ElementId element_id = events->events_[event_index].element_id; 327 ElementId element_id = events->events_[event_index].element_id;
328 328
329 // Use the map of all ElementAnimations, not just active ones, since 329 // Use the map of all ElementAnimations, not just ticking players, since
330 // non-active ElementAnimations may still receive events for impl-only 330 // non-ticking Players may still receive events for impl-only animations.
331 // animations.
332 const ElementToAnimationsMap& all_element_animations = 331 const ElementToAnimationsMap& all_element_animations =
333 element_to_animations_map_; 332 element_to_animations_map_;
334 auto iter = all_element_animations.find(element_id); 333 auto iter = all_element_animations.find(element_id);
335 if (iter != all_element_animations.end()) { 334 if (iter != all_element_animations.end()) {
336 switch (events->events_[event_index].type) { 335 switch (events->events_[event_index].type) {
337 case AnimationEvent::STARTED: 336 case AnimationEvent::STARTED:
338 (*iter).second->NotifyAnimationStarted(events->events_[event_index]); 337 (*iter).second->NotifyAnimationStarted(events->events_[event_index]);
339 break; 338 break;
340 339
341 case AnimationEvent::FINISHED: 340 case AnimationEvent::FINISHED:
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 return element_animations 512 return element_animations
514 ? element_animations->AnimationStartScale(list_type, start_scale) 513 ? element_animations->AnimationStartScale(list_type, start_scale)
515 : true; 514 : true;
516 } 515 }
517 516
518 bool AnimationHost::HasAnyAnimation(ElementId element_id) const { 517 bool AnimationHost::HasAnyAnimation(ElementId element_id) const {
519 auto element_animations = GetElementAnimationsForElementId(element_id); 518 auto element_animations = GetElementAnimationsForElementId(element_id);
520 return element_animations ? element_animations->HasAnyAnimation() : false; 519 return element_animations ? element_animations->HasAnyAnimation() : false;
521 } 520 }
522 521
523 bool AnimationHost::HasActiveAnimationForTesting(ElementId element_id) const { 522 bool AnimationHost::HasTickingAnimationForTesting(ElementId element_id) const {
524 auto element_animations = GetElementAnimationsForElementId(element_id); 523 auto element_animations = GetElementAnimationsForElementId(element_id);
525 return element_animations ? element_animations->HasActiveAnimation() : false; 524 return element_animations ? element_animations->HasTickingAnimation() : false;
526 } 525 }
527 526
528 void AnimationHost::ImplOnlyScrollAnimationCreate( 527 void AnimationHost::ImplOnlyScrollAnimationCreate(
529 ElementId element_id, 528 ElementId element_id,
530 const gfx::ScrollOffset& target_offset, 529 const gfx::ScrollOffset& target_offset,
531 const gfx::ScrollOffset& current_offset, 530 const gfx::ScrollOffset& current_offset,
532 base::TimeDelta delayed_by) { 531 base::TimeDelta delayed_by) {
533 DCHECK(scroll_offset_animations_impl_); 532 DCHECK(scroll_offset_animations_impl_);
534 scroll_offset_animations_impl_->ScrollAnimationCreate( 533 scroll_offset_animations_impl_->ScrollAnimationCreate(
535 element_id, target_offset, current_offset, delayed_by); 534 element_id, target_offset, current_offset, delayed_by);
(...skipping 14 matching lines...) Expand all
550 ScrollOffsetAnimations& AnimationHost::scroll_offset_animations() const { 549 ScrollOffsetAnimations& AnimationHost::scroll_offset_animations() const {
551 DCHECK(scroll_offset_animations_); 550 DCHECK(scroll_offset_animations_);
552 return *scroll_offset_animations_.get(); 551 return *scroll_offset_animations_.get();
553 } 552 }
554 553
555 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { 554 void AnimationHost::ScrollAnimationAbort(bool needs_completion) {
556 DCHECK(scroll_offset_animations_impl_); 555 DCHECK(scroll_offset_animations_impl_);
557 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); 556 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion);
558 } 557 }
559 558
560 void AnimationHost::ActivateAnimationPlayer( 559 void AnimationHost::AddToTicking(scoped_refptr<AnimationPlayer> player) {
561 scoped_refptr<AnimationPlayer> player) { 560 DCHECK(std::find(ticking_players_.begin(), ticking_players_.end(), player) ==
562 DCHECK(std::find(active_players_.begin(), active_players_.end(), player) == 561 ticking_players_.end());
563 active_players_.end()); 562 ticking_players_.push_back(player);
564 active_players_.push_back(player);
565 } 563 }
566 564
567 void AnimationHost::DeactivateAnimationPlayer( 565 void AnimationHost::RemoveFromTicking(scoped_refptr<AnimationPlayer> player) {
568 scoped_refptr<AnimationPlayer> player) {
569 auto to_erase = 566 auto to_erase =
570 std::find(active_players_.begin(), active_players_.end(), player); 567 std::find(ticking_players_.begin(), ticking_players_.end(), player);
571 if (to_erase != active_players_.end()) 568 if (to_erase != ticking_players_.end())
572 active_players_.erase(to_erase); 569 ticking_players_.erase(to_erase);
573 } 570 }
574 571
575 const AnimationHost::PlayersList& AnimationHost::active_players_for_testing() 572 const AnimationHost::PlayersList& AnimationHost::ticking_players_for_testing()
576 const { 573 const {
577 return active_players_; 574 return ticking_players_;
578 } 575 }
579 576
580 const AnimationHost::ElementToAnimationsMap& 577 const AnimationHost::ElementToAnimationsMap&
581 AnimationHost::all_element_animations_for_testing() const { 578 AnimationHost::element_animations_for_testing() const {
582 return element_to_animations_map_; 579 return element_to_animations_map_;
583 } 580 }
584 581
585 } // namespace cc 582 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_player.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698