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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
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 <math.h> |
31 #include "config.h" | 32 #include "config.h" |
32 #include "core/animation/AnimationClock.h" | 33 #include "core/animation/AnimationClock.h" |
| 34 #include "wtf/CurrentTime.h" |
| 35 |
| 36 namespace { |
| 37 |
| 38 // FIXME: This is an approximation of time between frames, used when |
| 39 // ticking the animation clock outside of animation frame callbacks. |
| 40 // Ideally this would be generated by the compositor. |
| 41 const double approximateFrameTime = 1 / 60.0; |
| 42 |
| 43 } |
33 | 44 |
34 namespace WebCore { | 45 namespace WebCore { |
35 | 46 |
| 47 unsigned AnimationClock::s_currentTask = 0; |
| 48 |
36 void AnimationClock::updateTime(double time) | 49 void AnimationClock::updateTime(double time) |
37 { | 50 { |
38 if (time > m_time) | 51 if (time > m_time) |
39 m_time = time; | 52 m_time = time; |
40 m_frozen = true; | 53 m_currentTask = s_currentTask; |
41 } | 54 } |
42 | 55 |
43 double AnimationClock::currentTime() | 56 double AnimationClock::currentTime() |
44 { | 57 { |
45 if (!m_frozen) { | 58 if (m_currentTask != s_currentTask) { |
46 double newTime = m_monotonicallyIncreasingTime(); | 59 double currentTime = m_monotonicallyIncreasingTime(); |
47 if (newTime >= m_time + minTimeBeforeUnsynchronizedAnimationClockTick) | 60 if (m_time < currentTime) { |
48 m_time = newTime; | 61 // Advance to the first estimated frame at or after the current time
. |
| 62 unsigned advanceCount = ceil((currentTime - m_time) / approximateFra
meTime); |
| 63 double newTime = m_time + advanceCount * approximateFrameTime; |
| 64 ASSERT(newTime >= currentTime); |
| 65 ASSERT(newTime <= currentTime + approximateFrameTime); |
| 66 updateTime(newTime); |
| 67 } |
49 } | 68 } |
50 return m_time; | 69 return m_time; |
51 } | 70 } |
52 | 71 |
| 72 void AnimationClock::resetTimeForTesting() |
| 73 { |
| 74 m_time = 0; |
| 75 m_currentTask = 0; |
| 76 s_currentTask = 0; |
53 } | 77 } |
| 78 |
| 79 } |
OLD | NEW |