euv_chart/backend/common/trait.rs
1use super::*;
2
3/// A rendering backend for the chart.
4///
5/// The three backends — WebGPU, WebGL2, and Canvas2D — all replay the
6/// same display list, so the chart model never has to know which one is
7/// in use. That is what keeps the public API identical across backends.
8pub trait ChartBackend {
9 /// Returns the kind of the backend.
10 ///
11 /// # Returns
12 ///
13 /// - `BackendKind` - A `BackendKind` value.
14 fn kind(&self) -> BackendKind;
15
16 /// Prepares the backend for a canvas of the given CSS size, at the
17 /// given device pixel ratio.
18 ///
19 /// The backends size their drawing buffer to `width * dpr` by
20 /// `height * dpr` physical pixels and scale their coordinate system
21 /// accordingly, so the model always works in CSS pixels.
22 ///
23 /// # Arguments
24 ///
25 /// - `f64` - A 64-bit float (`f64`).
26 fn resize(&mut self, width: f64, height: f64, dpr: f64);
27
28 /// Replays the display list onto the canvas.
29 ///
30 /// The backend is free to cache whatever it can: the display list is
31 /// retained between frames, so a chart that has not changed should
32 /// cost close to nothing to draw.
33 ///
34 /// # Arguments
35 ///
36 /// - `&DisplayList` - Shared reference to a `DisplayList`.
37 /// - `&mut TextShaper` - Mutable reference to a `TextShaper` (mutated in place).
38 fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper);
39
40 /// Releases the resources the backend holds.
41 ///
42 /// Called when the chart is disposed. The backend must stay usable
43 /// afterwards — it will simply re-acquire its resources on the next
44 /// render.
45 fn dispose(&mut self);
46}