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 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 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "core/animation/Player.h" | 33 #include "core/animation/Player.h" |
| 34 | 34 |
| 35 #include "core/animation/Animation.h" | |
| 35 #include "core/animation/DocumentTimeline.h" | 36 #include "core/animation/DocumentTimeline.h" |
| 36 #include "core/animation/TimedItem.h" | 37 #include "core/animation/TimedItem.h" |
| 37 | 38 |
| 38 namespace WebCore { | 39 namespace WebCore { |
| 39 | 40 |
| 40 namespace { | |
| 41 | |
| 42 double effectiveTime(double time) { return isNull(time) ? 0 : time; } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 PassRefPtr<Player> Player::create(DocumentTimeline& timeline, TimedItem* content ) | 41 PassRefPtr<Player> Player::create(DocumentTimeline& timeline, TimedItem* content ) |
| 47 { | 42 { |
| 48 return adoptRef(new Player(timeline, content)); | 43 return adoptRef(new Player(timeline, content)); |
| 49 } | 44 } |
| 50 | 45 |
| 51 Player::Player(DocumentTimeline& timeline, TimedItem* content) | 46 Player::Player(DocumentTimeline& timeline, TimedItem* content) |
| 52 : m_pauseStartTime(nullValue()) | 47 : m_pauseStartTime(nullValue()) |
| 53 , m_playbackRate(1) | 48 , m_playbackRate(1) |
| 54 , m_timeDrift(0) | 49 , m_timeDrift(0) |
| 55 , m_startTime(nullValue()) | 50 , m_startTime(nullValue()) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 75 update(); | 70 update(); |
| 76 } | 71 } |
| 77 | 72 |
| 78 double Player::currentTimeBeforeDrift() const | 73 double Player::currentTimeBeforeDrift() const |
| 79 { | 74 { |
| 80 if (isNull(m_startTime)) | 75 if (isNull(m_startTime)) |
| 81 return 0; | 76 return 0; |
| 82 return (effectiveTime(m_timeline.currentTime()) - startTime()) * m_playbackR ate; | 77 return (effectiveTime(m_timeline.currentTime()) - startTime()) * m_playbackR ate; |
| 83 } | 78 } |
| 84 | 79 |
| 80 bool Player::startCompositorAnimations() | |
| 81 { | |
| 82 // FIXME: Support starting compositor animations that have a fixed | |
| 83 // start time. | |
| 84 ASSERT(!hasStartTime()); | |
| 85 if (!m_content || !m_content->isAnimation()) | |
| 86 return false; | |
| 87 | |
| 88 return toAnimation(m_content.get())->startCompositorAnimations(); | |
| 89 } | |
| 90 | |
| 91 bool Player::isRunningCompositorAnimation() | |
| 92 { | |
| 93 if (!m_content || !m_content->isAnimation()) | |
| 94 return false; | |
| 95 return toAnimation(m_content.get())->isRunningCompositorAnimation(); | |
| 96 } | |
| 97 | |
| 98 void Player::cancelCompositorAnimations() | |
| 99 { | |
| 100 if (isRunningCompositorAnimation()) | |
| 101 toAnimation(m_content.get())->cancelCompositorAnimations(); | |
| 102 } | |
| 103 | |
| 85 double Player::pausedTimeDrift() const | 104 double Player::pausedTimeDrift() const |
| 86 { | 105 { |
| 87 ASSERT(pausedInternal()); | 106 ASSERT(pausedInternal()); |
| 88 return currentTimeBeforeDrift() - m_pauseStartTime; | 107 return currentTimeBeforeDrift() - m_pauseStartTime; |
| 89 } | 108 } |
| 90 | 109 |
| 91 double Player::timeDrift() const | 110 double Player::timeDrift() const |
| 92 { | 111 { |
| 93 return pausedInternal() ? pausedTimeDrift() : m_timeDrift; | 112 return pausedInternal() ? pausedTimeDrift() : m_timeDrift; |
| 94 } | 113 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 if (pausedInternal()) | 151 if (pausedInternal()) |
| 133 m_pauseStartTime = seekTime; | 152 m_pauseStartTime = seekTime; |
| 134 else | 153 else |
| 135 m_timeDrift = currentTimeBeforeDrift() - seekTime; | 154 m_timeDrift = currentTimeBeforeDrift() - seekTime; |
| 136 | 155 |
| 137 update(); | 156 update(); |
| 138 } | 157 } |
| 139 | 158 |
| 140 void Player::pauseForTesting() | 159 void Player::pauseForTesting() |
| 141 { | 160 { |
| 142 ASSERT(!paused()); | 161 RELEASE_ASSERT(!isRunningCompositorAnimation()); |
|
Steve Block
2013/11/18 05:03:03
Can you explain why you can assert this?
dstockwell
2013/11/18 06:11:20
Done.
| |
| 162 RELEASE_ASSERT(!paused()); | |
| 143 m_isPausedForTesting = true; | 163 m_isPausedForTesting = true; |
| 144 setPausedImpl(true); | 164 setPausedImpl(true); |
| 145 } | 165 } |
| 146 | 166 |
| 147 void Player::setPaused(bool newValue) | 167 void Player::setPaused(bool newValue) |
| 148 { | 168 { |
| 149 ASSERT(!m_isPausedForTesting); | 169 ASSERT(!m_isPausedForTesting); |
| 150 setPausedImpl(newValue); | 170 setPausedImpl(newValue); |
| 151 } | 171 } |
| 152 | 172 |
| 153 void Player::setPausedImpl(bool newValue) | 173 void Player::setPausedImpl(bool newValue) |
| 154 { | 174 { |
| 155 if (pausedInternal() == newValue) | 175 if (pausedInternal() == newValue) |
| 156 return; | 176 return; |
| 157 | 177 |
| 158 if (newValue) | 178 if (newValue) { |
| 179 cancelCompositorAnimations(); | |
| 159 m_pauseStartTime = currentTime(); | 180 m_pauseStartTime = currentTime(); |
| 160 else { | 181 } else { |
| 161 m_timeDrift = pausedTimeDrift(); | 182 m_timeDrift = pausedTimeDrift(); |
| 162 m_pauseStartTime = nullValue(); | 183 m_pauseStartTime = nullValue(); |
| 163 } | 184 } |
| 164 } | 185 } |
| 165 | 186 |
| 166 void Player::setPlaybackRate(double newRate) | 187 void Player::setPlaybackRate(double newRate) |
| 167 { | 188 { |
| 168 double previousTime = currentTime(); | 189 double previousTime = currentTime(); |
| 169 m_playbackRate = newRate; | 190 m_playbackRate = newRate; |
| 170 setCurrentTime(previousTime); | 191 setCurrentTime(previousTime); |
| 171 } | 192 } |
| 172 | 193 |
| 173 } // namespace | 194 } // namespace |
| OLD | NEW |