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

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

Issue 2349643003: CC Animation: Extract PropertyAnimationState as a non-nested struct. (Closed)
Patch Set: Created 4 years, 3 months 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
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/element_animations.h" 5 #include "cc/animation/element_animations.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset); 493 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset);
494 if (notify_pending_elements && has_element_in_pending_list()) 494 if (notify_pending_elements && has_element_in_pending_list())
495 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset); 495 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset);
496 } 496 }
497 497
498 void ElementAnimations::NotifyClientAnimationChanged( 498 void ElementAnimations::NotifyClientAnimationChanged(
499 TargetProperty::Type property, 499 TargetProperty::Type property,
500 ElementListType list_type, 500 ElementListType list_type,
501 bool notify_elements_about_potential_animation, 501 bool notify_elements_about_potential_animation,
502 bool notify_elements_about_running_animation) { 502 bool notify_elements_about_running_animation) {
503 struct PropertyAnimationState* animation_state = nullptr; 503 PropertyAnimationState* animation_state = nullptr;
504 switch (property) { 504 switch (property) {
505 case TargetProperty::OPACITY: 505 case TargetProperty::OPACITY:
506 animation_state = &opacity_animation_state_; 506 animation_state = &opacity_animation_state_;
507 break; 507 break;
508 case TargetProperty::TRANSFORM: 508 case TargetProperty::TRANSFORM:
509 animation_state = &transform_animation_state_; 509 animation_state = &transform_animation_state_;
510 break; 510 break;
511 case TargetProperty::FILTER: 511 case TargetProperty::FILTER:
512 animation_state = &filter_animation_state_; 512 animation_state = &filter_animation_state_;
513 break; 513 break;
(...skipping 26 matching lines...) Expand all
540 bool currently_animating = 540 bool currently_animating =
541 active ? animation_state->currently_running_for_active_elements 541 active ? animation_state->currently_running_for_active_elements
542 : animation_state->currently_running_for_pending_elements; 542 : animation_state->currently_running_for_pending_elements;
543 IsAnimatingChanged(list_type, property, AnimationChangeType::RUNNING, 543 IsAnimatingChanged(list_type, property, AnimationChangeType::RUNNING,
544 currently_animating); 544 currently_animating);
545 } 545 }
546 } 546 }
547 547
548 void ElementAnimations::UpdateClientAnimationStateInternal( 548 void ElementAnimations::UpdateClientAnimationStateInternal(
549 TargetProperty::Type property) { 549 TargetProperty::Type property) {
550 struct PropertyAnimationState* animation_state = nullptr; 550 PropertyAnimationState* animation_state = nullptr;
551 switch (property) { 551 switch (property) {
552 case TargetProperty::OPACITY: 552 case TargetProperty::OPACITY:
553 animation_state = &opacity_animation_state_; 553 animation_state = &opacity_animation_state_;
554 break; 554 break;
555 case TargetProperty::TRANSFORM: 555 case TargetProperty::TRANSFORM:
556 animation_state = &transform_animation_state_; 556 animation_state = &transform_animation_state_;
557 break; 557 break;
558 case TargetProperty::FILTER: 558 case TargetProperty::FILTER:
559 animation_state = &filter_animation_state_; 559 animation_state = &filter_animation_state_;
560 break; 560 break;
561 default: 561 default:
562 NOTREACHED(); 562 NOTREACHED();
563 break; 563 break;
564 } 564 }
565 bool was_currently_running_animation_for_active_elements =
566 animation_state->currently_running_for_active_elements;
567 bool was_currently_running_animation_for_pending_elements =
568 animation_state->currently_running_for_pending_elements;
569 bool was_potentially_animating_for_active_elements =
570 animation_state->potentially_animating_for_active_elements;
571 bool was_potentially_animating_for_pending_elements =
572 animation_state->potentially_animating_for_pending_elements;
573 565
566 PropertyAnimationState previous_state = *animation_state;
574 animation_state->Clear(); 567 animation_state->Clear();
575 DCHECK(was_potentially_animating_for_active_elements || 568 DCHECK(previous_state.IsValid());
576 !was_currently_running_animation_for_active_elements);
577 DCHECK(was_potentially_animating_for_pending_elements ||
578 !was_currently_running_animation_for_pending_elements);
579 569
580 for (auto& player : players_list_) { 570 for (auto& player : players_list_) {
581 for (const auto& animation : player.animations()) { 571 PropertyAnimationState player_state;
582 if (!animation->is_finished() && 572 player.GetPropertyAnimationStateFor(property, &player_state);
583 animation->target_property() == property) { 573 *animation_state |= player_state;
584 animation_state->potentially_animating_for_active_elements |=
585 animation->affects_active_elements();
586 animation_state->potentially_animating_for_pending_elements |=
587 animation->affects_pending_elements();
588 animation_state->currently_running_for_active_elements |=
589 animation->affects_active_elements() &&
590 animation->InEffect(last_tick_time_);
591 animation_state->currently_running_for_pending_elements |=
592 animation->affects_pending_elements() &&
593 animation->InEffect(last_tick_time_);
594 }
595 }
596 } 574 }
597 575
598 bool potentially_animating_changed_for_active_elements = 576 if (*animation_state == previous_state)
599 was_potentially_animating_for_active_elements !=
600 animation_state->potentially_animating_for_active_elements;
601 bool potentially_animating_changed_for_pending_elements =
602 was_potentially_animating_for_pending_elements !=
603 animation_state->potentially_animating_for_pending_elements;
604 bool currently_running_animation_changed_for_active_elements =
605 was_currently_running_animation_for_active_elements !=
606 animation_state->currently_running_for_active_elements;
607 bool currently_running_animation_changed_for_pending_elements =
608 was_currently_running_animation_for_pending_elements !=
609 animation_state->currently_running_for_pending_elements;
610 if (!potentially_animating_changed_for_active_elements &&
611 !potentially_animating_changed_for_pending_elements &&
612 !currently_running_animation_changed_for_active_elements &&
613 !currently_running_animation_changed_for_pending_elements)
614 return; 577 return;
578
579 PropertyAnimationState diff_state = previous_state ^ *animation_state;
580
615 if (has_element_in_active_list()) 581 if (has_element_in_active_list())
616 NotifyClientAnimationChanged( 582 NotifyClientAnimationChanged(
617 property, ElementListType::ACTIVE, 583 property, ElementListType::ACTIVE,
618 potentially_animating_changed_for_active_elements, 584 diff_state.potentially_animating_for_active_elements,
619 currently_running_animation_changed_for_active_elements); 585 diff_state.currently_running_for_active_elements);
620 if (has_element_in_pending_list()) 586 if (has_element_in_pending_list())
621 NotifyClientAnimationChanged( 587 NotifyClientAnimationChanged(
622 property, ElementListType::PENDING, 588 property, ElementListType::PENDING,
623 potentially_animating_changed_for_pending_elements, 589 diff_state.potentially_animating_for_pending_elements,
624 currently_running_animation_changed_for_pending_elements); 590 diff_state.currently_running_for_pending_elements);
625 } 591 }
626 592
627 bool ElementAnimations::HasActiveAnimation() const { 593 bool ElementAnimations::HasActiveAnimation() const {
628 for (auto& player : players_list_) { 594 for (auto& player : players_list_) {
629 if (player.HasActiveAnimation()) 595 if (player.HasActiveAnimation())
630 return true; 596 return true;
631 } 597 }
632 598
633 return false; 599 return false;
634 } 600 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 if (animation_host()) { 757 if (animation_host()) {
792 DCHECK(animation_host()->mutator_host_client()); 758 DCHECK(animation_host()->mutator_host_client());
793 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( 759 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation(
794 element_id()); 760 element_id());
795 } 761 }
796 762
797 return gfx::ScrollOffset(); 763 return gfx::ScrollOffset();
798 } 764 }
799 765
800 } // namespace cc 766 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698