CI / test (push) Canceled after 0s
A recording of an animation looked choppy because frames barely reached ffmpeg: each 8 MB 1080p frame went out only as far as the socket buffer took it on each main loop pass, so a new frame could be taken only every few hundred ms (V's recording changed picture ~12 times a second; headless, 2 a second). Frames were also stamped when ffmpeg read them, not when drawn, and every grab forced a full redraw. Now: - Both hosts (wasmhost raster_stub.c, host-wasm main.rs) copy a frame into a 3-slot queue and a writer thread sends it, so a frame never waits on the main loop. A full queue (ffmpeg behind) means that frame is not taken; the next one is, with its own time. - The stream is uncompressed RGBA in Matroska (recorder.mbt mkv_stream_header / mkv_frame_header; the hosts write the same 42-byte cluster header), each frame stamped with the time it was drawn. ffmpeg makes constant 60 fps H.264 from it, under nice -n 10. - A frame is taken when the desktop draws a changed frame (app.mbt draw_frame, compose_frame), at most 60 a second, or when the pointer moves. A still screen sends nothing; the REC pill redraws only its own rectangle when its seconds turn. - ffmpeg going away mid-recording says so in the notification. - Tests: the cluster header bytes, ffprobe reading the stream with each frame's own time, and the recording test now checks a 60 fps file as long as the recording ran. The recording tests fail with a clear message when ffmpeg/ffprobe are missing instead of returning early; CI installs ffmpeg. Headless 1080p, one window redrawing at 60 fps (rec-bench.sh in project files recorder-smooth/): distinct frames in the video 2.1/s -> 58.9/s (MoonBit host), 59.1/s (Rust host); overview open/close 1.8/s -> 38.7/s (its previews refresh at 5-10/s live). Compositor kept drawing 57 fps while recording; still screen: compositor 8% CPU. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjEUQq16Te1LPYMinT
99 lines
5.3 KiB
Plaintext
99 lines
5.3 KiB
Plaintext
package chandra:host@0.1.0;
|
|
|
|
/// Drawing done by the host. The compositor component decides what the screen shows (windows,
|
|
/// panel, wallpaper, decorations) and sends it as a list of draw operations; the host keeps the
|
|
/// framebuffer and does the pixel work natively, so no pixels cross the component boundary. Client
|
|
/// window buffers are captured here too (a native copy out of the client's shared memory), and the
|
|
/// component only holds their ids.
|
|
interface raster {
|
|
record rect { x: s32, y: s32, w: s32, h: s32 }
|
|
record color { r: u8, g: u8, b: u8, a: u8 }
|
|
record fill { area: rect, color: color, radius: s32 }
|
|
record stroke { area: rect, color: color, width: s32, radius: s32 }
|
|
record segment { x0: s32, y0: s32, x1: s32, y1: s32, color: color, width: s32 }
|
|
record disc { cx: s32, cy: s32, radius: s32, color: color, filled: bool }
|
|
/// `align`: 0 left, 1 centre, 2 right of `x`; `y` is the text's vertical centre.
|
|
record label { x: s32, y: s32, text: string, size: s32, color: color, align: u8, bold: bool, mono: bool }
|
|
/// An image from `load-image`, scaled to fill `area`.
|
|
record picture { area: rect, image: u32 }
|
|
variant op {
|
|
fill-rect(fill),
|
|
stroke-rect(stroke),
|
|
draw-line(segment),
|
|
draw-circle(disc),
|
|
draw-text(label),
|
|
push-clip(rect),
|
|
pop-clip,
|
|
draw-image(picture),
|
|
}
|
|
|
|
/// A toplevel: its decoration (drawn at `geometry` minus the insets), then its client surface.
|
|
record window {
|
|
geometry: rect,
|
|
inset-top: s32,
|
|
inset-right: s32,
|
|
inset-bottom: s32,
|
|
inset-left: s32,
|
|
deco: list<op>,
|
|
fullscreen: bool,
|
|
/// A surface id from `capture`; 0 when the client has not committed a buffer.
|
|
surface: u32,
|
|
}
|
|
record popup { area: rect, surface: u32 }
|
|
record frame {
|
|
width: s32,
|
|
height: s32,
|
|
/// The static backdrop (wallpaper and desktop card); none means "unchanged since the last submit" (the host keeps its pixels).
|
|
wallpaper: option<list<op>>,
|
|
background: list<op>,
|
|
windows: list<window>,
|
|
panel: list<op>,
|
|
popups: list<popup>,
|
|
}
|
|
|
|
/// Copy a client buffer (`stride * height` bytes at `offset` of the file behind `fd`) into a
|
|
/// host surface. `format` is the wl_shm format (0 ARGB8888, 1 XRGB8888). 0 on failure.
|
|
capture: func(fd: s32, offset: s32, stride: s32, width: s32, height: s32, format: s32) -> u32;
|
|
release: func(id: u32);
|
|
/// Decode the PNG or SVG file at `path` into a host image (an app icon), for `draw-image`.
|
|
/// Loading the same path again returns the same handle. 0 when it can't be read or decoded.
|
|
load-image: func(path: string) -> u32;
|
|
/// A scaled-down copy of captured surface `surface`, `w` x `h`, as an image for `draw-image`
|
|
/// (the Alt+Tab switcher's window previews). `reuse`: an earlier thumbnail handle to overwrite
|
|
/// in place, 0 for a new one. 0 when the surface is unknown or the size is silly.
|
|
thumbnail: func(surface: u32, w: s32, h: s32, reuse: u32) -> u32;
|
|
/// `w` x `h` RGBA8888 pixels as an image for `draw-image` (the face unlock window's camera
|
|
/// picture). `reuse`: an earlier handle from this function or `thumbnail` to overwrite in place,
|
|
/// 0 for a new one. 0 when the size is silly or `rgba` is too short.
|
|
image-pixels: func(w: s32, h: s32, rgba: list<u8>, reuse: u32) -> u32;
|
|
/// Draw a frame into the host framebuffer.
|
|
submit: func(f: frame);
|
|
/// The framebuffer as RGBA8888 (for screenshots and tests; the display path never needs it).
|
|
read-frame: func() -> list<u8>;
|
|
/// A new memfd holding the framebuffer as little-endian ARGB8888, ready to hand to a Wayland
|
|
/// compositor as a wl_shm pool. The caller closes it. -1 on failure.
|
|
export-memfd: func() -> s32;
|
|
/// Save the framebuffer as a PNG file at `path` (--gfx-out, tests): the pixels stay on the
|
|
/// host. False when it can't be written.
|
|
write-frame-png: func(path: string) -> bool;
|
|
/// Screen recording, without the pixels crossing into the component: copy the framebuffer's
|
|
/// `x`, `y`, `w` x `h` (on screen) into the host's recording queue as opaque RGBA8888, with an
|
|
/// arrow pointer drawn at screen position (`px`, `py`) when `pointer`, as a Matroska cluster
|
|
/// stamped with the host's monotonic clock in ms. False when the rectangle is not on screen or
|
|
/// the queue is full (the encoder is behind).
|
|
grab-recording-frame: func(x: s32, y: s32, w: s32, h: s32, pointer: bool, px: s32, py: s32) -> bool;
|
|
/// fd >= 0: the host's writer thread sends the queue to `fd` (a socket, after the stream
|
|
/// header; started on the first call): the frames still queued, or -1 once a write failed.
|
|
/// fd < 0: send what is queued and stop the writer: 0, or -1 when a write failed.
|
|
send-recording-frame: func(fd: s32) -> s32;
|
|
/// Screenshots, without the whole screen crossing into the component: freeze the framebuffer
|
|
/// on the host as the snapshot (replacing the last one). False when there is no framebuffer.
|
|
snapshot-frame: func() -> bool;
|
|
/// The snapshot's `x`, `y`, `w` x `h` (clipped to it), made opaque, as PNG file bytes. Empty
|
|
/// when the rectangle misses it.
|
|
snapshot-png: func(x: s32, y: s32, w: s32, h: s32) -> list<u8>;
|
|
/// The snapshot's `x`, `y`, `w` x `h` scaled (nearest pixel) to `out-w` x `out-h`, as opaque
|
|
/// RGBA8888 (the magnifier, the notification's thumbnail). Pixels off the snapshot are black.
|
|
snapshot-pixels: func(x: s32, y: s32, w: s32, h: s32, out-w: s32, out-h: s32) -> list<u8>;
|
|
}
|