Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Unified Diff: Source/core/animation/AnimationClock.cpp

Issue 369793003: Make the web-animations engine use the passed in blink::WebFrameTime values. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixing remaining usages of -1 in the code. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/animation/AnimationClock.h ('k') | Source/core/animation/AnimationClockTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/animation/AnimationClock.cpp
diff --git a/Source/core/animation/AnimationClock.cpp b/Source/core/animation/AnimationClock.cpp
index d51c95e7aed188da489a296342619fdac98b2841..89348c85107c5fc367d3cb6464a7c1c5af4e9ead 100644
--- a/Source/core/animation/AnimationClock.cpp
+++ b/Source/core/animation/AnimationClock.cpp
@@ -34,49 +34,73 @@
#include "wtf/CurrentTime.h"
#include <math.h>
-namespace {
-
-// FIXME: This is an approximation of time between frames, used when
-// ticking the animation clock outside of animation frame callbacks.
-// Ideally this would be generated by the compositor.
-const double approximateFrameTime = 1 / 60.0;
-
-}
-
namespace WebCore {
unsigned AnimationClock::s_currentTask = 0;
-void AnimationClock::updateTime(double time)
+void AnimationClock::updateTime(blink::WebFrameTime frameTime)
{
- if (time > m_time)
- m_time = time;
+ ASSERT(!frameTime.isNull());
+ ASSERT(internalCurrentTime() <= frameTime.displayFrameTime);
+ m_frameTime = frameTime;
m_currentTask = s_currentTask;
}
double AnimationClock::currentTime()
{
+ ASSERT(!m_frameTime.isNull());
+ ASSERT(m_frameTime.displayFrameTime >= 0);
+ ASSERT(m_frameTime.predictedNextDisplayFrameTime >= 0);
+ return internalCurrentTime();
+}
+
+double AnimationClock::internalCurrentTime()
+{
if (m_currentTask != s_currentTask) {
- const double currentTime = m_monotonicallyIncreasingTime();
- if (m_time < currentTime) {
- // Advance to the first estimated frame after the current time.
- const double frameShift = fmod(currentTime - m_time, approximateFrameTime);
- const double newTime = currentTime + (approximateFrameTime - frameShift);
- ASSERT(newTime >= currentTime);
- ASSERT(newTime <= currentTime + approximateFrameTime);
- updateTime(newTime);
- } else {
- m_currentTask = s_currentTask;
- }
+ return m_frameTime.predictedNextDisplayFrameTime;
}
- return m_time;
+ return m_frameTime.displayFrameTime;
}
-void AnimationClock::resetTimeForTesting()
+void AnimationClock::clearTimeForTesting()
{
- m_time = 0;
+ m_frameTime = blink::WebFrameTime();
m_currentTask = 0;
s_currentTask = 0;
}
+void AnimationClock::tickTimeForTesting()
+{
+ double nextTime = m_frameTime.predictedNextDisplayFrameTime;
+ if (nextTime == blink::WebFrameTime::Undefined) {
+ nextTime = WTF::monotonicallyIncreasingTime();
+ }
+
+ // AnimationClock doesn't use lastFrameTime or renderDeadline so we just
+ // use dummy values when testing.
+ updateTime(
+ blink::WebFrameTime(
+ blink::WebFrameTime::Undefined,
+ blink::WebFrameTime::Undefined,
+ nextTime,
+ nextTime + (1 / 60.0)));
+}
+
+void AnimationClock::resetTimeForTesting()
+{
+ clearTimeForTesting();
+ tickTimeForTesting();
+}
+
+blink::WebFrameTime AnimationClock::createTimeForTesting(double currentFrameMonotonic, double nextFrameMonotonic)
+{
+ // AnimationClock doesn't use the first two fields (lastFrameTime and
+ // renderDeadline).
+ return blink::WebFrameTime(
+ blink::WebFrameTime::Undefined,
+ blink::WebFrameTime::Undefined,
+ currentFrameMonotonic,
+ nextFrameMonotonic);
+}
+
}
« no previous file with comments | « Source/core/animation/AnimationClock.h ('k') | Source/core/animation/AnimationClockTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698