Skip to content

Commit 65aa232

Browse files
majidostephenmcgruer
authored andcommitted
Add details of migration (w3c#73)
- Introduce state and its serialization concept - Fix many link issues - Animation now has a timeline and list of attached timelines
1 parent 932a7e4 commit 65aa232

File tree

2 files changed

+267
-107
lines changed

2 files changed

+267
-107
lines changed

index.bs

+89-24
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ urlPrefix: https://heycam.github.io/webidl/; type: dfn;
2929
url: es-invoking-callback-functions; text: Invoke
3030
urlPrefix: https://html.spec.whatwg.org/#; type: dfn;
3131
url: run-the-animation-frame-callbacks; text: running the animation frame callbacks
32+
urlPrefix: http://w3c.github.io/html/infrastructure.html#; type: dfn;
33+
text: structuredserialize
34+
text: structureddeserialize
3235
urlPrefix: https://www.w3.org/TR/css3-transitions/#; type: dfn;
3336
text: animatable properties
3437
urlPrefix: https://w3c.github.io/web-animations/#; type: dfn;
@@ -271,26 +274,26 @@ and owns the instance specific state such as animation effect and timelines. It
271274
- An <dfn>animator current time</dfn> which is the corresponding <a>worklet animation</a>'s current
272275
time.
273276

274-
- An <dfn>animator timelines list</dfn> which is <a>list</a> of its attached <a>timelines</a>.
277+
- An <dfn>animator timeline</dfn> which is a <a>timeline</a>.
278+
279+
- An <dfn>animator attached timelines</dfn> which is <a>list</a> of attached <a>timelines</a>
280+
281+
- An <dfn>animator serialized options</dfn> which is a serializable object.
275282

276283

277284
Creating an Animator Instance {#creating-animator-instance}
278285
-----------------------------------------------------------
279286

280-
Each <a>animator instance</a> lives in an {{AnimationWorkletGlobalScope}}. The <a>animator
281-
instance</a> cannot be disposed arbitrarily (e.g., in the middle of running animation as it may
282-
contain the scripted animation state.
283-
284-
Issue: This is no longer true as we provide destroy callback.
287+
Each <a>animator instance</a> lives in an {{AnimationWorkletGlobalScope}}.
285288

286289
Each {{AnimationWorkletGlobalScope}} has an <dfn>animator instance set</dfn>. The set is populated
287290
when the user agent constructs a new <a>animator instance</a> in the {{AnimationWorkletGlobalScope}}
288291
scope. Each <a>animator instance</a> corresponds to a worklet animation in the document scope.
289292

290293
<div algorithm="create-animator">
291294

292-
To <dfn>create a new animator instance</dfn> given a |name|, |timeline|, |effect|, |options|, and
293-
|workletGlobalScope|, the user agent <em>must</em> run the following steps:
295+
To <dfn>create a new animator instance</dfn> given a |name|, |timeline|, |effect|, |serializedOptions|,
296+
|serializedState|, and |workletGlobalScope|, the user agent <em>must</em> run the following steps:
294297

295298
1. Let the |definition| be the result of looking up |name| on the |workletGlobalScope|'s
296299
<a>animator name to animator definition map</a>.
@@ -301,18 +304,25 @@ To <dfn>create a new animator instance</dfn> given a |name|, |timeline|, |effect
301304

302305
3. Let |timelineList| be a new <a>list</a> with |timeline| added to it.
303306

304-
4. Let |animatorInstance| be the result of <a>Construct</a>(|animatorCtor|, [|options|]).
307+
4. Let |options| be <a>StructuredDeserialize</a>(|serializedOptions|).
308+
309+
5. Let |state| be <a>StructuredDeserialize</a>(|serializedState|).
310+
311+
6. Let |animatorInstance| be the result of <a>Construct</a>(|animatorCtor|, [|options|, |state|]).
305312

306313
If <a>Construct</a> throws an exception, abort the following steps.
307314

308-
5. Set the following on |animatorInstance| with:
315+
316+
7. Set the following on |animatorInstance| with:
309317
- <a>animator name</a> being |name|
310318
- <a>animation requested flag</a> being <a>frame-current</a>
311319
- <a>animator current time</a> being unresolved
312320
- <a>animator effect</a> being |effect|
313-
- <a>animator timelines list</a> being |timelineList|
321+
- <a>animator timeline</a> being |timeline|
322+
- <a>animator attached timelines</a> being |timelineList|
323+
- <a>animator serialized options</a> being |options|
314324

315-
6. Add |animatorInstance| to |workletGlobalScope|'s <a>animator instance set</a>.
325+
8. Add |animatorInstance| to |workletGlobalScope|'s <a>animator instance set</a>.
316326

317327
</div>
318328

@@ -345,12 +355,11 @@ instance set</a>. For each such |instance| the user agent <em>must</em> perform
345355
belonging to the |instance| will not be visible within the visual viewport of the current
346356
frame the user agent <em>may</em> abort all the following steps.
347357

348-
Issue: Consider giving user agents permission to skip running animator instances to
349-
throttle slow animators.
358+
Issue: Consider giving user agents permission to skip running animator instances to
359+
throttle slow animators.
350360

351361
4. Let |animateFunction| be |definition|'s <a>animate function</a>.
352362

353-
354363
5. Let |currentTime| be <a>animator current time</a> of |instance|.
355364

356365
6. Let |effect| be <a>animator effect</a> of |instance|.
@@ -370,7 +379,63 @@ Removing an Animator Instance {#removing-animator}
370379
To <dfn>remove an animator instance</dfn> given |instance| and |workletGlobalScope| the user agent
371380
<em>must</em> run the following steps:
372381

373-
1. Remove |animatorInstance| from |workletGlobalScope|'s <a>animator instance set</a>.
382+
1. Remove |instance| from |workletGlobalScope|'s <a>animator instance set</a>.
383+
384+
</div>
385+
386+
Migrating an Animator Instance {#migrating-animator}
387+
-----------------------------------------
388+
User agents are responsible for assigning an animator to a worklet global scopes of which many can
389+
exist across different threads or processes. In order to give the most flexibility to user agents in
390+
this respect, we allow migration of an animator while it is running.
391+
392+
The section defines a migration process such that any author-defined effect that depends on internal
393+
state can maintain its state across such migrations. The basic mechanism for achieving this is to
394+
serialize the state and later restore it.
395+
396+
<div algorithm="migrate-animator">
397+
398+
When user agents wants to <dfn>migrate an animator instance</dfn> from one worklet global scope
399+
to another given |instance|, |sourceWorkletGlobalScope|, |destinationWorkletGlobalScope|,
400+
it <em>must</em> run the following steps :
401+
402+
1. Let |serializedState| be undefined.
403+
404+
2. <a>Queue a task</a> on |sourceWorkletGlobalScope| to run the following steps:
405+
406+
1. Let |animatorName| be |instance|'s <a>animator name</a>
407+
408+
2. Let the |definition| be the result of looking up |animatorName| on the
409+
|sourceWorkletGlobalScope|'s <a>animator name to animator definition map</a>.
410+
411+
If |definition| does not exist then abort the following steps.
412+
413+
4. Let |prototype| be the result of <a>Get</a>(|animatorCtor|, "prototype").
414+
415+
5. Let |onDestroyFunction| be the result of <a>Get</a>(|prototype|, "onDestroy").
416+
417+
6. If the result of <a>IsCallable</a>(|onDestroyFunction|) is false then abort the following
418+
steps.
419+
420+
7. <a>Invoke</a> |onDestroyFunction| with |instance| as the <a>callback this value</a> and let
421+
|state| be the result of this invocation.
422+
423+
8. Set |serializedState| to be the result of <a>StructuredSerialize</a>(|state|).
424+
If any exception is throws, then abort the following steps.
425+
426+
9. <a>remove an animator instance</a> given |instance|, and |sourceWorkletGlobalScope|.
427+
428+
2. Wait for the above step complete.
429+
430+
3. <a>Queue a task</a> on |destinationWorkletGlobalScope| to run the following steps:
431+
432+
1. <a>create a new animator instance</a> given:
433+
- The |instance|'s <a>animator name</a> as name.
434+
- The |instance|'s <a>animator timeline</a> as timeline.
435+
- The |instance|'s <a>animator effect</a> as effect.
436+
- The |instance|'s <a>animator serialized options</a> as options.
437+
- The |serializedState| as state.
438+
- The |destinationWorkletGlobalScope| as workletGlobalScope.
374439

375440
</div>
376441

@@ -384,7 +449,7 @@ Each <a>animator instance</a> has an associated <dfn>animation requested flag</d
384449
either <dfn>frame-requested</dfn> or <dfn>frame-current</dfn>. It is initially set to
385450
<a>frame-current</a>. Different circumstances can cause the <a>animation requested flag</a> to be
386451
set to <a>frame-requested</a>. These include the following:
387-
- Changes in the <a>current time</a> of any <a>timeline</a> in the animator's <a>animator timelines list</a>
452+
- Changes in the <a>current time</a> of any <a>timeline</a> in the animator's <a>animator attached timelines</a>
388453
- Changes in the <a>current time</a> of the animator's corresponding <a>Worklet Animation</a>
389454

390455
[[#running-animators]] resets the <a>animation requested flag</a> on animators to
@@ -410,7 +475,7 @@ animation's output.
410475

411476
<a>Worklet animation</a> has the following properties in addition to the {{Animation}} interface:
412477
- an <dfn>animation animator name</dfn> which identifies it's <a>animator definition</a>.
413-
- a <dfn>serialized options</dfn> which is <a>serializable</a> object that is used when
478+
- a <dfn>serialized options</dfn> which is serializable object that is used when
414479
constructing a new animator instance.
415480

416481
<figure>
@@ -467,7 +532,7 @@ Creates a new {{WorkletAnimation}} object using the following procedure.
467532
4. Run the procedure to <a>set the target effect of an animation</a> on |workletAnimation|
468533
passing |effect| as the new effect.
469534

470-
5. Let |serializedOptions| be the result of {{StructuredSerializeWithTransfer(options)}}.
535+
5. Let |serializedOptions| be the result of <a>StructuredSerialize</a>(|options|).
471536
Rethrow any exceptions.
472537

473538
6. Set the <a>serialized options</a> of |workletAnimation| to |serializedOptions|.
@@ -527,11 +592,11 @@ When a given |workletAnimation|'s <a>play state</a> changes to <a>pending</a>, <
527592
|workletAnimation|.
528593
3. <a>Queue a task</a> on |workletGlobalScope| to run the procedure to <a>create a new animator
529594
instance</a>, passing:
530-
* The |workletAnimation|'s animation animator name as |name|.
531-
* The |workletAnimation|'s timeline as |timeline|.
532-
* The |workletAnimation|'s effect as |effect|.
533-
* The |workletAnimation|'s serialized options as |options|.
534-
* The |workletGlobalScope| as |workletGlobalScope|.
595+
* The |workletAnimation|'s <a>animation animator name</a> as name.
596+
* The |workletAnimation|'s <a>timeline</a> as timeline.
597+
* The |workletAnimation|'s <a>animation effect</a> as effect.
598+
* The |workletAnimation|'s <a>serialized options</a> as options.
599+
* The |workletGlobalScope| as workletGlobalScope.
535600
4. If the procedure was successful, set the resulting <a>animator instance</a> as corresponding to
536601
|workletAnimation|.
537602

0 commit comments

Comments
 (0)