| # forma. The parallel CPU vector renderer | |
| *forma* 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 forma | |
| * read the forma [API reference](https://fuchsia-docs.firebaseapp.com/rust/forma/) | |
| * check out the [Carnelian clockface example](https://fuchsia.googlesource.com/fuchsia/+/HEAD/src/lib/ui/carnelian/examples/clockface.rs) | |
| ## Example | |
| ```rust | |
| use forma::{Buffer, BufferBuilder, Composition, LinearLayout, Fill, Point, Style}; | |
| fn main() { | |
| const WIDTH: usize = 256; | |
| const HEIGHT: usize = 256; | |
| let mut buffer = vec![255u8; WIDTH * HEIGHT * 4]; | |
| let mut layout = LinearLayout::new(WIDTH, WIDTH * 4); | |
| 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(); | |
| 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(&mut BufferBuilder::new(&mut buffer, &mut layout).build(), [1.0, 1.0, 1.0, 1.0], None); | |
| } | |
| ``` |