Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Workers and Canvas

Are web workers allowed to access a canvas object?

like image 773
l.thee.a Avatar asked Dec 08 '09 05:12

l.thee.a


People also ask

What is an Offscreen canvas?

The OffscreenCanvas interface provides a canvas that can be rendered off screen. It is available in both the window and worker contexts. OffscreenCanvas is a transferable object. Note: This feature is available in Web Workers.

Can I use offscreen canvas?

The OffscreenCanvas allows to create a canvas that can be rendered off screen. It can also be used in web workers.

What is Web canvas?

<canvas> is an HTML element which can be used to draw graphics via scripting (usually JavaScript). This can, for instance, be used to draw graphs, combine photos, or create simple animations.


1 Answers

Small update, as the question is now more than half a year old:

In Chrome/Chromium 6 you can now send a canvas' ImageData object to a web worker, let the web worker make changes to the object and then write it back to the canvas using putImageData(..).

Google's Chromabrush does it this way, the source-code can be found here:

  • Main thread
  • Web worker

Update:

The latest development snapshots of Opera (10.70) and Firefox (4.0b1) also support passing ImageData objects to a web worker.

Update 2017:

Actual links from Github (easier to find needed files from Chromabrush):

  • Sending imageData to worker
  • Receiving data
like image 162
tsauerwein Avatar answered Sep 22 '22 16:09

tsauerwein