haikuwebkit/LayoutTests/webanimations/scheduling-of-css-animation...

32 lines
871 B
HTML
Raw Permalink Normal View History

[Web Animations] Animation engine should not wake up every tick for steps timing functions https://bugs.webkit.org/show_bug.cgi?id=212103 <rdar://problem/62737868> Reviewed by Simon Fraser. Source/WebCore: Tests: webanimations/scheduling-of-animation-with-steps-timing-function-on-effect.html webanimations/scheduling-of-animation-with-steps-timing-function-on-keyframe.html webanimations/scheduling-of-css-animation-with-explicit-steps-timing-function-on-some-keyframes.html webanimations/scheduling-of-css-animation-with-implicit-steps-timing-function.html When an animation uses a steps() timing function, it will appear to animate discretely between values such that there is only n visual changes, where n is the number of steps provided. This gives us an opportunity to be more efficient when scheduling animations using steps() timing functions. In WebAnimation::timeToNextTick() we now ask the associated effect for the amount of progress until the next step. For an effect-wide steps() timing function, we can use the provided iteration progress. For animations with a linear effect-wide timing function (the default), we have to map the provided iteration progress to a keyframe interval, provided that interval uses a steps() timing function. The new {Animation|Keyframe}Effect::progressUntilNextStep() method returns WTF::nullopt for any other case. In order to test this, we add a new internals.timeToNextAnimationTick(animation) method which we use in the two new tests. * animation/AnimationEffect.cpp: (WebCore::AnimationEffect::progressUntilNextStep const): * animation/AnimationEffect.h: * animation/KeyframeEffect.cpp: (WebCore::KeyframeEffect::setBlendingKeyframes): (WebCore::KeyframeEffect::computeSomeKeyframesUseStepsTimingFunction): (WebCore::KeyframeEffect::timingFunctionForKeyframeAtIndex const): Avoid any out-of-bounds use of the underlying data structures by returning nullptr for cases where we don't have an explicit keyframe. We also make the function const such that it may be called from progressUntilNextStep(), it always was const but wasn't marked as such. (WebCore::KeyframeEffect::progressUntilNextStep const): * animation/KeyframeEffect.h: * animation/WebAnimation.cpp: (WebCore::WebAnimation::timeToNextTick const): * animation/WebAnimation.h: * animation/WebAnimation.idl: * testing/Internals.cpp: (WebCore::Internals::timeToNextAnimationTick const): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Allow Seconds to be divided or multiplied by a double with operands in any order. * wtf/Seconds.h: (WTF::operator*): (WTF::operator/): LayoutTests: Add tests that check that an animation using a steps() timing function correctly computes the time to the next tick accouning for the fact that it won't compute a different iteration progress until the next step. * webanimations/scheduling-of-animation-with-steps-timing-function-on-effect-expected.txt: Added. * webanimations/scheduling-of-animation-with-steps-timing-function-on-effect.html: Added. * webanimations/scheduling-of-animation-with-steps-timing-function-on-keyframe-expected.txt: Added. * webanimations/scheduling-of-animation-with-steps-timing-function-on-keyframe.html: Added. * webanimations/scheduling-of-css-animation-with-explicit-steps-timing-function-on-some-keyframes-expected.txt: Added. * webanimations/scheduling-of-css-animation-with-explicit-steps-timing-function-on-some-keyframes.html: Added. * webanimations/scheduling-of-css-animation-with-implicit-steps-timing-function-expected.txt: Added. * webanimations/scheduling-of-css-animation-with-implicit-steps-timing-function.html: Added. Canonical link: https://commits.webkit.org/225012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261926 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-20 16:26:16 +00:00
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<style>
div {
animation: anim 1s steps(10);
}
@keyframes anim {
50% { margin-left: 500px; }
}
</style>
<div></div>
<script>
async_test(async t => {
const animation = document.querySelector("div").getAnimations()[0];
await animation.ready;
animation.currentTime = 10;
assert_equals(internals.timeToNextAnimationTick(animation), 40, "Progress contained in the interval for an implicit 0% keyframe.");
animation.currentTime = 920;
assert_equals(internals.timeToNextAnimationTick(animation), 30, "Progress contained in the interval for an implicit 100% keyframe.");
t.done();
}, "Computing the time until the next tick for a CSS Animation with implicit steps() timing functions.");
</script>