plat/present_copy.rs#
Source: lib/plat/present_copy.rs
present_copy -- the copy of a present's dirty rectangles into the window's own pixels:
Windows' kept DIB section (win_api.rs), X11's MIT-SHM segments, shadow and staging images,
Wayland's wl_shm buffers and staging image (linux_damage.rs)
copy_boxes(dst, ds, src, ss, boxes, w, h) the boxes x0, y0, x1, y1 (exclusive; clipped to
w x h, they may overlap) of src (rows of ss bytes) into dst (rows of ds
bytes), 4 bytes a pixel; rows outside either slice are skipped. Below
PAR_MIN bytes plain row copies on this thread (no pool round trip); from
PAR_MIN on in row bands on the worker pool (parallel_for; a band is a run of
the target's rows, so no two threads write one row, overlapping boxes
included); from STREAM_MIN on with streaming stores (x86-64: movntdq), fenced
on every thread before the loop returns. The same bytes either way.
The thresholds are those of gfx's blit (gfx::COPY_PAR_MIN / COPY_STREAM_MIN, measured there): a
4K frame is 32 MB, source and target together no longer fit the caches, and the target is read
by someone else next (GDI's BitBlt, the X server, the compositor). plat has its own streaming
copy (stream_copy, simd::copy_stream's loop): plat comes before simd in the build order (the
workspace's members, which build_rs.py's LIBS and the publication follow), so depending on
simd would move simd below plat and give the published jflib-plat a new dependency, with
simd's kernels and its compute-crate build, for one loop of 30 lines.
fn present_copy_bench(dst: &mut [u8], ds: usize, src: &[u8], ss: usize, boxes: &[[i32; 4]], w: i32, h: i32)(benchmarks: plattest --test present-bench) copy_boxes for a bench outside plat: the boxes (x0, y0, x1, y1) of src into dst as a present copies them