Chromium Code Reviews| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 75 |
| 76 return animation.release(); | 76 return animation.release(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 Animation::Animation(ExecutionContext* executionContext, AnimationTimeline& time line, AnimationEffect* content) | 79 Animation::Animation(ExecutionContext* executionContext, AnimationTimeline& time line, AnimationEffect* content) |
| 80 : ActiveDOMObject(executionContext) | 80 : ActiveDOMObject(executionContext) |
| 81 , m_playState(Idle) | 81 , m_playState(Idle) |
| 82 , m_playbackRate(1) | 82 , m_playbackRate(1) |
| 83 , m_startTime(nullValue()) | 83 , m_startTime(nullValue()) |
| 84 , m_holdTime(0) | 84 , m_holdTime(0) |
| 85 , m_startClip(-std::numeric_limits<double>::infinity()) | |
| 86 , m_endClip(std::numeric_limits<double>::infinity()) | |
| 85 , m_sequenceNumber(nextSequenceNumber()) | 87 , m_sequenceNumber(nextSequenceNumber()) |
| 86 , m_content(content) | 88 , m_content(content) |
| 87 , m_timeline(&timeline) | 89 , m_timeline(&timeline) |
| 88 , m_paused(false) | 90 , m_paused(false) |
| 89 , m_held(true) | 91 , m_held(true) |
| 90 , m_isPausedForTesting(false) | 92 , m_isPausedForTesting(false) |
| 91 , m_outdated(false) | 93 , m_outdated(false) |
| 92 , m_finished(true) | 94 , m_finished(true) |
| 93 , m_compositorState(nullptr) | 95 , m_compositorState(nullptr) |
| 94 , m_compositorPending(false) | 96 , m_compositorPending(false) |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 | 433 |
| 432 if (previousCurrentTime != newCurrentTime) { | 434 if (previousCurrentTime != newCurrentTime) { |
| 433 setOutdated(); | 435 setOutdated(); |
| 434 } else if (!hadStartTime && m_timeline) { | 436 } else if (!hadStartTime && m_timeline) { |
| 435 // Even though this animation is not outdated, time to effect change is | 437 // Even though this animation is not outdated, time to effect change is |
| 436 // infinity until start time is set. | 438 // infinity until start time is set. |
| 437 m_timeline->wake(); | 439 m_timeline->wake(); |
| 438 } | 440 } |
| 439 } | 441 } |
| 440 | 442 |
| 443 bool Animation::clipped(double time) | |
| 444 { | |
| 445 ASSERT(!isNull(time)); | |
| 446 return time <= m_startClip || time > m_endClip + sourceEnd(); | |
| 447 } | |
| 448 | |
| 441 void Animation::setSource(AnimationEffect* newSource) | 449 void Animation::setSource(AnimationEffect* newSource) |
| 442 { | 450 { |
| 443 if (m_content == newSource) | 451 if (m_content == newSource) |
| 444 return; | 452 return; |
| 445 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP endingWithSourceChanged); | 453 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP endingWithSourceChanged); |
| 446 | 454 |
| 447 double storedCurrentTime = currentTimeInternal(); | 455 double storedCurrentTime = currentTimeInternal(); |
| 448 if (m_content) | 456 if (m_content) |
| 449 m_content->detach(); | 457 m_content->detach(); |
| 450 m_content = newSource; | 458 m_content = newSource; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 { | 784 { |
| 777 if (!m_timeline) | 785 if (!m_timeline) |
| 778 return false; | 786 return false; |
| 779 | 787 |
| 780 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); | 788 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); |
| 781 | 789 |
| 782 m_outdated = false; | 790 m_outdated = false; |
| 783 bool idle = playStateInternal() == Idle; | 791 bool idle = playStateInternal() == Idle; |
| 784 | 792 |
| 785 if (m_content) { | 793 if (m_content) { |
| 786 double inheritedTime = idle || isNull(m_timeline->currentTimeInternal()) ? nullValue() : currentTimeInternal(); | 794 double inheritedTime = idle || isNull(m_timeline->currentTimeInternal()) |
| 795 ? nullValue() | |
| 796 : currentTimeInternal(); | |
| 797 | |
| 798 // When the animation is limited, is held but we need to use the calcula ted current time. | |
| 799 // When the start time is null, the held time needs to be used, which is in inherited time. | |
| 800 if (!isNull(inheritedTime) && clipped(m_held && (!limited(inheritedTime) || isNull(m_startTime)) ? inheritedTime : calculateCurrentTime())) | |
|
dstockwell
2015/06/04 01:32:06
This might be better:
if (!isNull(inheritedTime))
samli
2015/06/09 01:23:53
Done.
| |
| 801 inheritedTime = nullValue(); | |
| 787 // Special case for end-exclusivity when playing backwards. | 802 // Special case for end-exclusivity when playing backwards. |
| 788 if (inheritedTime == 0 && m_playbackRate < 0) | 803 if (inheritedTime == 0 && m_playbackRate < 0) |
| 789 inheritedTime = -1; | 804 inheritedTime = -1; |
|
dstockwell
2015/06/04 01:32:06
this probably breaks clipping when clipStart is be
samli
2015/06/09 01:23:53
Yay, this isn't a problem.
| |
| 790 m_content->updateInheritedTime(inheritedTime, reason); | 805 m_content->updateInheritedTime(inheritedTime, reason); |
| 791 } | 806 } |
| 792 | 807 |
| 793 if ((idle || limited()) && !m_finished) { | 808 if ((idle || limited()) && !m_finished) { |
| 794 if (reason == TimingUpdateForAnimationFrame && (idle || hasStartTime())) { | 809 if (reason == TimingUpdateForAnimationFrame && (idle || hasStartTime())) { |
| 795 const AtomicString& eventType = EventTypeNames::finish; | 810 const AtomicString& eventType = EventTypeNames::finish; |
| 796 if (executionContext() && hasEventListeners(eventType)) { | 811 if (executionContext() && hasEventListeners(eventType)) { |
| 797 double eventCurrentTime = currentTimeInternal() * 1000; | 812 double eventCurrentTime = currentTimeInternal() * 1000; |
| 798 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, eventCurrentTime, timeline()->currentTime()); | 813 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, eventCurrentTime, timeline()->currentTime()); |
| 799 m_pendingFinishedEvent->setTarget(this); | 814 m_pendingFinishedEvent->setTarget(this); |
| 800 m_pendingFinishedEvent->setCurrentTarget(this); | 815 m_pendingFinishedEvent->setCurrentTarget(this); |
| 801 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini shedEvent); | 816 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini shedEvent); |
| 802 } | 817 } |
| 803 m_finished = true; | 818 m_finished = true; |
| 804 } | 819 } |
| 805 } | 820 } |
| 806 ASSERT(!m_outdated); | 821 ASSERT(!m_outdated); |
| 807 return !m_finished; | 822 return !m_finished || std::isfinite(timeToEffectChange()); |
| 808 } | 823 } |
| 809 | 824 |
| 810 double Animation::timeToEffectChange() | 825 double Animation::timeToEffectChange() |
| 811 { | 826 { |
| 812 ASSERT(!m_outdated); | 827 ASSERT(!m_outdated); |
| 813 if (m_held || !hasStartTime()) | 828 if (!hasStartTime()) |
| 814 return std::numeric_limits<double>::infinity(); | 829 return std::numeric_limits<double>::infinity(); |
| 830 | |
| 831 double currentTime = calculateCurrentTime(); | |
| 832 if (m_held) { | |
| 833 if (limited(currentTime)) { | |
| 834 if (m_playbackRate > 0 && m_endClip + sourceEnd() > currentTime) | |
| 835 return m_endClip + sourceEnd() - currentTime; | |
| 836 if (m_playbackRate < 0 && m_startClip <= currentTime) | |
| 837 return m_startClip - currentTime; | |
| 838 } | |
| 839 return std::numeric_limits<double>::infinity(); | |
| 840 } | |
| 841 | |
| 815 if (!m_content) | 842 if (!m_content) |
| 816 return -currentTimeInternal() / m_playbackRate; | 843 return -currentTimeInternal() / m_playbackRate; |
| 817 double result = m_playbackRate > 0 | 844 double result = m_playbackRate > 0 |
| 818 ? m_content->timeToForwardsEffectChange() / m_playbackRate | 845 ? m_content->timeToForwardsEffectChange() / m_playbackRate |
| 819 : m_content->timeToReverseEffectChange() / -m_playbackRate; | 846 : m_content->timeToReverseEffectChange() / -m_playbackRate; |
| 847 | |
| 820 return !hasActiveAnimationsOnCompositor() && m_content->phase() == Animation Effect::PhaseActive | 848 return !hasActiveAnimationsOnCompositor() && m_content->phase() == Animation Effect::PhaseActive |
| 821 ? 0 | 849 ? 0 |
| 822 : result; | 850 : clipTimeToEffectChange(result); |
| 851 } | |
| 852 | |
| 853 double Animation::clipTimeToEffectChange(double result) | |
|
dstockwell
2015/06/04 01:32:06
const?
samli
2015/06/09 01:23:53
Done.
| |
| 854 { | |
| 855 double currentTime = calculateCurrentTime(); | |
| 856 if (m_playbackRate > 0) { | |
| 857 if (currentTime <= m_startClip) | |
| 858 result = std::min(result, (m_startClip - currentTime) / m_playbackRa te); | |
| 859 else if (currentTime < m_endClip + sourceEnd()) | |
| 860 result = std::min(result, (m_endClip + sourceEnd() - currentTime) / m_playbackRate); | |
|
dstockwell
2015/06/04 01:32:06
This might prevent firing the finish event.
samli
2015/06/09 01:23:53
It shouldn't. This function always returns as smal
| |
| 861 } else { | |
| 862 if (currentTime >= m_endClip + sourceEnd()) | |
| 863 result = std::min(result, (currentTime - m_endClip + sourceEnd()) / -m_playbackRate); | |
| 864 else if (currentTime > m_startClip) | |
| 865 result = std::min(result, (currentTime - m_startClip) / -m_playbackR ate); | |
| 866 } | |
| 867 return result; | |
| 823 } | 868 } |
| 824 | 869 |
| 825 void Animation::cancel() | 870 void Animation::cancel() |
| 826 { | 871 { |
| 827 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand); | 872 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand); |
| 828 | 873 |
| 829 if (playStateInternal() == Idle) | 874 if (playStateInternal() == Idle) |
| 830 return; | 875 return; |
| 831 | 876 |
| 832 m_holdTime = currentTimeInternal(); | 877 m_holdTime = currentTimeInternal(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 visitor->trace(m_content); | 1068 visitor->trace(m_content); |
| 1024 visitor->trace(m_timeline); | 1069 visitor->trace(m_timeline); |
| 1025 visitor->trace(m_pendingFinishedEvent); | 1070 visitor->trace(m_pendingFinishedEvent); |
| 1026 visitor->trace(m_finishedPromise); | 1071 visitor->trace(m_finishedPromise); |
| 1027 visitor->trace(m_readyPromise); | 1072 visitor->trace(m_readyPromise); |
| 1028 EventTargetWithInlineData::trace(visitor); | 1073 EventTargetWithInlineData::trace(visitor); |
| 1029 ActiveDOMObject::trace(visitor); | 1074 ActiveDOMObject::trace(visitor); |
| 1030 } | 1075 } |
| 1031 | 1076 |
| 1032 } // namespace | 1077 } // namespace |
| OLD | NEW |