blitz_paint/
lib.rs

1//! Paint a [`blitz_dom::BaseDocument`] by pushing [`anyrender`] drawing commands into
2//! an impl [`anyrender::PaintScene`].
3
4mod color;
5mod debug_overlay;
6mod gradient;
7mod kurbo_css;
8mod layers;
9mod render;
10mod sizing;
11mod text;
12
13use anyrender::PaintScene;
14use blitz_dom::BaseDocument;
15use layers::reset_layer_stats;
16use render::BlitzDomPainter;
17
18/// Paint a [`blitz_dom::BaseDocument`] by pushing drawing commands into
19/// an impl [`anyrender::PaintScene`].
20///
21/// This function assumes that the styles and layout in the [`BaseDocument`] are already
22/// resolved. Please ensure that this is the case before trying to paint.
23///
24/// The implementation of [`PaintScene`] is responsible for handling the commands that are pushed into it.
25/// Generally this will involve executing them to draw a rasterized image/texture. But in some cases it may choose to
26/// transform them to a vector format (e.g. SVG/PDF) or serialize them in raw form for later use.
27pub fn paint_scene(
28    scene: &mut impl PaintScene,
29    dom: &BaseDocument,
30    scale: f64,
31    width: u32,
32    height: u32,
33) {
34    reset_layer_stats();
35
36    let devtools = *dom.devtools();
37    let generator = BlitzDomPainter {
38        dom,
39        scale,
40        width,
41        height,
42        devtools,
43    };
44    generator.paint_scene(scene);
45
46    // println!(
47    //     "Rendered using {} clips (depth: {}) (wanted: {})",
48    //     CLIPS_USED.load(atomic::Ordering::SeqCst),
49    //     CLIP_DEPTH_USED.load(atomic::Ordering::SeqCst),
50    //     CLIPS_WANTED.load(atomic::Ordering::SeqCst)
51    // );
52}