ui/canvas.rs#
Source: lib/ui/canvas.rs
canvas -- a canvas whose zoom and pan go through GPU textures (G3c; docs/GPU.md "Leinwände")
The CPU stays the truth: a canvas records its Cmd::Custom as ever (ui.canvas, ui.cmd_custom), its
Draw paints what the view shows. Right after it the widget tells the library what that drawing
is made of:
ui.canvas_gpu_wanted() -> bool is it worth building a CanvasDesc? (Never on other targets,
without a GPU output, in headless runs.)
ui.canvas_gpu(CanvasDesc { .. }) the custom command recorded last shows this content through
this view
ui.canvas_gpu_damage(id, r) the content rectangle r (x0, y0, x1, y1, content units)
changed: its tiles are drawn again when they are needed
While the view moves and the content stays, the content comes from tiles (TILE x TILE px GPU
textures, drawn once by CanvasContent::draw_view, kept under a budget) that the render pass draws
with the transform: no raster, no upload of the view. A short time after the last change the
view is drawn once more by the CPU: at rest the picture is byte for byte the CPU path's. An edit
goes the CPU's way as without a GPU and costs no tile.
Everywhere else, and with CanvasGpu::Cpu, ui.canvas_gpu does nothing and the Draw paints every
frame; the widget's code stays the same on every target.
enum CanvasGpuhow a canvas may use the GPU while its view movesCpu-- the CPU path in every frame, as without a GPUPan-- moves by whole pixels at the same scale come from the tiles; another scale is drawn by the CPU at once. Pixel-exact when the content's raster does not depend on its placeZoom-- also zoom: the tiles are scaled while the gesture runs (a little soft or coarse), the CPU draws the picture sharp a moment after it
struct CanvasViewthe view of a canvas: the content point (u, v) shows at the window pixel position (ox + u * scale, oy + v * scale)scale: f64ox: f64oy: f64
trait CanvasContentwhat a canvas shows, drawable through any view (at render time)fn draw_view(&self, g: &mut Gfx, v: CanvasView, rect: [i32; 4])draw the content through view v into g (origin 0, the clip says what needs pixels, rect = the target's rectangle): what the canvas's Draw paints there at this view, without what lies over it, every pixel opaque
struct CanvasDesca canvas for ui.canvas_gpuid: u32-- its identity in the window (the tiles live as long as it is drawn; ui.canvas_gpu_damage)name: &'static str-- its name for jfgui_GPU_CANVAS_CPU / jfgui_GPU_CANVAS_PAN ("image", "diagram", ...)rect: [i32; 4]-- the window rectangle x, y, w, h the content fills, opaque (inside the custom command's box)view: CanvasViewver: u32-- stands for everything the content shows: another value drops its tilescontent: Rc<dyn CanvasContent>gpu: CanvasGpuexact_pan: bool-- the raster does not depend on the place: a move by whole pixels must match byte for byte (jfgui_GPU_VERIFY fails on a difference; else it is counted, GpuOutput::canvas_diff_*)
impl Ui
fn canvas_gpu_wanted(&self) -> boolis the GPU output there to use a CanvasDesc? A widget without one saves building itfn canvas_gpu(&mut self, d: CanvasDesc)the custom command recorded last shows this content through this view (module header)fn canvas_gpu_damage(&mut self, id: u32, r: [f64; 4])the content rectangle x0, y0, x1, y1 (content units) of canvas id changed: its tiles go (of the window being built when it has the canvas; else, outside the passes too, of the canvas of that id in every window)