Skip to Content
valo
Reference

DisplayListBuilder

Record drawing commands without touching the GPU.

DisplayListBuilder records drawing commands into a display list. Recording is CPU-only: bounds, clips, and layer extents are resolved here so rendering does not rediscover them.

use valo::{Color, DisplayListBuilder, Paint, Rect};

let paint = Paint::from_color(Color::rgb(0.78, 1.0, 0.24));
let mut builder = DisplayListBuilder::new();
builder.save();
builder.translate(160.0, 110.0);
builder.rotate(0.2);
builder.draw_rrect(Rect::new(-100.0, -55.0, 200.0, 110.0), 20.0, &paint);
builder.restore();
let display_list = builder.build();
const builder = new DisplayListBuilder();
builder.save();
builder.translate(160, 110);
builder.rotate(0.2);
builder.drawRoundedRect(-100, -55, 200, 110, new Float32Array([20]), paint);
builder.restore();
const list = builder.build();

The scene is JavaScript. Change the rotation, corner radii, or circle radius and it redraws. This widget already owns the builder for the frame.

scene.jsplayground
loading editor
liveacquiring device

build() finishes the recording. In Rust it consumes the builder. In JavaScript every mutating method throws after build().

Transforms, clips, and layers

Save and restore around local transforms, clips, and layers. An unmatched restore is a debug assertion in Rust and is ignored in release.

  • Clips may intersect the current region or subtract from it (ClipOp.Difference).
  • Save layers group several draws before applying opacity, blending, or a filter.
  • Backdrop blur is a save layer that opens already filled with a Gaussian of the pixels beneath it (save_layer_backdrop, JavaScript backdropBlur). See Backdrop blur.

Coordinates are local pixels with y downward until a transform says otherwise.

What you can record

Rects, rounded rects, circles, paths, images, nested display lists, and paragraphs. JavaScript drawCircle and clipRoundedRect match the C and Rust circle and rounded-clip calls. See Paint for style and Path for geometry.

Two more are Rust only for now:

  • The whole clip with draw_paint, as Flutter's Canvas.drawPaint: the paint covers everything the clip lets through, so a blend such as Clear or DstIn reaches past any shape, and a save layer around it covers its own clip. The paint always fills, and its mask blur is ignored.
  • A shadow with draw_shadow, as Flutter's Canvas.drawShadow: an occluder's path, colour, elevation and the view's device pixel ratio. It is resolved when it is drawn, as Impeller draws it: the path moved down by device_pixel_ratio × elevation, filled with a lighter tone of the colour under a blur as wide as that height in pixels, whatever scale the list is drawn at.
builder.draw_paint(&Paint::from_color(Color::rgb(0.98, 0.98, 0.98)));
builder.draw_shadow(&card, FillRule::NonZero, Color::BLACK, 4.0, false, 2.0);

Next: DisplayList.

On this page