| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/animation/AnimationClock.h" | 32 #include "core/animation/AnimationClock.h" |
| 33 | 33 |
| 34 #include "wtf/CurrentTime.h" | |
| 35 #include <math.h> | |
| 36 | |
| 37 namespace { | |
| 38 | |
| 39 // FIXME: This is an approximation of time between frames, used when | |
| 40 // ticking the animation clock outside of animation frame callbacks. | |
| 41 // Ideally this would be generated by the compositor. | |
| 42 const double approximateFrameTime = 1 / 60.0; | |
| 43 | |
| 44 } | |
| 45 | |
| 46 namespace WebCore { | 34 namespace WebCore { |
| 47 | 35 |
| 48 unsigned AnimationClock::s_currentTask = 0; | |
| 49 | |
| 50 void AnimationClock::updateTime(double time) | 36 void AnimationClock::updateTime(double time) |
| 51 { | 37 { |
| 52 if (time > m_time) | 38 if (time > m_time) |
| 53 m_time = time; | 39 m_time = time; |
| 54 m_currentTask = s_currentTask; | 40 m_frozen = true; |
| 55 } | 41 } |
| 56 | 42 |
| 57 double AnimationClock::currentTime() | 43 double AnimationClock::currentTime() |
| 58 { | 44 { |
| 59 if (m_currentTask != s_currentTask) { | 45 if (!m_frozen) { |
| 60 const double currentTime = m_monotonicallyIncreasingTime(); | 46 double newTime = m_monotonicallyIncreasingTime(); |
| 61 if (m_time < currentTime) { | 47 if (newTime >= m_time + minTimeBeforeUnsynchronizedAnimationClockTick) |
| 62 // Advance to the first estimated frame after the current time. | 48 m_time = newTime; |
| 63 const double frameShift = fmod(currentTime - m_time, approximateFram
eTime); | |
| 64 const double newTime = currentTime + approximateFrameTime - frameShi
ft; | |
| 65 ASSERT(newTime > currentTime); | |
| 66 ASSERT(newTime <= currentTime + approximateFrameTime); | |
| 67 updateTime(newTime); | |
| 68 } else { | |
| 69 m_currentTask = s_currentTask; | |
| 70 } | |
| 71 } | 49 } |
| 72 return m_time; | 50 return m_time; |
| 73 } | 51 } |
| 74 | 52 |
| 75 void AnimationClock::resetTimeForTesting() | |
| 76 { | |
| 77 m_time = 0; | |
| 78 m_currentTask = 0; | |
| 79 s_currentTask = 0; | |
| 80 } | 53 } |
| 81 | |
| 82 } | |
| OLD | NEW |