tree: 2d6b75cc0f7b3ae0b24541656bc888611accac01 [path history] [tgz]
  1. BUILD.gn
  2. README.md
  3. src/
src/graphics/lib/compute/mold/README.md

mold. The parallel CPU vector renderer

mold is a highly efficient vector content renderer and composer that makes use of all processor cores and vector units.

It currently supports:

  • non-zero or even-odd paths
  • lines, quadratic and cubic B├ęzier curves and their rational counterparts
  • RGB solid fills with opacity
  • correct gamma blending
  • efficient per-path transforms

The renderer achieves its performance through a few principles that are present throughout the code-base:

  • tiled renderer can render simple tiles efficiently
  • long expensive buffer operations are parallelized on multiple threads
  • partial results are stored in temporary buffers and the whole renderer runs in a multi-stage pipeline
  • tight loops are as branchless as possible and are easily auto-vectorized
  • high-quality efficient linear-to-sRGB approximation

Getting started with mold

Example

use mold::{Buffer, Composition, Fill, Point, Style};

fn main() {
    const WIDTH: usize = 256;
    const HEIGHT: usize = 256;

    let mut buffer = vec![[255u8; 4]; WIDTH * HEIGHT];
    let mut composition = Composition::new();

    let mut triangle_path = Path::new();
    triangle_path.line(
        Point::new(100.0, 100.0),
        Point::new(150.0, 200.0),
    );
    triangle_path.line(
        Point::new(150.0, 200.0),
        Point::new(200.0, 100.0),
    );
    triangle_path.line(
        Point::new(200.0, 100.0),
        Point::new(100.0, 100.0),
    );

    let layer_id = composition.create_layer().expect("layer limit reached");

    composition.insert_in_layer(layer_id, &triangle_path).set_style(Style {
        fill: Fill::Solid([1.0, 0.0, 0.0, 1.0]),
        ..Default::default()
    });

    composition.render(
        Buffer {
            buffer: &mut buffer,
            width: WIDTH,
            ..Default::default()
        },
        [1.0, 1.0, 1.0, 1.0],
        None,
    );

}