Skip to main content

Module offscreen

Module offscreen 

Source
Expand description

The painting threads behind the offscreen exports (docs/canvas.md “Exporting”).

Toolkit::render_bitmap answers with an event, so a toolkit whose 2-D API can draw into a memory surface from any thread paints there and posts the answer back to the UI thread. The pool is shared by every toolkit in the process: a few threads, one short of the cores and never more than four, so a screenful of requests cannot starve the UI thread or the app’s own work. Jobs run in the order they were queued.

Not built for the web: a browser’s createImageBitmap is already asynchronous, and wasm32-unknown-unknown has no threads to spawn.

Functions§

spawn
Run job on a painting thread, or inline when none could be started. A panic inside job is contained (crate::ffi_guard::contain) so one bad replay cannot take the thread, and with it every later export, down; the job itself should answer its request in that case, which is why toolkits wrap the paint and not the post.