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(internalCurrentTime() <= frameTime.displayFrameTime); |
53 m_time = time; | 44 m_frameTime = frameTime; |
54 m_currentTask = s_currentTask; | 45 m_currentTask = s_currentTask; |
55 } | 46 } |
56 | 47 |
57 double AnimationClock::currentTime() | 48 double AnimationClock::currentTime() |
58 { | 49 { |
50 ASSERT(m_frameTime.displayFrameTime >= 0); | |
51 ASSERT(m_frameTime.predictedNextDisplayFrameTime >= 0); | |
52 return internalCurrentTime(); | |
53 } | |
54 | |
55 double AnimationClock::internalCurrentTime() | |
56 { | |
59 if (m_currentTask != s_currentTask) { | 57 if (m_currentTask != s_currentTask) { |
60 const double currentTime = m_monotonicallyIncreasingTime(); | 58 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 } | 59 } |
72 return m_time; | 60 return m_frameTime.displayFrameTime; |
61 } | |
62 | |
63 void AnimationClock::clearTimeForTesting() | |
64 { | |
65 m_frameTime = blink::WebFrameTime(-1, -1, -1, -1); | |
eseidel
2014/07/07 16:31:50
Either make it default with an .isEmpty() accessor
mithro-old
2014/07/07 17:47:15
I've attempted a isNull / createNull pair on the W
| |
66 m_currentTask = 0; | |
67 s_currentTask = 0; | |
68 } | |
69 | |
70 void AnimationClock::tickTimeForTesting() | |
71 { | |
72 double nextTime = m_frameTime.predictedNextDisplayFrameTime; | |
73 if (nextTime == -1.0) { | |
74 nextTime = WTF::monotonicallyIncreasingTime(); | |
75 } | |
76 | |
77 updateTime(blink::WebFrameTime(-1, -1, nextTime, nextTime + (1 / 60.0))); | |
73 } | 78 } |
74 | 79 |
75 void AnimationClock::resetTimeForTesting() | 80 void AnimationClock::resetTimeForTesting() |
76 { | 81 { |
77 m_time = 0; | 82 clearTimeForTesting(); |
78 m_currentTask = 0; | 83 tickTimeForTesting(); |
79 s_currentTask = 0; | |
80 } | 84 } |
81 | |
82 } | 85 } |
OLD | NEW |