[whatwg] Canvas in Workers

Elliott Sprehn esprehn at chromium.org
Mon Nov 19 10:33:40 PST 2012


On Mon, Nov 19, 2012 at 12:26 AM, Gregg Tavares (社用) <gman at 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



More information about the whatwg mailing list