JFLib

render2d/cpu.rs#

Source: lib/render2d/cpu.rs

cpu -- the CPU path (G6e1, decision 29; docs/RENDER2D.md "Der CPU-Weg"): a scene drawn through lib/gfx's rasterizer
without a device, with the camera, the painter's order, the visible layers and the look of a frame on the GPU.  A child
of scene.rs: it reads the scene's entities, layers, styles, blocks, texts, highlights and overlay, and its R-tree (pick.rs).

A frame: the view's box in the drawing (f64), grown by the widest reach in pixels, through the R-tree; the entities found
sorted into the painter's order (layer, then place in the layer), inserts walked down into their blocks through the
inverse transforms as pick.rs walks them (the copies of an array that meet the view, each block's own tree, nested
inserts).  Every point goes from its units to pixels relative to the view in f64 (a block's through its insert's
transform, the camera's centre taken off before anything is scaled), so ±1e7 at 1e-6 units per pixel stays exact; centre
lines are clipped in f64 to the target grown by the stroke's reach, and every piece handed to lib/gfx is clipped to the
target and GUARD px around it: lib/gfx sees small f32 numbers only.  Each entity is one fill of lib/gfx (exact area
coverage by signed accumulation), blended once in its colour as the GPU blends it (premultiplied sRGB codes).

Strokes are convex pieces whose areas add up to the union the GPU computes: per segment its strip, cut at the bisector of
each join where the cut fits both segments (miter: the tip comes from the cut, bevel: its line cuts too, round: the
perpendicular through the vertex, the outer sector a piece of its own), else the GPU's union |a| + |w| + |b| - |a ∩ b|
(both strips end at the perpendicular, the join's piece beyond both, their intersection subtracted: the accumulation's
sign takes it); caps as planes (butt, square) or half disks.  Arcs are flattened within ARC_TOL px only where they come
near the view; curves and fills as the GPU flattens them (the scene's flattening while it holds for the camera, else the
same function for this camera; a block's per zoom band), fills even-odd from oriented rings.  Dash patterns cut in f64
along each entity's lengths, flat tones and mixes at the GPU's thresholds; hatches clipped to the fill in f64 and
multiplied by its coverage as the GPU does; text from its glyphs' outlines in G6c's layout, bars below TEXT_BAR_BELOW px
per em; highlights and the overlay as G6d draws them.
  • struct CpuInfo what the last draw_cpu did (Scene::draw_cpu, cpu_info). It may grow
    • found: u32 -- entities on layers the index found near the view (an insert once), and what was drawn: entities on layers, each copy of a block's entity in an insert once
    • drawn: u32
    • fills: u32 -- fills lib/gfx made (an entity one, a bar of small text one, a hatch's coverages more) and the lines it rasterized
    • lines: u64
    • flattened: u32 -- curves and fills flattened on the way (the scene's flattening was made for another zoom band or window; a block's curves and fills each time)
    • overlay: u32 -- overlay items drawn

impl Scene

  • fn draw_cpu(&mut self, dc: &mut Dc, sf: &mut Surface, r: [i32; 4]) -> CpuInfo the scene drawn on the CPU through lib/gfx (G6e1, decision 29): the camera's view of a target of r's size into the rectangle r (x, y, w, h, relative to dc's origin) of sf, clipped to dc's clip, blended over what is there (the app clears it first, as a frame's load does); the painter's order, the visible layers, the look, the highlights and the overlay of a frame on the GPU (docs/RENDER2D.md "Der CPU-Weg"). With and without a device. dc keeps its colour, clip and origin
  • fn set_cpu_single(&mut self, single: bool) draw_cpu on one thread (false: row bands on lib/gfx's parallel loop where one is set, gfx::set_parallel: lib/ui sets its worker pool there; the same bytes either way)
  • fn cpu_info(&self) -> CpuInfo what the last draw_cpu did

Source: docs/API.md in the JFLib repository.