mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 05:39:41 +02:00
Automatic update from web-platform-tests [Animation Worklet] Fix flaky worklet-animation-with-fill-mode.https.html Use a more robust method for waiting on receiving local times on main thread when test is running with threaded compositing. Previously we would wait for one async frame and some more time to ensure we have received the local times on main thread. This can be flaky. Instead wait until local time is no longer null which means worklet has produced at least one frame and that frame has been synced with main. To this end WorkletAnimation now exposes its effect (similar to regular animations) and we use that to access the effect's local time. Bug: 915352 Change-Id: I05ab560d90a55ff68e048b2c8ed19e87435dffeb Reviewed-on: https://chromium-review.googlesource.com/c/1496478 Commit-Queue: Majid Valipour <majidvp@chromium.org> Reviewed-by: Yi Gu <yigu@chromium.org> Cr-Commit-Position: refs/heads/master@{#636970} -- wpt-commits: f8602d068887aebd4d962b77bcce88661ac2c245 wpt-pr: 15623
65 lines
No EOL
1.9 KiB
JavaScript
65 lines
No EOL
1.9 KiB
JavaScript
'use strict';
|
|
|
|
function registerPassthroughAnimator() {
|
|
return runInAnimationWorklet(`
|
|
registerAnimator('passthrough', class {
|
|
animate(currentTime, effect) { effect.localTime = currentTime; }
|
|
});
|
|
`);
|
|
}
|
|
|
|
function registerConstantLocalTimeAnimator(localTime) {
|
|
return runInAnimationWorklet(`
|
|
registerAnimator('constant_time', class {
|
|
animate(currentTime, effect) { effect.localTime = ${localTime}; }
|
|
});
|
|
`);
|
|
}
|
|
|
|
// TODO(majidvp): This is used to sidestep a bug where we currently animate
|
|
// with currentTime=NaN when scroll timeline is not active. Remove once we fix
|
|
// http://crbug.com/937456
|
|
function registerPassthroughExceptNaNAnimator() {
|
|
return runInAnimationWorklet(`
|
|
registerAnimator('passthrough_except_nan', class {
|
|
animate(currentTime, effect) {
|
|
if (Number.isNaN(currentTime)) return;
|
|
effect.localTime = currentTime;
|
|
}
|
|
});
|
|
`);
|
|
}
|
|
|
|
function runInAnimationWorklet(code) {
|
|
return CSS.animationWorklet.addModule(
|
|
URL.createObjectURL(new Blob([code], {type: 'text/javascript'}))
|
|
);
|
|
}
|
|
|
|
function waitForAsyncAnimationFrames(count) {
|
|
// In Chrome, waiting for N+1 main thread frames guarantees that compositor has produced
|
|
// at least N frames.
|
|
// TODO(majidvp): re-evaluate this choice once other browsers have implemented
|
|
// AnimationWorklet.
|
|
return waitForAnimationFrames(count + 1);
|
|
}
|
|
|
|
async function waitForAnimationFrameWithCondition(condition) {
|
|
do {
|
|
await new Promise(window.requestAnimationFrame);
|
|
} while (!condition())
|
|
}
|
|
|
|
async function waitForDocumentTimelineAdvance() {
|
|
const timeAtStart = document.timeline.currentTime;
|
|
do {
|
|
await new Promise(window.requestAnimationFrame);
|
|
} while (timeAtStart === document.timeline.currentTime)
|
|
}
|
|
|
|
// Wait until animation's effect has a non-null localTime.
|
|
async function waitForNotNullLocalTime(animation) {
|
|
await waitForAnimationFrameWithCondition(_ => {
|
|
return animation.effect.getComputedTiming().localTime !== null;
|
|
});
|
|
} |