W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

Re: exposing CANVAS or something like it to Web Workers

From: Charles Pritchard <chuck@jumis.com>
Date: Mon, 14 May 2012 19:00:57 -0700
Message-ID: <4FB1B8D9.3030400@jumis.com>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: "Gregg Tavares (勤)" <gman@google.com>, public-webapps@w3.org
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:52 GMT