Re: exposing CANVAS or something like it to Web Workers

On 5/14/2012 6:07 PM, Boris Zbarsky wrote:
> On 5/14/12 8:55 PM, Gregg Tavares (勤) wrote:
>>     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?
>
> Anything involving setting color (e.g. the strokeStyle setter, the 
> fillStyle setter), due to "currentColor".  Anything involving text 
> because font styles come from the element or document.
>
> Those are the ones that come to mind offhand, but I haven't looked at 
> the various recent additions to the 2d context closely.

What would web fonts do in this situation, in Mozilla? If I've confirmed 
that a font is loaded in the main thread, would it be available to a 
worker for use in rendering?

Some implementations of Canvas font methods have been buggy, but 
dropping fillText/strokeText altogether would be a loss and may look 
strange in the specs.
I've seen font not working correctly with other canvas state variables 
in WebKit + Chrome; so it's not as though font is fully supported in the 
main thread, currently.

It may be easier to postpone Image / Picture semantics in workers. I 
think patterns could still be salvaged from createPattern.
It sounds like there are practical issues in current implementations.

When authoring,
With a picture, I can still xhr request it in the worker, then I send it 
to the main thread, and load it in the main thread, then send it back to 
the worker.
As an author, if I'm loading images I expect them to be a normal part of 
the page's load time and responsiveness.... I can still off-load my 
js-heavy work onto workers.

In Canvas 2d anyway, I can easily get by without picture in workers: (a 
= new Picture()).src = ....; a.onload { ctx.drawImage(a,0,0); };  if I 
can use fillRect with pattern.
Otherwise, I'd have to do the extra steps of pushing pixel arrays back 
and forth.

All of the extra work is still worth it to get work done in workers, in 
cases where this level of work is needed. It's just a few extra lines of 
JS code (every time).

-Charles

Received on Tuesday, 15 May 2012 02:01:22 UTC