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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport()
->createAnimationTimeline()); | 82 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport()
->createAnimationTimeline()); |
83 } | 83 } |
84 | 84 |
85 ASSERT(document); | 85 ASSERT(document); |
86 } | 86 } |
87 | 87 |
88 AnimationTimeline::~AnimationTimeline() | 88 AnimationTimeline::~AnimationTimeline() |
89 { | 89 { |
90 } | 90 } |
91 | 91 |
| 92 bool AnimationTimeline::isActive() |
| 93 { |
| 94 return m_document && m_document->page(); |
| 95 } |
| 96 |
92 void AnimationTimeline::animationAttached(Animation& animation) | 97 void AnimationTimeline::animationAttached(Animation& animation) |
93 { | 98 { |
94 ASSERT(animation.timeline() == this); | 99 ASSERT(animation.timeline() == this); |
95 ASSERT(!m_animations.contains(&animation)); | 100 ASSERT(!m_animations.contains(&animation)); |
96 m_animations.add(&animation); | 101 m_animations.add(&animation); |
97 } | 102 } |
98 | 103 |
99 Animation* AnimationTimeline::play(AnimationEffect* child) | 104 Animation* AnimationTimeline::play(AnimationEffect* child) |
100 { | 105 { |
101 if (!m_document) | 106 if (!m_document) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 animations.append(animation); | 143 animations.append(animation); |
139 | 144 |
140 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority)
; | 145 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority)
; |
141 | 146 |
142 for (Animation* animation : animations) { | 147 for (Animation* animation : animations) { |
143 if (!animation->update(reason)) | 148 if (!animation->update(reason)) |
144 m_animationsNeedingUpdate.remove(animation); | 149 m_animationsNeedingUpdate.remove(animation); |
145 } | 150 } |
146 | 151 |
147 ASSERT(m_outdatedAnimationCount == 0); | 152 ASSERT(m_outdatedAnimationCount == 0); |
148 ASSERT(m_lastCurrentTimeInternal == currentTimeInternal()); | 153 ASSERT(m_lastCurrentTimeInternal == currentTimeInternal() || (std::isnan(cur
rentTimeInternal()) && std::isnan(m_lastCurrentTimeInternal))); |
149 | 154 |
150 #if ENABLE(ASSERT) | 155 #if ENABLE(ASSERT) |
151 for (const auto& animation : m_animationsNeedingUpdate) | 156 for (const auto& animation : m_animationsNeedingUpdate) |
152 ASSERT(!animation->outdated()); | 157 ASSERT(!animation->outdated()); |
153 #endif | 158 #endif |
154 } | 159 } |
155 | 160 |
156 void AnimationTimeline::scheduleNextService() | 161 void AnimationTimeline::scheduleNextService() |
157 { | 162 { |
158 ASSERT(m_outdatedAnimationCount == 0); | 163 ASSERT(m_outdatedAnimationCount == 0); |
(...skipping 10 matching lines...) Expand all Loading... |
169 } | 174 } |
170 } | 175 } |
171 | 176 |
172 void AnimationTimeline::AnimationTimelineTiming::wakeAfter(double duration) | 177 void AnimationTimeline::AnimationTimelineTiming::wakeAfter(double duration) |
173 { | 178 { |
174 if (m_timer.isActive() && m_timer.nextFireInterval() < duration) | 179 if (m_timer.isActive() && m_timer.nextFireInterval() < duration) |
175 return; | 180 return; |
176 m_timer.startOneShot(duration, BLINK_FROM_HERE); | 181 m_timer.startOneShot(duration, BLINK_FROM_HERE); |
177 } | 182 } |
178 | 183 |
179 void AnimationTimeline::AnimationTimelineTiming::cancelWake() | |
180 { | |
181 m_timer.stop(); | |
182 } | |
183 | |
184 void AnimationTimeline::AnimationTimelineTiming::serviceOnNextFrame() | 184 void AnimationTimeline::AnimationTimelineTiming::serviceOnNextFrame() |
185 { | 185 { |
186 if (m_timeline->m_document && m_timeline->m_document->view()) | 186 if (m_timeline->m_document && m_timeline->m_document->view()) |
187 m_timeline->m_document->view()->scheduleAnimation(); | 187 m_timeline->m_document->view()->scheduleAnimation(); |
188 } | 188 } |
189 | 189 |
190 DEFINE_TRACE(AnimationTimeline::AnimationTimelineTiming) | 190 DEFINE_TRACE(AnimationTimeline::AnimationTimelineTiming) |
191 { | 191 { |
192 visitor->trace(m_timeline); | 192 visitor->trace(m_timeline); |
193 AnimationTimeline::PlatformTiming::trace(visitor); | 193 AnimationTimeline::PlatformTiming::trace(visitor); |
194 } | 194 } |
195 | 195 |
196 double AnimationTimeline::zeroTime() | 196 double AnimationTimeline::zeroTime() |
197 { | 197 { |
198 if (!m_zeroTimeInitialized && m_document && m_document->loader()) { | 198 if (!m_zeroTimeInitialized && m_document && m_document->loader()) { |
199 m_zeroTime = m_document->loader()->timing().referenceMonotonicTime(); | 199 m_zeroTime = m_document->loader()->timing().referenceMonotonicTime(); |
200 m_zeroTimeInitialized = true; | 200 m_zeroTimeInitialized = true; |
201 } | 201 } |
202 return m_zeroTime; | 202 return m_zeroTime; |
203 } | 203 } |
204 | 204 |
| 205 void AnimationTimeline::resetForTesting() |
| 206 { |
| 207 m_zeroTime = 0; |
| 208 m_zeroTimeInitialized = true; |
| 209 m_playbackRate = 1; |
| 210 m_lastCurrentTimeInternal = 0; |
| 211 } |
| 212 |
205 double AnimationTimeline::currentTime(bool& isNull) | 213 double AnimationTimeline::currentTime(bool& isNull) |
206 { | 214 { |
207 return currentTimeInternal(isNull) * 1000; | 215 return currentTimeInternal(isNull) * 1000; |
208 } | 216 } |
209 | 217 |
210 double AnimationTimeline::currentTimeInternal(bool& isNull) | 218 double AnimationTimeline::currentTimeInternal(bool& isNull) |
211 { | 219 { |
212 if (!m_document) { | 220 if (!isActive()) { |
213 isNull = true; | 221 isNull = true; |
214 return std::numeric_limits<double>::quiet_NaN(); | 222 return std::numeric_limits<double>::quiet_NaN(); |
215 } | 223 } |
216 double result = m_playbackRate == 0 | 224 double result = m_playbackRate == 0 |
217 ? zeroTime() | 225 ? zeroTime() |
218 : (document()->animationClock().currentTime() - zeroTime()) * m_playback
Rate; | 226 : (document()->animationClock().currentTime() - zeroTime()) * m_playback
Rate; |
219 isNull = std::isnan(result); | 227 isNull = std::isnan(result); |
220 return result; | 228 return result; |
221 } | 229 } |
222 | 230 |
223 double AnimationTimeline::currentTime() | 231 double AnimationTimeline::currentTime() |
224 { | 232 { |
225 return currentTimeInternal() * 1000; | 233 return currentTimeInternal() * 1000; |
226 } | 234 } |
227 | 235 |
228 double AnimationTimeline::currentTimeInternal() | 236 double AnimationTimeline::currentTimeInternal() |
229 { | 237 { |
230 bool isNull; | 238 bool isNull; |
231 return currentTimeInternal(isNull); | 239 return currentTimeInternal(isNull); |
232 } | 240 } |
233 | 241 |
234 void AnimationTimeline::setCurrentTime(double currentTime) | 242 void AnimationTimeline::setCurrentTime(double currentTime) |
235 { | 243 { |
236 setCurrentTimeInternal(currentTime / 1000); | 244 setCurrentTimeInternal(currentTime / 1000); |
237 } | 245 } |
238 | 246 |
239 void AnimationTimeline::setCurrentTimeInternal(double currentTime) | 247 void AnimationTimeline::setCurrentTimeInternal(double currentTime) |
240 { | 248 { |
241 if (!document()) | 249 if (!isActive()) |
242 return; | 250 return; |
243 m_zeroTime = m_playbackRate == 0 | 251 m_zeroTime = m_playbackRate == 0 |
244 ? currentTime | 252 ? currentTime |
245 : document()->animationClock().currentTime() - currentTime / m_playbackR
ate; | 253 : document()->animationClock().currentTime() - currentTime / m_playbackR
ate; |
246 m_zeroTimeInitialized = true; | 254 m_zeroTimeInitialized = true; |
247 | 255 |
248 for (const auto& animation : m_animations) { | 256 for (const auto& animation : m_animations) { |
249 // The Player needs a timing update to pick up a new time. | 257 // The Player needs a timing update to pick up a new time. |
250 animation->setOutdated(); | 258 animation->setOutdated(); |
251 } | 259 } |
(...skipping 14 matching lines...) Expand all Loading... |
266 for (const auto& animation : m_animationsNeedingUpdate) | 274 for (const auto& animation : m_animationsNeedingUpdate) |
267 animation->pauseForTesting(pauseTime); | 275 animation->pauseForTesting(pauseTime); |
268 serviceAnimations(TimingUpdateOnDemand); | 276 serviceAnimations(TimingUpdateOnDemand); |
269 } | 277 } |
270 | 278 |
271 bool AnimationTimeline::needsAnimationTimingUpdate() | 279 bool AnimationTimeline::needsAnimationTimingUpdate() |
272 { | 280 { |
273 if (currentTimeInternal() == m_lastCurrentTimeInternal) | 281 if (currentTimeInternal() == m_lastCurrentTimeInternal) |
274 return false; | 282 return false; |
275 | 283 |
| 284 if (std::isnan(currentTimeInternal()) && std::isnan(m_lastCurrentTimeInterna
l)) |
| 285 return false; |
| 286 |
276 // We allow m_lastCurrentTimeInternal to advance here when there | 287 // We allow m_lastCurrentTimeInternal to advance here when there |
277 // are no animations to allow animations spawned during style | 288 // are no animations to allow animations spawned during style |
278 // recalc to not invalidate this flag. | 289 // recalc to not invalidate this flag. |
279 if (m_animationsNeedingUpdate.isEmpty()) | 290 if (m_animationsNeedingUpdate.isEmpty()) |
280 m_lastCurrentTimeInternal = currentTimeInternal(); | 291 m_lastCurrentTimeInternal = currentTimeInternal(); |
281 | 292 |
282 return !m_animationsNeedingUpdate.isEmpty(); | 293 return !m_animationsNeedingUpdate.isEmpty(); |
283 } | 294 } |
284 | 295 |
285 void AnimationTimeline::clearOutdatedAnimation(Animation* animation) | 296 void AnimationTimeline::clearOutdatedAnimation(Animation* animation) |
286 { | 297 { |
287 ASSERT(!animation->outdated()); | 298 ASSERT(!animation->outdated()); |
288 m_outdatedAnimationCount--; | 299 m_outdatedAnimationCount--; |
289 } | 300 } |
290 | 301 |
291 void AnimationTimeline::setOutdatedAnimation(Animation* animation) | 302 void AnimationTimeline::setOutdatedAnimation(Animation* animation) |
292 { | 303 { |
293 ASSERT(animation->outdated()); | 304 ASSERT(animation->outdated()); |
294 m_outdatedAnimationCount++; | 305 m_outdatedAnimationCount++; |
295 m_animationsNeedingUpdate.add(animation); | 306 m_animationsNeedingUpdate.add(animation); |
296 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) | 307 if (isActive() && !m_document->page()->animator().isServicingAnimations()) |
297 m_timing->serviceOnNextFrame(); | 308 m_timing->serviceOnNextFrame(); |
298 } | 309 } |
299 | 310 |
300 void AnimationTimeline::setPlaybackRate(double playbackRate) | 311 void AnimationTimeline::setPlaybackRate(double playbackRate) |
301 { | 312 { |
302 if (!document()) | 313 if (!isActive()) |
303 return; | 314 return; |
304 double currentTime = currentTimeInternal(); | 315 double currentTime = currentTimeInternal(); |
305 m_playbackRate = playbackRate; | 316 m_playbackRate = playbackRate; |
306 m_zeroTime = playbackRate == 0 | 317 m_zeroTime = playbackRate == 0 |
307 ? currentTime | 318 ? currentTime |
308 : document()->animationClock().currentTime() - currentTime / playbackRat
e; | 319 : document()->animationClock().currentTime() - currentTime / playbackRat
e; |
309 m_zeroTimeInitialized = true; | 320 m_zeroTimeInitialized = true; |
310 | 321 |
311 // Corresponding compositor animation may need to be restarted to pick up | 322 // Corresponding compositor animation may need to be restarted to pick up |
312 // the new playback rate. Marking the effect changed forces this. | 323 // the new playback rate. Marking the effect changed forces this. |
(...skipping 22 matching lines...) Expand all Loading... |
335 | 346 |
336 DEFINE_TRACE(AnimationTimeline) | 347 DEFINE_TRACE(AnimationTimeline) |
337 { | 348 { |
338 visitor->trace(m_document); | 349 visitor->trace(m_document); |
339 visitor->trace(m_timing); | 350 visitor->trace(m_timing); |
340 visitor->trace(m_animationsNeedingUpdate); | 351 visitor->trace(m_animationsNeedingUpdate); |
341 visitor->trace(m_animations); | 352 visitor->trace(m_animations); |
342 } | 353 } |
343 | 354 |
344 } // namespace | 355 } // namespace |
OLD | NEW |