Re: exposing CANVAS or something like it to Web Workers

On Mon, May 14, 2012 at 5:12 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 5/14/12 8:03 PM, Gregg Tavares (勤) wrote:
>
>> var canvasSurface = new CanvasSurface();
>> var ctx = canvasSurface.getContext("2d")**;
>> var pic = new Picture;
>> pic.src = "http://someplace.com/**someimage.jpg<http://someplace.com/someimage.jpg>
>> ";
>> pic.onload = function() {
>>    ctx.drawImage(pic, 0, );
>> }
>>
>> Let's assume you can instantiate these things in either the page or a
>> worker. Nether can be transfered.
>>
>> Would that work? What problems would that have?
>>
>
> Two things that come to mind immediately:
>
> 1)  Various canvas 2d context methods depend on the styles of the canvas
> to define how they actually behave.  Clearly this would need some sort of
> changes for Workers anyway; the question is what those changes would need
> to be.
>

Which methods are these?



>
> 2)  How (or maybe whether) this should work with pic.src = "
> http://someplace.com/**someimage.svg <http://someplace.com/someimage.svg>"
> is an interesting question.
>
> 3)  This leaves open the question of how to get data from the worker back
> to the main thread to paint there.
>

I feel that's a somewhat orthogonal issue to getting a Canvas or
CanvasSurface in a worker. At least for the WebGL case, WebGL already
defines ways to share data safely between contexts so that use case is
already covered.

For a 2d context I can certainly imagine lots of ways. Some fast, some slow

slow) pass the result of toDataURL back

slow) pass an ImageData.data back (transfer of ownership)

fast) some how use a CanvasSurface as the source of a video tag

maybe there are some other ideas? But, even if we didn't resolve this, it's
still massively useful, at least for WebGL, to be able to instantiate a
WebGL context in a worker.





>
> #1 is an issue with any proposal that puts a 2d context in a worker.
>
> #2 is only an issue if we do the image loads in workers somehow; if we
> wanted to just rasterize the SVG and pass the resulting data to the worker
> there would be no problem, obviously.
>
> For #3, being able to transfer a canvas context from the page to a worker
> but leave it painting to the canvas may still be desirable...
>
> -Boris
>
>

Received on Tuesday, 15 May 2012 00:56:14 UTC