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 16 matching lines...) Expand all Loading... |
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" | 34 #include "wtf/CurrentTime.h" |
35 #include <math.h> | 35 #include <math.h> |
36 | 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 { | 37 namespace WebCore { |
47 | 38 |
48 unsigned AnimationClock::s_currentTask = 0; | 39 unsigned AnimationClock::s_currentTask = 0; |
49 | 40 |
50 void AnimationClock::updateTime(double time) | 41 void AnimationClock::updateTime(blink::WebFrameTime frameTime) |
51 { | 42 { |
52 if (time > m_time) | 43 ASSERT(!frameTime.isNull()); |
53 m_time = time; | 44 ASSERT(internalCurrentTime() <= frameTime.displayFrameTime); |
| 45 m_frameTime = frameTime; |
54 m_currentTask = s_currentTask; | 46 m_currentTask = s_currentTask; |
55 } | 47 } |
56 | 48 |
57 double AnimationClock::currentTime() | 49 double AnimationClock::currentTime() |
58 { | 50 { |
| 51 ASSERT(!m_frameTime.isNull()); |
| 52 ASSERT(m_frameTime.displayFrameTime >= 0); |
| 53 ASSERT(m_frameTime.predictedNextDisplayFrameTime >= 0); |
| 54 return internalCurrentTime(); |
| 55 } |
| 56 |
| 57 double AnimationClock::internalCurrentTime() |
| 58 { |
59 if (m_currentTask != s_currentTask) { | 59 if (m_currentTask != s_currentTask) { |
60 const double currentTime = m_monotonicallyIncreasingTime(); | 60 return m_frameTime.predictedNextDisplayFrameTime; |
61 if (m_time < currentTime) { | |
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 } | |
71 } | 61 } |
72 return m_time; | 62 return m_frameTime.displayFrameTime; |
| 63 } |
| 64 |
| 65 void AnimationClock::clearTimeForTesting() |
| 66 { |
| 67 m_frameTime = blink::WebFrameTime(); |
| 68 m_currentTask = 0; |
| 69 s_currentTask = 0; |
| 70 } |
| 71 |
| 72 void AnimationClock::tickTimeForTesting() |
| 73 { |
| 74 double nextTime = m_frameTime.predictedNextDisplayFrameTime; |
| 75 if (nextTime == blink::WebFrameTime::Undefined) { |
| 76 nextTime = WTF::monotonicallyIncreasingTime(); |
| 77 } |
| 78 |
| 79 // AnimationClock doesn't use lastFrameTime or renderDeadline so we just |
| 80 // use dummy values when testing. |
| 81 updateTime( |
| 82 blink::WebFrameTime( |
| 83 blink::WebFrameTime::Undefined, |
| 84 blink::WebFrameTime::Undefined, |
| 85 nextTime, |
| 86 nextTime + (1 / 60.0))); |
73 } | 87 } |
74 | 88 |
75 void AnimationClock::resetTimeForTesting() | 89 void AnimationClock::resetTimeForTesting() |
76 { | 90 { |
77 m_time = 0; | 91 clearTimeForTesting(); |
78 m_currentTask = 0; | 92 tickTimeForTesting(); |
79 s_currentTask = 0; | 93 } |
| 94 |
| 95 blink::WebFrameTime AnimationClock::createTimeForTesting(double currentFrameMono
tonic, double nextFrameMonotonic) |
| 96 { |
| 97 // AnimationClock doesn't use the first two fields (lastFrameTime and |
| 98 // renderDeadline). |
| 99 return blink::WebFrameTime( |
| 100 blink::WebFrameTime::Undefined, |
| 101 blink::WebFrameTime::Undefined, |
| 102 currentFrameMonotonic, |
| 103 nextFrameMonotonic); |
80 } | 104 } |
81 | 105 |
82 } | 106 } |
OLD | NEW |