| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layer_animation_controller.h" | 5 #include "cc/animation/layer_animation_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "cc/animation/animation.h" | 9 #include "cc/animation/animation.h" |
| 10 #include "cc/animation/animation_delegate.h" | 10 #include "cc/animation/animation_delegate.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 ScopedPtrVector<Animation>& animations = active_animations_; | 85 ScopedPtrVector<Animation>& animations = active_animations_; |
| 86 animations.erase(cc::remove_if(&animations, | 86 animations.erase(cc::remove_if(&animations, |
| 87 animations.begin(), | 87 animations.begin(), |
| 88 animations.end(), | 88 animations.end(), |
| 89 HasAnimationIdAndProperty(animation_id, | 89 HasAnimationIdAndProperty(animation_id, |
| 90 target_property)), | 90 target_property)), |
| 91 animations.end()); | 91 animations.end()); |
| 92 UpdateActivation(NormalActivation); | 92 UpdateActivation(NormalActivation); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void LayerAnimationController::AbortAnimations( |
| 96 Animation::TargetProperty target_property) { |
| 97 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 98 if (active_animations_[i]->target_property() == target_property && |
| 99 !active_animations_[i]->is_finished()) |
| 100 active_animations_[i]->SetRunState(Animation::Aborted, last_tick_time_); |
| 101 } |
| 102 } |
| 103 |
| 95 // Ensures that the list of active animations on the main thread and the impl | 104 // Ensures that the list of active animations on the main thread and the impl |
| 96 // thread are kept in sync. | 105 // thread are kept in sync. |
| 97 void LayerAnimationController::PushAnimationUpdatesTo( | 106 void LayerAnimationController::PushAnimationUpdatesTo( |
| 98 LayerAnimationController* controller_impl) { | 107 LayerAnimationController* controller_impl) { |
| 99 DCHECK(this != controller_impl); | 108 DCHECK(this != controller_impl); |
| 100 if (force_sync_) { | 109 if (force_sync_) { |
| 101 ReplaceImplThreadAnimations(controller_impl); | 110 ReplaceImplThreadAnimations(controller_impl); |
| 102 force_sync_ = false; | 111 force_sync_ = false; |
| 103 } else { | 112 } else { |
| 104 PurgeAnimationsMarkedForDeletion(); | 113 PurgeAnimationsMarkedForDeletion(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 active_animations_[i]->target_property() == event.target_property) { | 318 active_animations_[i]->target_property() == event.target_property) { |
| 310 active_animations_[i]->set_received_finished_event(true); | 319 active_animations_[i]->set_received_finished_event(true); |
| 311 if (layer_animation_delegate_) | 320 if (layer_animation_delegate_) |
| 312 layer_animation_delegate_->NotifyAnimationFinished(wall_clock_time); | 321 layer_animation_delegate_->NotifyAnimationFinished(wall_clock_time); |
| 313 | 322 |
| 314 return; | 323 return; |
| 315 } | 324 } |
| 316 } | 325 } |
| 317 } | 326 } |
| 318 | 327 |
| 328 void LayerAnimationController::NotifyAnimationAborted( |
| 329 const AnimationEvent& event) { |
| 330 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 331 if (active_animations_[i]->group() == event.group_id && |
| 332 active_animations_[i]->target_property() == event.target_property) { |
| 333 active_animations_[i]->SetRunState(Animation::Aborted, |
| 334 event.monotonic_time); |
| 335 } |
| 336 } |
| 337 } |
| 338 |
| 319 void LayerAnimationController::NotifyAnimationPropertyUpdate( | 339 void LayerAnimationController::NotifyAnimationPropertyUpdate( |
| 320 const AnimationEvent& event) { | 340 const AnimationEvent& event) { |
| 321 switch (event.target_property) { | 341 switch (event.target_property) { |
| 322 case Animation::Opacity: | 342 case Animation::Opacity: |
| 323 NotifyObserversOpacityAnimated(event.opacity); | 343 NotifyObserversOpacityAnimated(event.opacity); |
| 324 break; | 344 break; |
| 325 case Animation::Transform: | 345 case Animation::Transform: |
| 326 NotifyObserversTransformAnimated(event.transform); | 346 NotifyObserversTransformAnimated(event.transform); |
| 327 break; | 347 break; |
| 328 default: | 348 default: |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 started_event.is_impl_only = active_animations_[i]->is_impl_only(); | 558 started_event.is_impl_only = active_animations_[i]->is_impl_only(); |
| 539 events->push_back(started_event); | 559 events->push_back(started_event); |
| 540 } | 560 } |
| 541 } | 561 } |
| 542 } | 562 } |
| 543 } | 563 } |
| 544 | 564 |
| 545 void LayerAnimationController::MarkFinishedAnimations(double monotonic_time) { | 565 void LayerAnimationController::MarkFinishedAnimations(double monotonic_time) { |
| 546 for (size_t i = 0; i < active_animations_.size(); ++i) { | 566 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 547 if (active_animations_[i]->IsFinishedAt(monotonic_time) && | 567 if (active_animations_[i]->IsFinishedAt(monotonic_time) && |
| 568 active_animations_[i]->run_state() != Animation::Aborted && |
| 548 active_animations_[i]->run_state() != Animation::WaitingForDeletion) | 569 active_animations_[i]->run_state() != Animation::WaitingForDeletion) |
| 549 active_animations_[i]->SetRunState(Animation::Finished, monotonic_time); | 570 active_animations_[i]->SetRunState(Animation::Finished, monotonic_time); |
| 550 } | 571 } |
| 551 } | 572 } |
| 552 | 573 |
| 553 void LayerAnimationController::ResolveConflicts(double monotonic_time) { | 574 void LayerAnimationController::ResolveConflicts(double monotonic_time) { |
| 554 // Find any animations that are animating the same property and resolve the | 575 // Find any animations that are animating the same property and resolve the |
| 555 // confict. We could eventually blend, but for now we'll just abort the | 576 // confict. We could eventually blend, but for now we'll just abort the |
| 556 // previous animation (where 'previous' means: (1) has a prior start time or | 577 // previous animation (where 'previous' means: (1) has a prior start time or |
| 557 // (2) has an equal start time, but was added to the queue earlier, i.e., | 578 // (2) has an equal start time, but was added to the queue earlier, i.e., |
| (...skipping 21 matching lines...) Expand all Loading... |
| 579 } | 600 } |
| 580 | 601 |
| 581 void LayerAnimationController::MarkAnimationsForDeletion( | 602 void LayerAnimationController::MarkAnimationsForDeletion( |
| 582 double monotonic_time, AnimationEventsVector* events) { | 603 double monotonic_time, AnimationEventsVector* events) { |
| 583 // Non-aborted animations are marked for deletion after a corresponding | 604 // Non-aborted animations are marked for deletion after a corresponding |
| 584 // AnimationEvent::Finished event is sent or received. This means that if | 605 // AnimationEvent::Finished event is sent or received. This means that if |
| 585 // we don't have an events vector, we must ensure that non-aborted animations | 606 // we don't have an events vector, we must ensure that non-aborted animations |
| 586 // have received a finished event before marking them for deletion. | 607 // have received a finished event before marking them for deletion. |
| 587 for (size_t i = 0; i < active_animations_.size(); i++) { | 608 for (size_t i = 0; i < active_animations_.size(); i++) { |
| 588 int group_id = active_animations_[i]->group(); | 609 int group_id = active_animations_[i]->group(); |
| 610 if (active_animations_[i]->run_state() == Animation::Aborted) { |
| 611 if (events && !active_animations_[i]->is_impl_only()) { |
| 612 AnimationEvent aborted_event( |
| 613 AnimationEvent::Aborted, |
| 614 id_, |
| 615 group_id, |
| 616 active_animations_[i]->target_property(), |
| 617 monotonic_time); |
| 618 events->push_back(aborted_event); |
| 619 } |
| 620 active_animations_[i]->SetRunState(Animation::WaitingForDeletion, |
| 621 monotonic_time); |
| 622 continue; |
| 623 } |
| 624 |
| 589 bool all_anims_with_same_id_are_finished = false; | 625 bool all_anims_with_same_id_are_finished = false; |
| 590 | 626 |
| 591 // Since deleting an animation on the main thread leads to its deletion | 627 // Since deleting an animation on the main thread leads to its deletion |
| 592 // on the impl thread, we only mark a Finished main thread animation for | 628 // on the impl thread, we only mark a Finished main thread animation for |
| 593 // deletion once it has received a Finished event from the impl thread. | 629 // deletion once it has received a Finished event from the impl thread. |
| 594 bool animation_i_will_send_or_has_received_finish_event = | 630 bool animation_i_will_send_or_has_received_finish_event = |
| 595 events || active_animations_[i]->received_finished_event(); | 631 events || active_animations_[i]->received_finished_event(); |
| 596 // If an animation is finished, and not already marked for deletion, | 632 // If an animation is finished, and not already marked for deletion, |
| 597 // find out if all other animations in the same group are also finished. | 633 // find out if all other animations in the same group are also finished. |
| 598 if (active_animations_[i]->run_state() == Animation::Aborted || | 634 if (active_animations_[i]->run_state() == Animation::Finished && |
| 599 (active_animations_[i]->run_state() == Animation::Finished && | 635 animation_i_will_send_or_has_received_finish_event) { |
| 600 animation_i_will_send_or_has_received_finish_event)) { | |
| 601 all_anims_with_same_id_are_finished = true; | 636 all_anims_with_same_id_are_finished = true; |
| 602 for (size_t j = 0; j < active_animations_.size(); ++j) { | 637 for (size_t j = 0; j < active_animations_.size(); ++j) { |
| 603 bool animation_j_will_send_or_has_received_finish_event = | 638 bool animation_j_will_send_or_has_received_finish_event = |
| 604 events || active_animations_[j]->received_finished_event(); | 639 events || active_animations_[j]->received_finished_event(); |
| 605 if (group_id == active_animations_[j]->group() && | 640 if (group_id == active_animations_[j]->group() && |
| 606 (!active_animations_[j]->is_finished() || | 641 (!active_animations_[j]->is_finished() || |
| 607 (active_animations_[j]->run_state() == Animation::Finished && | 642 (active_animations_[j]->run_state() == Animation::Finished && |
| 608 !animation_j_will_send_or_has_received_finish_event))) { | 643 !animation_j_will_send_or_has_received_finish_event))) { |
| 609 all_anims_with_same_id_are_finished = false; | 644 all_anims_with_same_id_are_finished = false; |
| 610 break; | 645 break; |
| 611 } | 646 } |
| 612 } | 647 } |
| 613 } | 648 } |
| 614 if (all_anims_with_same_id_are_finished) { | 649 if (all_anims_with_same_id_are_finished) { |
| 615 // We now need to remove all animations with the same group id as | 650 // We now need to remove all animations with the same group id as |
| 616 // group_id (and send along animation finished notifications, if | 651 // group_id (and send along animation finished notifications, if |
| 617 // necessary). | 652 // necessary). |
| 618 for (size_t j = i; j < active_animations_.size(); j++) { | 653 for (size_t j = i; j < active_animations_.size(); j++) { |
| 619 if (group_id == active_animations_[j]->group()) { | 654 if (active_animations_[j]->group() == group_id && |
| 655 active_animations_[j]->run_state() != Animation::Aborted) { |
| 620 if (events) { | 656 if (events) { |
| 621 AnimationEvent finished_event( | 657 AnimationEvent finished_event( |
| 622 AnimationEvent::Finished, | 658 AnimationEvent::Finished, |
| 623 id_, | 659 id_, |
| 624 active_animations_[j]->group(), | 660 active_animations_[j]->group(), |
| 625 active_animations_[j]->target_property(), | 661 active_animations_[j]->target_property(), |
| 626 monotonic_time); | 662 monotonic_time); |
| 627 finished_event.is_impl_only = active_animations_[j]->is_impl_only(); | 663 finished_event.is_impl_only = active_animations_[j]->is_impl_only(); |
| 628 events->push_back(finished_event); | 664 events->push_back(finished_event); |
| 629 } | 665 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 value_observers_); | 799 value_observers_); |
| 764 LayerAnimationValueObserver* obs; | 800 LayerAnimationValueObserver* obs; |
| 765 while ((obs = it.GetNext()) != NULL) | 801 while ((obs = it.GetNext()) != NULL) |
| 766 if (obs->IsActive()) | 802 if (obs->IsActive()) |
| 767 return true; | 803 return true; |
| 768 } | 804 } |
| 769 return false; | 805 return false; |
| 770 } | 806 } |
| 771 | 807 |
| 772 } // namespace cc | 808 } // namespace cc |
| OLD | NEW |