Re: [whatwg] Canvas in Workers

On Mon, Nov 19, 2012 at 12:26 AM, Gregg Tavares (社用) <gman@google.com>wrote:

> Sorry if this is clear in the specs but can you explain how sizing the
> canvas works?
>
>
>    // main.html
>    <canvas></canvas>
>    <script>
>     var canvas = document.getElementsByTagName('canvas')[0];
>     var worker = new Worker('clock.js');
>     var proxy = canvas.transferControlToProxy());
>     worker.postMessage(proxy, [proxy]);
>
>     setTimeout(function() {
>         canvas.width = 200;   // does this work? What happens?
>

You resize the output surface that the image coming from the worker will be
drawn into. This is different than changing the buffer used for drawing.

    }, 4000);
>    </script>
>
>    // clock.js worker
>    onmessage = function (event) {
>      var context = new CanvasRenderingContext2d();
>      event.data.setContext(context);
>      setInterval(function () {
>        context.width = 400;  // Can I do this? What happens when I do?
>

You resize the buffer that's inside of the worker.

- E

Received on Monday, 19 November 2012 20:45:15 UTC