Re: [whatwg] Canvas in Workers

on ImageBitmap should zero size canvases just work (and create a 0 sized
ImageBitmap)?

My personal preference is for APIs that just work with zero sizes so I
don't have to write lots of special cases for handling zero.

For example [1,2,3].slice(0,0) returns []. It doesn't throw.
"abc".substring(0,0) returns "" it doesn't throw. fillRect(x, y, 0, 0)
doesn't throw. etc...

It just makes life a lot easier



On Tue, Nov 20, 2012 at 3:33 AM, Elliott Sprehn <esprehn@chromium.org>wrote:

>
> 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 Friday, 30 November 2012 08:11:34 UTC