Skip to Content
valo
Reference

Context

Submit a display list to a host-owned GPU device.

Context is Valo on one GPU device. Create it from a device and queue your application already owns. It holds pipelines, atlases, uploaded images, and reusable targets — not windows, files, or application content. Reuse it across frames.

let mut context = valo::Context::new(device, queue);
if let Some(frame) = surface.acquire() {
    context.render(&display_list, &frame.target(Some(Color::BLACK)));
    context.present(frame);
}

Pixels can also be read back without a window. request_pixels draws a list into pixels of any size and asks the GPU for them; the request is a future of straight-alpha RGBA8:

let list = Arc::new(display_list);
let request = context.request_pixels(&list, [320, 220], Some(Color::BLACK));
// Natively, call `context.check_requests()` while the request is out;
// on the web the browser answers on its own.
let pixels = request.await?.into_bytes();

render submits one command buffer and returns frame statistics. request_pixels draws in tiles past the device's largest texture, and export_pixels does the same one tile per step, for a progress bar.

A list can also become an Image to draw or sample: display_list_to_image(&list, size).

JavaScript: Device and Renderer

The same GPU owner is split across two objects. createDevice() is the shared Context. device.attach(canvas) is one canvas's swapchain and backing:

await initializeValo();
const device = await createDevice();
const renderer = device.attach(canvas);
const stats = renderer.render(list, true, 0.04, 0.04, 0.05, 1);

The true argument clears to the supplied colour. Pass false to draw incrementally over preserved pixels. Attach several canvases to one device so they share atlases — see One device, many canvases.

The live canvases on Paint and DisplayListBuilder already go through createDevice and attach. Change those scenes to see a render on this device.

Runtime effects

prepare_runtime_effect(&effect, format) compiles a runtime effect's pipelines before its first draw, so it does not stall the frame it first appears in. It warms the common case only: the effect filling or covering a shape at the default blend, with its overrides at their defaults, into targets of format.

Options

  • set_text_tiers — bitmap, SDF, or outlines by font size. Defaults suit normal use.
  • set_hide_missing_glyphs — blank instead of tofu for unresolved characters.
  • set_text_raster_hold / set_raster_hold — reuse existing rasters during a zoom gesture; clear them when the view settles.

memory_report() estimates retained GPU memory. In JavaScript, call device.memoryReport().

Next: Surface.

On this page