@@ -29,6 +29,9 @@ urlPrefix: https://heycam.github.io/webidl/; type: dfn;
29
29
url: es-invoking-callback-functions; text: Invoke
30
30
urlPrefix: https://html.spec.whatwg.org/#; type: dfn;
31
31
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
32
35
urlPrefix: https://www.w3.org/TR/css3-transitions/#; type: dfn;
33
36
text: animatable properties
34
37
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
271
274
- An <dfn>animator current time</dfn> which is the corresponding <a>worklet animation</a> 's current
272
275
time.
273
276
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.
275
282
276
283
277
284
Creating an Animator Instance {#creating-animator-instance}
278
285
-----------------------------------------------------------
279
286
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}} .
285
288
286
289
Each {{AnimationWorkletGlobalScope}} has an <dfn>animator instance set</dfn> . The set is populated
287
290
when the user agent constructs a new <a>animator instance</a> in the {{AnimationWorkletGlobalScope}}
288
291
scope. Each <a>animator instance</a> corresponds to a worklet animation in the document scope.
289
292
290
293
<div algorithm="create-animator">
291
294
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:
294
297
295
298
1. Let the |definition| be the result of looking up |name| on the |workletGlobalScope|'s
296
299
<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
301
304
302
305
3. Let |timelineList| be a new <a>list</a> with |timeline| added to it.
303
306
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|] ).
305
312
306
313
If <a>Construct</a> throws an exception, abort the following steps.
307
314
308
- 5. Set the following on |animatorInstance| with:
315
+
316
+ 7. Set the following on |animatorInstance| with:
309
317
- <a>animator name</a> being |name|
310
318
- <a>animation requested flag</a> being <a>frame-current</a>
311
319
- <a>animator current time</a> being unresolved
312
320
- <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|
314
324
315
- 6 . Add |animatorInstance| to |workletGlobalScope|'s <a>animator instance set</a> .
325
+ 8 . Add |animatorInstance| to |workletGlobalScope|'s <a>animator instance set</a> .
316
326
317
327
</div>
318
328
@@ -345,12 +355,11 @@ instance set</a>. For each such |instance| the user agent <em>must</em> perform
345
355
belonging to the |instance| will not be visible within the visual viewport of the current
346
356
frame the user agent <em> may</em> abort all the following steps.
347
357
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.
350
360
351
361
4. Let |animateFunction| be |definition|'s <a>animate function</a> .
352
362
353
-
354
363
5. Let |currentTime| be <a>animator current time</a> of |instance|.
355
364
356
365
6. Let |effect| be <a>animator effect</a> of |instance|.
@@ -370,7 +379,63 @@ Removing an Animator Instance {#removing-animator}
370
379
To <dfn>remove an animator instance</dfn> given |instance| and |workletGlobalScope| the user agent
371
380
<em> must</em> run the following steps:
372
381
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.
374
439
375
440
</div>
376
441
@@ -384,7 +449,7 @@ Each <a>animator instance</a> has an associated <dfn>animation requested flag</d
384
449
either <dfn>frame-requested</dfn> or <dfn>frame-current</dfn> . It is initially set to
385
450
<a>frame-current</a> . Different circumstances can cause the <a>animation requested flag</a> to be
386
451
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>
388
453
- Changes in the <a>current time</a> of the animator's corresponding <a>Worklet Animation</a>
389
454
390
455
[[#running-animators]] resets the <a>animation requested flag</a> on animators to
@@ -410,7 +475,7 @@ animation's output.
410
475
411
476
<a>Worklet animation</a> has the following properties in addition to the {{Animation}} interface:
412
477
- 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
414
479
constructing a new animator instance.
415
480
416
481
<figure>
@@ -467,7 +532,7 @@ Creates a new {{WorkletAnimation}} object using the following procedure.
467
532
4. Run the procedure to <a>set the target effect of an animation</a> on |workletAnimation|
468
533
passing |effect| as the new effect.
469
534
470
- 5. Let |serializedOptions| be the result of {{StructuredSerializeWithTransfer( options)}} .
535
+ 5. Let |serializedOptions| be the result of <a>StructuredSerialize</a> (| options|) .
471
536
Rethrow any exceptions.
472
537
473
538
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>, <
527
592
|workletAnimation|.
528
593
3. <a>Queue a task</a> on |workletGlobalScope| to run the procedure to <a>create a new animator
529
594
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.
535
600
4. If the procedure was successful, set the resulting <a>animator instance</a> as corresponding to
536
601
|workletAnimation|.
537
602
0 commit comments