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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 double Player::currentTimeWithLag() const | 91 double Player::currentTimeWithLag() const |
92 { | 92 { |
93 ASSERT(!m_held); | 93 ASSERT(!m_held); |
94 double time = currentTimeWithoutLag(); | 94 double time = currentTimeWithoutLag(); |
95 return std::isinf(time) ? time : time - m_storedTimeLag; | 95 return std::isinf(time) ? time : time - m_storedTimeLag; |
96 } | 96 } |
97 | 97 |
98 void Player::updateTimingState(double newCurrentTime) | 98 void Player::updateTimingState(double newCurrentTime) |
99 { | 99 { |
100 ASSERT(!isNull(newCurrentTime)); | 100 ASSERT(!isNull(newCurrentTime)); |
| 101 bool oldHeld = m_held; |
101 m_held = m_paused || !m_playbackRate || limited(newCurrentTime); | 102 m_held = m_paused || !m_playbackRate || limited(newCurrentTime); |
102 if (m_held) { | 103 if (m_held) { |
| 104 if (!oldHeld || m_holdTime != newCurrentTime) |
| 105 setOutdated(); |
103 m_holdTime = newCurrentTime; | 106 m_holdTime = newCurrentTime; |
104 m_storedTimeLag = nullValue(); | 107 m_storedTimeLag = nullValue(); |
105 } else { | 108 } else { |
106 m_holdTime = nullValue(); | 109 m_holdTime = nullValue(); |
107 m_storedTimeLag = currentTimeWithoutLag() - newCurrentTime; | 110 m_storedTimeLag = currentTimeWithoutLag() - newCurrentTime; |
| 111 setOutdated(); |
108 } | 112 } |
109 setOutdated(); | |
110 } | 113 } |
111 | 114 |
112 void Player::updateCurrentTimingState() | 115 void Player::updateCurrentTimingState() |
113 { | 116 { |
114 if (m_held) { | 117 if (m_held) { |
115 updateTimingState(m_holdTime); | 118 updateTimingState(m_holdTime); |
116 } else { | 119 return; |
117 updateTimingState(currentTimeWithLag()); | |
118 if (m_held && limited(m_holdTime)) | |
119 m_holdTime = m_playbackRate < 0 ? 0 : sourceEnd(); | |
120 } | 120 } |
| 121 if (!limited(currentTimeWithLag())) |
| 122 return; |
| 123 m_held = true; |
| 124 m_holdTime = m_playbackRate < 0 ? 0 : sourceEnd(); |
| 125 m_storedTimeLag = nullValue(); |
121 } | 126 } |
122 | 127 |
123 double Player::currentTime() | 128 double Player::currentTime() |
124 { | 129 { |
125 updateCurrentTimingState(); | 130 updateCurrentTimingState(); |
126 if (m_held) | 131 if (m_held) |
127 return m_holdTime; | 132 return m_holdTime; |
128 return currentTimeWithLag(); | 133 return currentTimeWithLag(); |
129 } | 134 } |
130 | 135 |
131 void Player::setCurrentTime(double newCurrentTime) | 136 void Player::setCurrentTime(double newCurrentTime) |
132 { | 137 { |
133 if (!std::isfinite(newCurrentTime)) | 138 if (!std::isfinite(newCurrentTime)) |
134 return; | 139 return; |
135 updateTimingState(newCurrentTime); | 140 updateTimingState(newCurrentTime); |
136 } | 141 } |
137 | 142 |
138 void Player::setStartTime(double newStartTime) | 143 void Player::setStartTime(double newStartTime) |
139 { | 144 { |
140 if (!std::isfinite(newStartTime)) | 145 if (!std::isfinite(newStartTime)) |
141 return; | 146 return; |
142 updateCurrentTimingState(); // Update the value of held | 147 updateCurrentTimingState(); // Update the value of held |
143 m_startTime = newStartTime; | 148 m_startTime = newStartTime; |
144 if (!m_held) | 149 if (m_held) |
145 updateCurrentTimingState(); | 150 return; |
| 151 updateCurrentTimingState(); |
| 152 setOutdated(); |
146 } | 153 } |
147 | 154 |
148 void Player::setSource(TimedItem* newSource) | 155 void Player::setSource(TimedItem* newSource) |
149 { | 156 { |
150 if (m_content == newSource) | 157 if (m_content == newSource) |
151 return; | 158 return; |
152 double storedCurrentTime = currentTime(); | 159 double storedCurrentTime = currentTime(); |
153 if (m_content) | 160 if (m_content) |
154 m_content->detach(); | 161 m_content->detach(); |
155 m_content = newSource; | 162 m_content = newSource; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 264 } |
258 | 265 |
259 void Player::cancelAnimationOnCompositor() | 266 void Player::cancelAnimationOnCompositor() |
260 { | 267 { |
261 if (hasActiveAnimationsOnCompositor()) | 268 if (hasActiveAnimationsOnCompositor()) |
262 toAnimation(m_content.get())->cancelAnimationOnCompositor(); | 269 toAnimation(m_content.get())->cancelAnimationOnCompositor(); |
263 } | 270 } |
264 | 271 |
265 bool Player::update() | 272 bool Player::update() |
266 { | 273 { |
267 if (!m_timeline) | 274 m_outdated = false; |
| 275 |
| 276 if (!m_timeline || !m_content) |
268 return false; | 277 return false; |
269 | 278 |
270 double inheritedTime = isNull(m_timeline->currentTime()) ? nullValue() : cur
rentTime(); | 279 double inheritedTime = isNull(m_timeline->currentTime()) ? nullValue() : cur
rentTime(); |
271 m_outdated = false; | |
272 | |
273 if (!m_content) | |
274 return false; | |
275 | |
276 m_content->updateInheritedTime(inheritedTime); | 280 m_content->updateInheritedTime(inheritedTime); |
277 | 281 |
278 ASSERT(!m_outdated); | 282 ASSERT(!m_outdated); |
279 return m_content->isCurrent() || m_content->isInEffect(); | 283 return m_content->isCurrent() || m_content->isInEffect(); |
280 } | 284 } |
281 | 285 |
282 double Player::timeToEffectChange() | 286 double Player::timeToEffectChange() |
283 { | 287 { |
284 ASSERT(!m_outdated); | 288 ASSERT(!m_outdated); |
285 if (!m_content || !m_playbackRate) | 289 if (!m_content || !m_playbackRate) |
(...skipping 17 matching lines...) Expand all Loading... |
303 { | 307 { |
304 RELEASE_ASSERT(!paused()); | 308 RELEASE_ASSERT(!paused()); |
305 updateTimingState(pauseTime); | 309 updateTimingState(pauseTime); |
306 if (!m_isPausedForTesting && hasActiveAnimationsOnCompositor()) | 310 if (!m_isPausedForTesting && hasActiveAnimationsOnCompositor()) |
307 toAnimation(m_content.get())->pauseAnimationForTestingOnCompositor(curre
ntTime()); | 311 toAnimation(m_content.get())->pauseAnimationForTestingOnCompositor(curre
ntTime()); |
308 m_isPausedForTesting = true; | 312 m_isPausedForTesting = true; |
309 pause(); | 313 pause(); |
310 } | 314 } |
311 | 315 |
312 } // namespace | 316 } // namespace |
OLD | NEW |