[css-houdini-drafts] [css-animationworklet] Allow sending data to animators in worklet from main thread (#869)

majido has just created a new issue for https://github.com/w3c/css-houdini-drafts:

== [css-animationworklet] Allow sending data to animators in worklet from main thread ==

Many useful effects running inside animation worklet may need to know about specific values from main thread, e.g., size of window or bounding client rects of various objects.


We allow such data to be sent when worklet animation (via `options` property) is being constructed.  However this is limited since these values may change during the lifetime of the animation (e.g., window resize). Currently in these cases one has to cancel the current animation and create a new one. This does not work well and can cause jusmp if the animation has internal state.

A simple  logical extension is to allow options to be updated. Here is a proposal that achieves this:

In Animation Worklet context:

```js
registerAnimator('abc', class {
  constructor(options) {
    this.options = options;
  }
  optionsChanged(options) {
    this.options = options;
    // TODO figure out if this should also implicitly invalidated the animation such that animate() is always called or alternatively we have a way to request one frame!
  }
  animate(time, effect) {
    // uses options.height as needed
  }
});
```

In document context:
```js
let options = { height: top.innerHeight };
const animation = new WorkletAnimation('abc', keyframe, options);
animation.play()

window.addEventListener('resize', e => {
  options.height = top.innerHeight;
  animation.updateOptions(options); 
});
```

Why method instead of a property? 
This means we don't need to keep the options as a live object. This is similar to other [Web-animation APIs](https://drafts.csswg.org/web-animations-1/#dom-keyframeeffect-setkeyframes).



Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/869 using your GitHub account

Received on Wednesday, 27 March 2019 16:05:26 UTC