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 |
34 namespace WebCore { | 46 namespace WebCore { |
35 | 47 |
| 48 unsigned AnimationClock::s_currentTask = 0; |
| 49 |
36 void AnimationClock::updateTime(double time) | 50 void AnimationClock::updateTime(double time) |
37 { | 51 { |
38 if (time > m_time) | 52 if (time > m_time) |
39 m_time = time; | 53 m_time = time; |
40 m_frozen = true; | 54 m_currentTask = s_currentTask; |
41 } | 55 } |
42 | 56 |
43 double AnimationClock::currentTime() | 57 double AnimationClock::currentTime() |
44 { | 58 { |
45 if (!m_frozen) { | 59 if (m_currentTask != s_currentTask) { |
46 double newTime = m_monotonicallyIncreasingTime(); | 60 const double currentTime = m_monotonicallyIncreasingTime(); |
47 if (newTime >= m_time + minTimeBeforeUnsynchronizedAnimationClockTick) | 61 if (m_time < currentTime) { |
48 m_time = newTime; | 62 // Advance to the first estimated frame after the current time. |
| 63 const double frameShift = fmod(currentTime - m_time, approximateFram
eTime); |
| 64 const double newTime = currentTime + (approximateFrameTime - frameSh
ift); |
| 65 ASSERT(newTime >= currentTime); |
| 66 ASSERT(newTime <= currentTime + approximateFrameTime); |
| 67 updateTime(newTime); |
| 68 } else { |
| 69 m_currentTask = s_currentTask; |
| 70 } |
49 } | 71 } |
50 return m_time; | 72 return m_time; |
51 } | 73 } |
52 | 74 |
| 75 void AnimationClock::resetTimeForTesting() |
| 76 { |
| 77 m_time = 0; |
| 78 m_currentTask = 0; |
| 79 s_currentTask = 0; |
53 } | 80 } |
| 81 |
| 82 } |
OLD | NEW |