Bug 211839 - [Web Animations] Use CA animations when playbackRate != 1 and direction != normal
Summary: [Web Animations] Use CA animations when playbackRate != 1 and direction != no...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Animations (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-13 06:34 PDT by Antoine Quint
Modified: 2021-09-09 04:05 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antoine Quint 2020-05-13 06:34:20 PDT
When fixing bug 204717 we made it so that we wouldn't attempt to run a CA animation if the animation's playback rate is different than 1. This bug is about trying to lift this restriction.
Comment 1 Radar WebKit Bug Importer 2020-05-13 06:34:36 PDT
<rdar://problem/63182225>
Comment 2 Antoine Quint 2020-05-20 12:47:00 PDT
Looks like we can make this work with this approach:

    1. create a CAAnimation
        1. set `animation.duration` to `webAnimation.duration`
        2. set `animation.beginTime` to `-webAnimation.currentTime`
    2. create a CAAnimationGroup
        1. set `group.speed` to `webAnimation.playbackRate`
        2. set `group.duration` to `webAnimation.effect.duration - webAnimation.currentTime`
        3. set `group.animations` to `[animation]`
Comment 3 Antoine Quint 2020-05-25 05:04:25 PDT
Actually, I think the solution is to set the CAAnimation timeOffset to match the Web Animation's currentTime and set speed to match playbackRate, but set the computed duration on a parent CAANimationGroup to clip.
Comment 4 Matt Perry 2021-08-26 06:40:21 PDT
In creating a library built upon WAAPI the only bugs I've encountered are in Webkit, and the majority of those have involved accelerated animations.

These aren't bugs I can reasonably ship to users, and setting playbackRate to 1.000001 to force animations onto the main thread in Webkit has fixed them all.

If this ticket gets resolved can you also offer a way to flag to Webkit that an animation shouldn't run on the main thread? Because looking through many of the tickets here, and indeed the linked bug in this one, a quick fix has often been to add conditions when an animation shouldn't run on Core Animation. It would be great if you could extend to developers this same opportunity, as I'm concerned that my hacky solution will re-expose users to timing bugs if they're not fixed before this ticket is resolved.
Comment 5 Matt Perry 2021-08-26 06:42:41 PDT
(In reply to Matt Perry from comment #4)

> If this ticket gets resolved can you also offer a way to flag to Webkit that
> an animation shouldn't run on the main thread? 


Apologises, that should read "should run on the main thread". Specifically something like

element.animate(keyframes, { _webkitRunOnMainThread: true })

would be appreciated.
Comment 6 Antoine Quint 2021-09-08 07:26:31 PDT
Matt, while I understand where you're coming from, I don't think offering a way to explicitly disable accelerated animations is the right approach. Rather, we need to fix bugs related to accelerated animations, so thanks for filing the bugs you have filed for now and to keep filing them as you find them.
Comment 7 Matt Perry 2021-09-08 08:37:06 PDT
I agree it’s not an ideal approach. In lieu of that would it be possible to consider the main-thread/accelerated synchronisation bugs in https://bugs.webkit.org/show_bug.cgi?id=229399 as a higher priority than this ticket? As it’s the only remaining blocker as of iOS 15
Comment 8 Antoine Quint 2021-09-09 04:05:47 PDT
Agreed, bug 229399 is something I will look into soon.