Skip to content

Commit 199ca9f

Browse files
authored
[css-animationworklet] Add a principles document and implementation status (w3c#824)
Adding a principles document listing the objective and key principles. In particular, it lists a few directions for extending API to cover additional key usecases not addressed by current proposal. Also added an implementation status document which list rough road for the feature implementation in Chrome which should help anyone planning to plan to experiment with it. Minor fixes: - replace AnimationWorklet with Animation Worklet where appropriate - Fix broken link and remove old link to CompositorWorker.
1 parent d0f4fd7 commit 199ca9f

File tree

3 files changed

+166
-11
lines changed

3 files changed

+166
-11
lines changed

css-animationworklet/README.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Overview
55

6-
AnimationWorklet is a new primitive for creating scroll-linked and other high performance
6+
Animation Worklet is a new primitive for creating scroll-linked and other high performance
77
procedural animations on the web. It is being incubated here as part of the
88
[CSS Houdini task force](https://github.com/w3c/css-houdini-drafts/wiki), and if successful will be
99
transferred to that task force for full standardization.
@@ -24,7 +24,10 @@ environment, *worklet*. It aims to be compatible with Web Animations and uses ex
2424
much as possible. We believe this API hits a sweet spot in balancing among performance, richness,
2525
and rationality for addressing our key use cases.
2626

27-
This design supersedes our [CompositorWorker proposal][cw-proposal].
27+
See the [Animation Worklet design principles and goals](principles.md) for an overview of the
28+
motivations behind Animation Worklet and how the design will be evolved to support a growing set of
29+
rich use cases. Also see [the status document](status.md) for high level implementation status and
30+
timeline.
2831

2932
# Motivating Use Cases
3033

@@ -46,11 +49,8 @@ This design supersedes our [CompositorWorker proposal][cw-proposal].
4649
- Efficient Expando ([demo](http://googlechromelabs.github.io/houdini-samples/animation-worklet/expando/), [more info](https://developers.google.com/web/updates/2017/03/performant-expand-and-collapse))
4750
- Compositing growing / shrinking box with border (using 9 patch)
4851

49-
* Animating scroll offsets:
5052

51-
- Having multiple scrollers scroll in sync e.g. diff viewer keeping old/new in sync when you
52-
scroll either ([demo](https://googlechromelabs.github.io/houdini-samples/animation-worklet/sync-scroller/))
53-
- Implementing smooth scroll animations (e.g., custom physic based fling curves)
53+
These usecases are enabled by the current proposed but [additional usecases](principles.md#animation-worklet-vision) are going to be addressed by extension of the API.
5454

5555
***Note***: Demos work best in the latest Chrome Canary with the experimental
5656
web platform features enabled (`--enable-experimental-web-platform-features`
@@ -101,10 +101,10 @@ makes it possible for worklet animation to drive effects spanning multiple eleme
101101

102102
**TODO**: At the moment, `GroupEffect` only supports just two different scheduling models (i.e.,
103103
parallel, sequence). These models governs how the group effect time is translated to its children
104-
effect times by modifying the child effect start time. AnimationWorklet allows a much more flexible
105-
scheduling model by making it possible to to set children effect's local time directly. In other
106-
words we allow arbitrary start time for child effects. This is something that needs to be added to
107-
level 2 spec.
104+
effect times by modifying the child effect start time. Animation Worklet allows a much more
105+
flexible scheduling model by making it possible to to set children effect's local time directly. In
106+
other words we allow arbitrary start time for child effects. This is something that needs to be
107+
added to level 2 spec.
108108

109109
## Multiple Timelines
110110
Unlike typical animations, worklet animations can be attached to multiple timelines. This is
@@ -389,9 +389,10 @@ partial interface AnimationEffectReadOnly {
389389
390390
391391
# Specification
392-
The [draft specification](https://https://drafts.css-houdini.org/css-animationworklet) is
392+
The [draft specification](https://drafts.css-houdini.org/css-animationworklet) is
393393
the most recent version.
394394
395395
396396
[roc-thread]: https://lists.w3.org/Archives/Public/public-houdini/2015Mar/0020.html
397397
[cw-proposal]: https://github.com/w3c/css-houdini-drafts/blob/master/composited-scrolling-and-animation/Explainer.md
398+

css-animationworklet/principles.md

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Animation Worklet Design Principles and Goals
2+
***for rich interactive effects on the Web Platform***
3+
4+
5+
## Problem and Motivation
6+
7+
**Fact**: Fact: It is difficult to build smooth rich interactive effects on the web.
8+
9+
**Why do we care?**
10+
Silky smooth rich interactive user interfaces are now a [basic user expectation][performance] on
11+
modern computing platforms. For web platform to remain competitive it should be capable of high
12+
fidelity, smooth, responsive UI.
13+
14+
15+
**Where is the difficulty?**
16+
Three key aspects of rich interactive effects are: smoothness, responsiveness to input (a.k.a. R & A
17+
of [RAILS model][rails]) and their rich interaction model.
18+
19+
The two main methods for creating animations on the web fall short in at least one of these aspects:
20+
21+
- CSS (Web) Animations: Aimed at supporting stateless declarative time-driven effects. The
22+
expressiveness is sufficient for common time-based effects. The resulting animation can be smooth
23+
<sup>[1](#footnote1)</sup>. However it's unclear how this model can be scaled to handle the
24+
multi-dimensional inputs, conditional values, and statefulness required by the use cases below.
25+
- requestAnimationFrame: Aimed at creating scripted animation effects. It can support rich
26+
interaction models but it is difficult to make smooth or responsive. This expressiveness of
27+
Javascript coupled with access to all input methods, application state and dom makes this API
28+
capable of building rich interactive effects. However these can only run on main thread alongside
29+
all other scripts<sup>[2](#footnote2)</sup> which severely hampers their responsiveness and
30+
smoothness. Chrome [studies](https://tdresser.github.io/input-latency-deep-reports/) have shown that script is the main culprit to user responsiveness issues.
31+
32+
Animation Worklet aims to help bridge the gap between these two.
33+
34+
## Animation Worklet Vision
35+
36+
[Animation Worklet][specification] aims to rectify this shortcomings by enabling animations that can
37+
be:
38+
39+
* rich (imperative, stateful)
40+
* fast-by-default (isolated from main thread)
41+
* respond to rich input e.g., touch, gesture, scroll.
42+
43+
Animation Worklet is a primitive in the [extensible web](https://extensiblewebmanifesto.org/) spirit.
44+
It exposes browser's fast path to applications in a way that it was never before and reduces browser
45+
magic.
46+
47+
Examples of rich interactive effects that are (or will be made) possible with Animation Worklet:
48+
49+
50+
* Scroll driven effects:
51+
* [Hidey-bar](https://googlechromelabs.github.io/houdini-samples/animation-worklet/twitter-header/): animation depends on both time and scroll input.
52+
* [Parallax](https://googlechromelabs.github.io/houdini-samples/animation-worklet/parallax-scrolling/): Simplest scroll-drive effect.
53+
* [Custom paginated slider](http://aw-playground.glitch.me/amp-scroller.html).
54+
* Pull-to-refresh: animation depends on both touch and time inputs.
55+
* Custom scrollbars.
56+
* [More examples](https://github.com/w3c/css-houdini-drafts/blob/master/scroll-customization-api/UseCases.md) of scroll-driven effects.
57+
* Gesture driven effects:
58+
* [Image manipulator](https://github.com/w3c/csswg-drafts/issues/2493#issuecomment-422153926) that scales, rotates etc.
59+
* Swipe to dismiss.
60+
* Drag-N-Drop.
61+
* Tiled panning e.g., Google maps.
62+
* Stateful script driven effects:
63+
* [Spring-based emulations](https://googlechromelabs.github.io/houdini-samples/animation-worklet/spring-timing/).
64+
* [Spring-Sticky effect](http://googlechromelabs.github.io/houdini-samples/animation-worklet/spring-sticky/).
65+
* Touch-driven physical environments.
66+
* [Expando](http://googlechromelabs.github.io/houdini-samples/animation-worklet/expando/): Procedural animations with multiple elements.
67+
* Animated scroll offsets:
68+
* Having multiple scrollers scroll in sync e.g. diff viewer keeping old/new in sync when you
69+
scroll either ([demo](https://googlechromelabs.github.io/houdini-samples/animation-worklet/sync-scroller/))
70+
* Custom smooth scroll animations (e.g., physic based fling curves)
71+
72+
73+
## First Principle - Richness
74+
75+
Animation Worklet enables developers to create custom animations by providing an `animate` function
76+
that runs inside animation worklet global scope. The animation logic can take advantage of the full
77+
expressive power of JavaScript, maintain local state, modify and coordinated across many elements.
78+
This new extension point in browser animation system enables richer effects that go well beyond what
79+
can be achieved today with Web Animations and closer to what is possible with requestAnimationFrame.
80+
81+
**Further explorations in this direction:** Allow richer access to scrolling machinery (e.g., scroll
82+
customization), custom paint worklets, and outputs beyond existing KeyframeEffect interface.
83+
84+
85+
## Second Principle - Performance
86+
87+
Animation Worklet is designed to be thread agnostic. In particular, it can run off main thread
88+
keeping its performance isolated from main thread (also reducing main thread load).
89+
90+
Animation Worklet API encourages the developers to isolate their critical UI work inside limited
91+
worklet scope with well-specified input and output. This allows user-agent to make much better
92+
scheduling decision about this work and in particular, be much better at maintaining a strict
93+
frame-budget to successfully run these animations on its fast path. Presently the above performance
94+
guarantees are only accessible to a limited set of declarative time-based effects.
95+
96+
**Further explorations in this direction**: Introduce more sophisticated per-animation scheduling
97+
where a slow animation may run at slower frame-rate without affecting other well-behaved animations,
98+
experiment with translating animation code to native code or even GL shaders moving the computation
99+
to GPU for even stronger performance guarantees!
100+
101+
102+
## Third Principle - Interactivity
103+
104+
Animation Worklet is designed to enable support for animations whose input goes beyond just time, a
105+
single-dimensional variable.
106+
107+
Web animation timing model is stateless and driven by a single dimensional variable, time.
108+
109+
Although this model works well for declarative time-based animation, it falls short when it comes to
110+
interactive input-driven effects that are inherently stateful. While it is possible to map simple
111+
forms of input (e.g., [single dimensional scroll](https://wicg.github.io/scroll-animations/#intro))
112+
into time, it is much more difficult (almost impossible) to do so for multi-dimensional stateful
113+
input such as multi-touch and gesture input.
114+
115+
Animation Worklet has the necessary expressive power and richness to easily accommodate the full
116+
richness of multi-dimensional input such as touch, gesture, scroll etc. For example it is trivial to
117+
react to scroll phase change, pointer state change, addition/removal of new pointer or state,
118+
calculate pointer velocity, acceleration and other computed values inside an animation worklet.
119+
120+
**Further explorations in this direction:** Expose pointer and gesture as input to animation
121+
([current proposal](https://github.com/w3c/csswg-drafts/issues/2493#issuecomment-422109535))
122+
123+
124+
# Appendix
125+
126+
127+
## Footnotes
128+
129+
* <a name="footnote1">1</a>: If authors limit themselves to cheap-to-update properties. In Chrome
130+
these are composited properties e.g., transform, opacity, filter but other engines may have a
131+
slightly difference subset.
132+
133+
134+
[performance]: https://paul.kinlan.me/what-news-readers-want/
135+
[rails]: https://developers.google.com/web/fundamentals/performance/rail#goals-and-guidelines
136+
[specification]: https://github.com/w3c/css-houdini-drafts/tree/master/css-animationworklet

css-animationworklet/status.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Implementation Status
2+
3+
## Chrome
4+
5+
This is a rough sketch of how Chrome plans to deliver Animation Worklet features:
6+
7+
1. Animation Worktlet Prototype (done): scripted custom animation, single effect, only fast
8+
properties, off-thread.
9+
2. Animation Worktlet [Origin Trial][ot-blogpost] (in progress, [signup][ot-signup]): good
10+
performance, scroll input (ScrollTimeline), basic web-animation controls (play/cancel).
11+
3. Animation Worktlet MVP (in development): animate all properties (slow path ones running in sync
12+
with main thread), multiple effects (i.e., GroupEffect), full web-animation integration.
13+
4. Animation Worktlet V2 (future): touch/gesture input, multiple inputs in single animation,
14+
sophisticated scheduling, other outputs.
15+
16+
[ot-blogpost]: https://developers.google.com/web/updates/2018/10/animation-worklet
17+
[ot-signup]:https://docs.google.com/forms/d/e/1FAIpQLSfO0_ptFl8r8G0UFhT0xhV17eabG-erUWBDiKSRDTqEZ_9ULQ/viewform
18+

0 commit comments

Comments
 (0)