| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 | 57 |
| 58 PassRefPtrWillBeRawPtr<AnimationTimeline> AnimationTimeline::create(Document* do
cument, PassOwnPtrWillBeRawPtr<PlatformTiming> timing) | 58 PassRefPtrWillBeRawPtr<AnimationTimeline> AnimationTimeline::create(Document* do
cument, PassOwnPtrWillBeRawPtr<PlatformTiming> timing) |
| 59 { | 59 { |
| 60 return adoptRefWillBeNoop(new AnimationTimeline(document, timing)); | 60 return adoptRefWillBeNoop(new AnimationTimeline(document, timing)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 AnimationTimeline::AnimationTimeline(Document* document, PassOwnPtrWillBeRawPtr<
PlatformTiming> timing) | 63 AnimationTimeline::AnimationTimeline(Document* document, PassOwnPtrWillBeRawPtr<
PlatformTiming> timing) |
| 64 : m_document(document) | 64 : m_document(document) |
| 65 , m_zeroTime(0) | 65 , m_zeroTime(0) |
| 66 , m_currentTimeSnapshot(0) |
| 67 , m_rawCurrentTimeSnapshot(0) |
| 68 , m_playbackRate(1) |
| 66 { | 69 { |
| 67 if (!timing) | 70 if (!timing) |
| 68 m_timing = adoptPtrWillBeNoop(new AnimationTimelineTiming(this)); | 71 m_timing = adoptPtrWillBeNoop(new AnimationTimelineTiming(this)); |
| 69 else | 72 else |
| 70 m_timing = timing; | 73 m_timing = timing; |
| 71 | 74 |
| 72 ASSERT(document); | 75 ASSERT(document); |
| 73 } | 76 } |
| 74 | 77 |
| 75 AnimationTimeline::~AnimationTimeline() | 78 AnimationTimeline::~AnimationTimeline() |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 { | 180 { |
| 178 return currentTimeInternal(isNull) * 1000; | 181 return currentTimeInternal(isNull) * 1000; |
| 179 } | 182 } |
| 180 | 183 |
| 181 double AnimationTimeline::currentTimeInternal(bool& isNull) | 184 double AnimationTimeline::currentTimeInternal(bool& isNull) |
| 182 { | 185 { |
| 183 if (!m_document) { | 186 if (!m_document) { |
| 184 isNull = true; | 187 isNull = true; |
| 185 return std::numeric_limits<double>::quiet_NaN(); | 188 return std::numeric_limits<double>::quiet_NaN(); |
| 186 } | 189 } |
| 187 double result = m_document->animationClock().currentTime() - zeroTime(); | 190 // New currentTime = currentTime when the playback rate was last changed + t
ime delta since then * playback rate |
| 191 double result = m_currentTimeSnapshot + (m_document->animationClock().curren
tTime() - m_rawCurrentTimeSnapshot - zeroTime()) * playbackRate(); |
| 188 isNull = std::isnan(result); | 192 isNull = std::isnan(result); |
| 189 return result; | 193 return result; |
| 190 } | 194 } |
| 191 | 195 |
| 192 double AnimationTimeline::currentTime() | 196 double AnimationTimeline::currentTime() |
| 193 { | 197 { |
| 194 return currentTimeInternal() * 1000; | 198 return currentTimeInternal() * 1000; |
| 195 } | 199 } |
| 196 | 200 |
| 197 double AnimationTimeline::currentTimeInternal() | 201 double AnimationTimeline::currentTimeInternal() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 223 } | 227 } |
| 224 | 228 |
| 225 void AnimationTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) | 229 void AnimationTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) |
| 226 { | 230 { |
| 227 ASSERT(player->outdated()); | 231 ASSERT(player->outdated()); |
| 228 m_playersNeedingUpdate.add(player); | 232 m_playersNeedingUpdate.add(player); |
| 229 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) | 233 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) |
| 230 m_timing->serviceOnNextFrame(); | 234 m_timing->serviceOnNextFrame(); |
| 231 } | 235 } |
| 232 | 236 |
| 237 void AnimationTimeline::setPlaybackRate(double playbackRate) |
| 238 { |
| 239 // FIXME: need to invalidate compositor animations |
| 240 m_currentTimeSnapshot = currentTimeInternal(); |
| 241 m_rawCurrentTimeSnapshot = m_document->animationClock().currentTime() - zero
Time(); |
| 242 m_playbackRate = playbackRate; |
| 243 } |
| 244 |
| 245 double AnimationTimeline::playbackRate() const |
| 246 { |
| 247 return m_playbackRate; |
| 248 } |
| 249 |
| 233 #if !ENABLE(OILPAN) | 250 #if !ENABLE(OILPAN) |
| 234 void AnimationTimeline::detachFromDocument() | 251 void AnimationTimeline::detachFromDocument() |
| 235 { | 252 { |
| 236 // FIXME: AnimationTimeline should keep Document alive. | 253 // FIXME: AnimationTimeline should keep Document alive. |
| 237 m_document = nullptr; | 254 m_document = nullptr; |
| 238 } | 255 } |
| 239 #endif | 256 #endif |
| 240 | 257 |
| 241 void AnimationTimeline::trace(Visitor* visitor) | 258 void AnimationTimeline::trace(Visitor* visitor) |
| 242 { | 259 { |
| 243 #if ENABLE(OILPAN) | 260 #if ENABLE(OILPAN) |
| 244 visitor->trace(m_document); | 261 visitor->trace(m_document); |
| 245 visitor->trace(m_timing); | 262 visitor->trace(m_timing); |
| 246 visitor->trace(m_playersNeedingUpdate); | 263 visitor->trace(m_playersNeedingUpdate); |
| 247 visitor->trace(m_players); | 264 visitor->trace(m_players); |
| 248 #endif | 265 #endif |
| 249 } | 266 } |
| 250 | 267 |
| 251 } // namespace | 268 } // namespace |
| OLD | NEW |