| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/animation/Animation.h" | 31 #include "core/animation/Animation.h" |
| 32 | 32 |
| 33 #include "core/animation/AnimationTimeline.h" | 33 #include "core/animation/AnimationTimeline.h" |
| 34 #include "core/animation/CompositorPendingAnimations.h" | 34 #include "core/animation/CompositorPendingAnimations.h" |
| 35 #include "core/animation/KeyframeEffect.h" | 35 #include "core/animation/KeyframeEffectReadOnly.h" |
| 36 #include "core/animation/css/CSSAnimations.h" | 36 #include "core/animation/css/CSSAnimations.h" |
| 37 #include "core/dom/Document.h" | 37 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExceptionCode.h" | 38 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/dom/StyleChangeReason.h" | 39 #include "core/dom/StyleChangeReason.h" |
| 40 #include "core/events/AnimationPlaybackEvent.h" | 40 #include "core/events/AnimationPlaybackEvent.h" |
| 41 #include "core/frame/UseCounter.h" | 41 #include "core/frame/UseCounter.h" |
| 42 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
| 43 #include "core/inspector/InspectorTraceEvents.h" | 43 #include "core/inspector/InspectorTraceEvents.h" |
| 44 #include "platform/RuntimeEnabledFeatures.h" | 44 #include "platform/RuntimeEnabledFeatures.h" |
| 45 #include "platform/animation/CompositorAnimationPlayer.h" | 45 #include "platform/animation/CompositorAnimationPlayer.h" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 381 |
| 382 // FIXME: This avoids marking this animation as outdated needlessly when a | 382 // FIXME: This avoids marking this animation as outdated needlessly when a |
| 383 // start time is notified, but we should refactor how outdating works to | 383 // start time is notified, but we should refactor how outdating works to |
| 384 // avoid this. | 384 // avoid this. |
| 385 clearOutdated(); | 385 clearOutdated(); |
| 386 m_currentTimePending = false; | 386 m_currentTimePending = false; |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool Animation::affects(const Element& element, CSSPropertyID property) const { | 390 bool Animation::affects(const Element& element, CSSPropertyID property) const { |
| 391 if (!m_content || !m_content->isKeyframeEffect()) | 391 if (!m_content || !m_content->isKeyframeEffectReadOnly()) |
| 392 return false; | 392 return false; |
| 393 | 393 |
| 394 const KeyframeEffect* effect = toKeyframeEffect(m_content.get()); | 394 const KeyframeEffectReadOnly* effect = |
| 395 toKeyframeEffectReadOnly(m_content.get()); |
| 395 return (effect->target() == &element) && | 396 return (effect->target() == &element) && |
| 396 effect->affects(PropertyHandle(property)); | 397 effect->affects(PropertyHandle(property)); |
| 397 } | 398 } |
| 398 | 399 |
| 399 double Animation::calculateStartTime(double currentTime) const { | 400 double Animation::calculateStartTime(double currentTime) const { |
| 400 return m_timeline->effectiveTime() - currentTime / m_playbackRate; | 401 return m_timeline->effectiveTime() - currentTime / m_playbackRate; |
| 401 } | 402 } |
| 402 | 403 |
| 403 double Animation::calculateCurrentTime() const { | 404 double Animation::calculateCurrentTime() const { |
| 404 if (isNull(m_startTime) || !m_timeline) | 405 if (isNull(m_startTime) || !m_timeline) |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 715 |
| 715 bool Animation::canStartAnimationOnCompositor() const { | 716 bool Animation::canStartAnimationOnCompositor() const { |
| 716 if (m_isCompositedAnimationDisabledForTesting || effectSuppressed()) | 717 if (m_isCompositedAnimationDisabledForTesting || effectSuppressed()) |
| 717 return false; | 718 return false; |
| 718 | 719 |
| 719 // FIXME: Timeline playback rates should be compositable | 720 // FIXME: Timeline playback rates should be compositable |
| 720 if (m_playbackRate == 0 || (std::isinf(effectEnd()) && m_playbackRate < 0) || | 721 if (m_playbackRate == 0 || (std::isinf(effectEnd()) && m_playbackRate < 0) || |
| 721 (timeline() && timeline()->playbackRate() != 1)) | 722 (timeline() && timeline()->playbackRate() != 1)) |
| 722 return false; | 723 return false; |
| 723 | 724 |
| 724 return m_timeline && m_content && m_content->isKeyframeEffect() && playing(); | 725 return m_timeline && m_content && m_content->isKeyframeEffectReadOnly() && |
| 726 playing(); |
| 725 } | 727 } |
| 726 | 728 |
| 727 bool Animation::isCandidateForAnimationOnCompositor() const { | 729 bool Animation::isCandidateForAnimationOnCompositor() const { |
| 728 if (!canStartAnimationOnCompositor()) | 730 if (!canStartAnimationOnCompositor()) |
| 729 return false; | 731 return false; |
| 730 | 732 |
| 731 return toKeyframeEffect(m_content.get()) | 733 return toKeyframeEffectReadOnly(m_content.get()) |
| 732 ->isCandidateForAnimationOnCompositor(m_playbackRate); | 734 ->isCandidateForAnimationOnCompositor(m_playbackRate); |
| 733 } | 735 } |
| 734 | 736 |
| 735 bool Animation::maybeStartAnimationOnCompositor() { | 737 bool Animation::maybeStartAnimationOnCompositor() { |
| 736 if (!canStartAnimationOnCompositor()) | 738 if (!canStartAnimationOnCompositor()) |
| 737 return false; | 739 return false; |
| 738 | 740 |
| 739 bool reversed = m_playbackRate < 0; | 741 bool reversed = m_playbackRate < 0; |
| 740 | 742 |
| 741 double startTime = timeline()->zeroTime() + startTimeInternal(); | 743 double startTime = timeline()->zeroTime() + startTimeInternal(); |
| 742 if (reversed) { | 744 if (reversed) { |
| 743 startTime -= effectEnd() / fabs(m_playbackRate); | 745 startTime -= effectEnd() / fabs(m_playbackRate); |
| 744 } | 746 } |
| 745 | 747 |
| 746 double timeOffset = 0; | 748 double timeOffset = 0; |
| 747 if (std::isnan(startTime)) { | 749 if (std::isnan(startTime)) { |
| 748 timeOffset = | 750 timeOffset = |
| 749 reversed ? effectEnd() - currentTimeInternal() : currentTimeInternal(); | 751 reversed ? effectEnd() - currentTimeInternal() : currentTimeInternal(); |
| 750 timeOffset = timeOffset / fabs(m_playbackRate); | 752 timeOffset = timeOffset / fabs(m_playbackRate); |
| 751 } | 753 } |
| 752 DCHECK_NE(m_compositorGroup, 0); | 754 DCHECK_NE(m_compositorGroup, 0); |
| 753 return toKeyframeEffect(m_content.get()) | 755 return toKeyframeEffectReadOnly(m_content.get()) |
| 754 ->maybeStartAnimationOnCompositor(m_compositorGroup, startTime, | 756 ->maybeStartAnimationOnCompositor(m_compositorGroup, startTime, |
| 755 timeOffset, m_playbackRate); | 757 timeOffset, m_playbackRate); |
| 756 } | 758 } |
| 757 | 759 |
| 758 void Animation::setCompositorPending(bool effectChanged) { | 760 void Animation::setCompositorPending(bool effectChanged) { |
| 759 // FIXME: KeyframeEffect could notify this directly? | 761 // FIXME: KeyframeEffect could notify this directly? |
| 760 if (!hasActiveAnimationsOnCompositor()) { | 762 if (!hasActiveAnimationsOnCompositor()) { |
| 761 destroyCompositorPlayer(); | 763 destroyCompositorPlayer(); |
| 762 m_compositorState.reset(); | 764 m_compositorState.reset(); |
| 763 } | 765 } |
| 764 if (effectChanged && m_compositorState) { | 766 if (effectChanged && m_compositorState) { |
| 765 m_compositorState->effectChanged = true; | 767 m_compositorState->effectChanged = true; |
| 766 } | 768 } |
| 767 if (m_compositorPending || m_isPausedForTesting) { | 769 if (m_compositorPending || m_isPausedForTesting) { |
| 768 return; | 770 return; |
| 769 } | 771 } |
| 770 if (!m_compositorState || m_compositorState->effectChanged || | 772 if (!m_compositorState || m_compositorState->effectChanged || |
| 771 m_compositorState->playbackRate != m_playbackRate || | 773 m_compositorState->playbackRate != m_playbackRate || |
| 772 m_compositorState->startTime != m_startTime) { | 774 m_compositorState->startTime != m_startTime) { |
| 773 m_compositorPending = true; | 775 m_compositorPending = true; |
| 774 timeline()->document()->compositorPendingAnimations().add(this); | 776 timeline()->document()->compositorPendingAnimations().add(this); |
| 775 } | 777 } |
| 776 } | 778 } |
| 777 | 779 |
| 778 void Animation::cancelAnimationOnCompositor() { | 780 void Animation::cancelAnimationOnCompositor() { |
| 779 if (hasActiveAnimationsOnCompositor()) | 781 if (hasActiveAnimationsOnCompositor()) |
| 780 toKeyframeEffect(m_content.get())->cancelAnimationOnCompositor(); | 782 toKeyframeEffectReadOnly(m_content.get())->cancelAnimationOnCompositor(); |
| 781 | 783 |
| 782 destroyCompositorPlayer(); | 784 destroyCompositorPlayer(); |
| 783 } | 785 } |
| 784 | 786 |
| 785 void Animation::restartAnimationOnCompositor() { | 787 void Animation::restartAnimationOnCompositor() { |
| 786 if (hasActiveAnimationsOnCompositor()) | 788 if (hasActiveAnimationsOnCompositor()) |
| 787 toKeyframeEffect(m_content.get())->restartAnimationOnCompositor(); | 789 toKeyframeEffectReadOnly(m_content.get())->restartAnimationOnCompositor(); |
| 788 } | 790 } |
| 789 | 791 |
| 790 void Animation::cancelIncompatibleAnimationsOnCompositor() { | 792 void Animation::cancelIncompatibleAnimationsOnCompositor() { |
| 791 if (m_content && m_content->isKeyframeEffect()) | 793 if (m_content && m_content->isKeyframeEffectReadOnly()) |
| 792 toKeyframeEffect(m_content.get()) | 794 toKeyframeEffectReadOnly(m_content.get()) |
| 793 ->cancelIncompatibleAnimationsOnCompositor(); | 795 ->cancelIncompatibleAnimationsOnCompositor(); |
| 794 } | 796 } |
| 795 | 797 |
| 796 bool Animation::hasActiveAnimationsOnCompositor() { | 798 bool Animation::hasActiveAnimationsOnCompositor() { |
| 797 if (!m_content || !m_content->isKeyframeEffect()) | 799 if (!m_content || !m_content->isKeyframeEffectReadOnly()) |
| 798 return false; | 800 return false; |
| 799 | 801 |
| 800 return toKeyframeEffect(m_content.get())->hasActiveAnimationsOnCompositor(); | 802 return toKeyframeEffectReadOnly(m_content.get()) |
| 803 ->hasActiveAnimationsOnCompositor(); |
| 801 } | 804 } |
| 802 | 805 |
| 803 bool Animation::update(TimingUpdateReason reason) { | 806 bool Animation::update(TimingUpdateReason reason) { |
| 804 if (!m_timeline) | 807 if (!m_timeline) |
| 805 return false; | 808 return false; |
| 806 | 809 |
| 807 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); | 810 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); |
| 808 | 811 |
| 809 clearOutdated(); | 812 clearOutdated(); |
| 810 bool idle = playStateInternal() == Idle; | 813 bool idle = playStateInternal() == Idle; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 if (timeline) | 943 if (timeline) |
| 941 timeline->playerDestroyed(*this); | 944 timeline->playerDestroyed(*this); |
| 942 } | 945 } |
| 943 } | 946 } |
| 944 | 947 |
| 945 void Animation::attachCompositedLayers() { | 948 void Animation::attachCompositedLayers() { |
| 946 if (!m_compositorPlayer) | 949 if (!m_compositorPlayer) |
| 947 return; | 950 return; |
| 948 | 951 |
| 949 DCHECK(m_content); | 952 DCHECK(m_content); |
| 950 DCHECK(m_content->isKeyframeEffect()); | 953 DCHECK(m_content->isKeyframeEffectReadOnly()); |
| 951 | 954 |
| 952 toKeyframeEffect(m_content.get())->attachCompositedLayers(); | 955 toKeyframeEffectReadOnly(m_content.get())->attachCompositedLayers(); |
| 953 } | 956 } |
| 954 | 957 |
| 955 void Animation::detachCompositedLayers() { | 958 void Animation::detachCompositedLayers() { |
| 956 if (m_compositorPlayer && m_compositorPlayer->isElementAttached()) | 959 if (m_compositorPlayer && m_compositorPlayer->isElementAttached()) |
| 957 m_compositorPlayer->detachElement(); | 960 m_compositorPlayer->detachElement(); |
| 958 } | 961 } |
| 959 | 962 |
| 960 void Animation::notifyAnimationStarted(double monotonicTime, int group) { | 963 void Animation::notifyAnimationStarted(double monotonicTime, int group) { |
| 961 timeline() | 964 timeline() |
| 962 ->document() | 965 ->document() |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 RegisteredEventListener& registeredListener) { | 1073 RegisteredEventListener& registeredListener) { |
| 1071 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); | 1074 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); |
| 1072 if (eventType == EventTypeNames::finish) | 1075 if (eventType == EventTypeNames::finish) |
| 1073 UseCounter::count(getExecutionContext(), UseCounter::AnimationFinishEvent); | 1076 UseCounter::count(getExecutionContext(), UseCounter::AnimationFinishEvent); |
| 1074 } | 1077 } |
| 1075 | 1078 |
| 1076 void Animation::pauseForTesting(double pauseTime) { | 1079 void Animation::pauseForTesting(double pauseTime) { |
| 1077 RELEASE_ASSERT(!paused()); | 1080 RELEASE_ASSERT(!paused()); |
| 1078 setCurrentTimeInternal(pauseTime, TimingUpdateOnDemand); | 1081 setCurrentTimeInternal(pauseTime, TimingUpdateOnDemand); |
| 1079 if (hasActiveAnimationsOnCompositor()) | 1082 if (hasActiveAnimationsOnCompositor()) |
| 1080 toKeyframeEffect(m_content.get()) | 1083 toKeyframeEffectReadOnly(m_content.get()) |
| 1081 ->pauseAnimationForTestingOnCompositor(currentTimeInternal()); | 1084 ->pauseAnimationForTestingOnCompositor(currentTimeInternal()); |
| 1082 m_isPausedForTesting = true; | 1085 m_isPausedForTesting = true; |
| 1083 pause(); | 1086 pause(); |
| 1084 } | 1087 } |
| 1085 | 1088 |
| 1086 void Animation::setEffectSuppressed(bool suppressed) { | 1089 void Animation::setEffectSuppressed(bool suppressed) { |
| 1087 m_effectSuppressed = suppressed; | 1090 m_effectSuppressed = suppressed; |
| 1088 if (suppressed) | 1091 if (suppressed) |
| 1089 cancelAnimationOnCompositor(); | 1092 cancelAnimationOnCompositor(); |
| 1090 } | 1093 } |
| 1091 | 1094 |
| 1092 void Animation::disableCompositedAnimationForTesting() { | 1095 void Animation::disableCompositedAnimationForTesting() { |
| 1093 m_isCompositedAnimationDisabledForTesting = true; | 1096 m_isCompositedAnimationDisabledForTesting = true; |
| 1094 cancelAnimationOnCompositor(); | 1097 cancelAnimationOnCompositor(); |
| 1095 } | 1098 } |
| 1096 | 1099 |
| 1097 void Animation::invalidateKeyframeEffect(const TreeScope& treeScope) { | 1100 void Animation::invalidateKeyframeEffect(const TreeScope& treeScope) { |
| 1098 if (!m_content || !m_content->isKeyframeEffect()) | 1101 if (!m_content || !m_content->isKeyframeEffectReadOnly()) |
| 1099 return; | 1102 return; |
| 1100 | 1103 |
| 1101 Element& target = *toKeyframeEffect(m_content.get())->target(); | 1104 Element& target = *toKeyframeEffectReadOnly(m_content.get())->target(); |
| 1102 | 1105 |
| 1103 if (CSSAnimations::isAffectedByKeyframesFromScope(target, treeScope)) | 1106 if (CSSAnimations::isAffectedByKeyframesFromScope(target, treeScope)) |
| 1104 target.setNeedsStyleRecalc(LocalStyleChange, | 1107 target.setNeedsStyleRecalc(LocalStyleChange, |
| 1105 StyleChangeReasonForTracing::create( | 1108 StyleChangeReasonForTracing::create( |
| 1106 StyleChangeReason::StyleSheetChange)); | 1109 StyleChangeReason::StyleSheetChange)); |
| 1107 } | 1110 } |
| 1108 | 1111 |
| 1109 DEFINE_TRACE(Animation) { | 1112 DEFINE_TRACE(Animation) { |
| 1110 visitor->trace(m_content); | 1113 visitor->trace(m_content); |
| 1111 visitor->trace(m_timeline); | 1114 visitor->trace(m_timeline); |
| 1112 visitor->trace(m_pendingFinishedEvent); | 1115 visitor->trace(m_pendingFinishedEvent); |
| 1113 visitor->trace(m_pendingCancelledEvent); | 1116 visitor->trace(m_pendingCancelledEvent); |
| 1114 visitor->trace(m_finishedPromise); | 1117 visitor->trace(m_finishedPromise); |
| 1115 visitor->trace(m_readyPromise); | 1118 visitor->trace(m_readyPromise); |
| 1116 EventTargetWithInlineData::trace(visitor); | 1119 EventTargetWithInlineData::trace(visitor); |
| 1117 ActiveDOMObject::trace(visitor); | 1120 ActiveDOMObject::trace(visitor); |
| 1118 } | 1121 } |
| 1119 | 1122 |
| 1120 } // namespace blink | 1123 } // namespace blink |
| OLD | NEW |