| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 PassRefPtrWillBeRawPtr<AnimationTimeline> AnimationTimeline::create(Document* do
cument, PassOwnPtrWillBeRawPtr<PlatformTiming> timing) | 62 PassRefPtrWillBeRawPtr<AnimationTimeline> AnimationTimeline::create(Document* do
cument, PassOwnPtrWillBeRawPtr<PlatformTiming> timing) |
| 63 { | 63 { |
| 64 return adoptRefWillBeNoop(new AnimationTimeline(document, timing)); | 64 return adoptRefWillBeNoop(new AnimationTimeline(document, timing)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 AnimationTimeline::AnimationTimeline(Document* document, PassOwnPtrWillBeRawPtr<
PlatformTiming> timing) | 67 AnimationTimeline::AnimationTimeline(Document* document, PassOwnPtrWillBeRawPtr<
PlatformTiming> timing) |
| 68 : m_document(document) | 68 : m_document(document) |
| 69 , m_zeroTime(0) // 0 is used by unit tests which cannot initialize from the
loader | 69 , m_zeroTime(0) // 0 is used by unit tests which cannot initialize from the
loader |
| 70 , m_zeroTimeInitialized(false) | 70 , m_zeroTimeInitialized(false) |
| 71 , m_outdatedAnimationCount(0) |
| 71 , m_playbackRate(1) | 72 , m_playbackRate(1) |
| 72 , m_lastCurrentTimeInternal(0) | 73 , m_lastCurrentTimeInternal(0) |
| 73 { | 74 { |
| 74 if (!timing) | 75 if (!timing) |
| 75 m_timing = adoptPtrWillBeNoop(new AnimationTimelineTiming(this)); | 76 m_timing = adoptPtrWillBeNoop(new AnimationTimelineTiming(this)); |
| 76 else | 77 else |
| 77 m_timing = timing; | 78 m_timing = timing; |
| 78 | 79 |
| 79 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor
m::current()->compositorSupport()) | 80 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor
m::current()->compositorSupport()) |
| 80 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport()
->createAnimationTimeline()); | 81 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport()
->createAnimationTimeline()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 for (RefPtrWillBeMember<Animation> animation : m_animationsNeedingUpdate) | 141 for (RefPtrWillBeMember<Animation> animation : m_animationsNeedingUpdate) |
| 141 animations.append(animation.get()); | 142 animations.append(animation.get()); |
| 142 | 143 |
| 143 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority)
; | 144 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority)
; |
| 144 | 145 |
| 145 for (Animation* animation : animations) { | 146 for (Animation* animation : animations) { |
| 146 if (!animation->update(reason)) | 147 if (!animation->update(reason)) |
| 147 m_animationsNeedingUpdate.remove(animation); | 148 m_animationsNeedingUpdate.remove(animation); |
| 148 } | 149 } |
| 149 | 150 |
| 150 ASSERT(!hasOutdatedAnimation()); | 151 ASSERT(m_outdatedAnimationCount == 0); |
| 152 |
| 153 #if ENABLE(ASSERT) |
| 154 for (const auto& animation : m_animationsNeedingUpdate) |
| 155 ASSERT(!animation->outdated()); |
| 156 #endif |
| 151 } | 157 } |
| 152 | 158 |
| 153 void AnimationTimeline::scheduleNextService() | 159 void AnimationTimeline::scheduleNextService() |
| 154 { | 160 { |
| 155 ASSERT(!hasOutdatedAnimation()); | 161 ASSERT(m_outdatedAnimationCount == 0); |
| 156 | 162 |
| 157 double timeToNextEffect = std::numeric_limits<double>::infinity(); | 163 double timeToNextEffect = std::numeric_limits<double>::infinity(); |
| 158 for (const auto& animation : m_animationsNeedingUpdate) { | 164 for (const auto& animation : m_animationsNeedingUpdate) { |
| 159 timeToNextEffect = std::min(timeToNextEffect, animation->timeToEffectCha
nge()); | 165 timeToNextEffect = std::min(timeToNextEffect, animation->timeToEffectCha
nge()); |
| 160 } | 166 } |
| 161 | 167 |
| 162 if (timeToNextEffect < s_minimumDelay) { | 168 if (timeToNextEffect < s_minimumDelay) { |
| 163 m_timing->serviceOnNextFrame(); | 169 m_timing->serviceOnNextFrame(); |
| 164 } else if (timeToNextEffect != std::numeric_limits<double>::infinity()) { | 170 } else if (timeToNextEffect != std::numeric_limits<double>::infinity()) { |
| 165 m_timing->wakeAfter(timeToNextEffect - s_minimumDelay); | 171 m_timing->wakeAfter(timeToNextEffect - s_minimumDelay); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return std::isnan(time) ? 0 : time; | 261 return std::isnan(time) ? 0 : time; |
| 256 } | 262 } |
| 257 | 263 |
| 258 void AnimationTimeline::pauseAnimationsForTesting(double pauseTime) | 264 void AnimationTimeline::pauseAnimationsForTesting(double pauseTime) |
| 259 { | 265 { |
| 260 for (const auto& animation : m_animationsNeedingUpdate) | 266 for (const auto& animation : m_animationsNeedingUpdate) |
| 261 animation->pauseForTesting(pauseTime); | 267 animation->pauseForTesting(pauseTime); |
| 262 serviceAnimations(TimingUpdateOnDemand); | 268 serviceAnimations(TimingUpdateOnDemand); |
| 263 } | 269 } |
| 264 | 270 |
| 265 bool AnimationTimeline::hasOutdatedAnimation() const | |
| 266 { | |
| 267 for (const auto& animation : m_animationsNeedingUpdate) { | |
| 268 if (animation->outdated()) | |
| 269 return true; | |
| 270 } | |
| 271 return false; | |
| 272 } | |
| 273 | |
| 274 bool AnimationTimeline::needsAnimationTimingUpdate() | 271 bool AnimationTimeline::needsAnimationTimingUpdate() |
| 275 { | 272 { |
| 276 return m_animationsNeedingUpdate.size() && currentTimeInternal() != m_lastCu
rrentTimeInternal; | 273 return m_animationsNeedingUpdate.size() && currentTimeInternal() != m_lastCu
rrentTimeInternal; |
| 277 } | 274 } |
| 278 | 275 |
| 276 void AnimationTimeline::clearOutdatedAnimation(Animation* animation) |
| 277 { |
| 278 ASSERT(!animation->outdated()); |
| 279 m_outdatedAnimationCount--; |
| 280 } |
| 281 |
| 279 void AnimationTimeline::setOutdatedAnimation(Animation* animation) | 282 void AnimationTimeline::setOutdatedAnimation(Animation* animation) |
| 280 { | 283 { |
| 281 ASSERT(animation->outdated()); | 284 ASSERT(animation->outdated()); |
| 285 m_outdatedAnimationCount++; |
| 282 m_animationsNeedingUpdate.add(animation); | 286 m_animationsNeedingUpdate.add(animation); |
| 283 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) | 287 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) |
| 284 m_timing->serviceOnNextFrame(); | 288 m_timing->serviceOnNextFrame(); |
| 285 } | 289 } |
| 286 | 290 |
| 287 void AnimationTimeline::setPlaybackRate(double playbackRate) | 291 void AnimationTimeline::setPlaybackRate(double playbackRate) |
| 288 { | 292 { |
| 289 if (!document()) | 293 if (!document()) |
| 290 return; | 294 return; |
| 291 double currentTime = currentTimeInternal(); | 295 double currentTime = currentTimeInternal(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 319 { | 323 { |
| 320 #if ENABLE(OILPAN) | 324 #if ENABLE(OILPAN) |
| 321 visitor->trace(m_document); | 325 visitor->trace(m_document); |
| 322 visitor->trace(m_timing); | 326 visitor->trace(m_timing); |
| 323 visitor->trace(m_animationsNeedingUpdate); | 327 visitor->trace(m_animationsNeedingUpdate); |
| 324 visitor->trace(m_animations); | 328 visitor->trace(m_animations); |
| 325 #endif | 329 #endif |
| 326 } | 330 } |
| 327 | 331 |
| 328 } // namespace | 332 } // namespace |
| OLD | NEW |