Re: [w3ctag/design-reviews] OffscreenCanvas new commit() and DedicatedWorker.requestAnimationFrame (#288)

So where is the up to date spec? The spec linked above says

> ## canvas . transferControlToOffscreen ()
> Returns a newly created OffscreenCanvas object that uses the canvas element as a placeholder. Once the canvas element has become a placeholder for an OffscreenCanvas object, its intrinsic size can no longer be changed, and it cannot have a rendering context. **The content of the placeholder canvas is updated by calling the commit() method of the OffscreenCanvas object's rendering context**.

But talking to others (and in testing) this is no longer the case. For an `OffscreenCanvas` the contents of the placeholder is updated automatically after the current event exits just like a normal canvas. In other words, just like a normal canvas if you call `gl.clear` or `gl.drawXXX` then a task is queued to copy/swap the drawing buffer into the canvas.  `commit` is only needed for spin loops 

Example: This renders to the canvas. no call to `commit` needed

in worker

```
self.onmessage = function(evt) {
  const canvas = evt.data.canvas;
  const gl = canvas.getContext("webgl");
  gl.clearColor(0,1,0,1);
  gl.clear(gl.COLOR_BUFFER_BIT);
};
```

In main thread

```
  const canvas = document.querySelector("canvas");
  const offscreen = canvas.transferControlToOffscreen();
  worker.postMessage({canvas: offscreen}, [offscreen]);
```

https://jsfiddle.net/greggman/w3t0gmvz/

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3ctag/design-reviews/issues/288#issuecomment-402913494

Received on Friday, 6 July 2018 03:16:36 UTC