CI / test (push) Failing after 29s
The wasm software renderer cost ~10-20 ns/pixel, so any changed frame took ~100+ ms at 1080p and the desktop swung between idle and very slow. The compositor still builds the scene (windows, decorations, panel, wallpaper) but a new moonplasma:host/raster interface turns it into pixels in the host: - host-wasm/src/raster.rs: a port of compositor/renderer (same blend arithmetic: fills, strokes, lines, circles, text, clips, shadows, surface blits), a wallpaper+desktop-card cache, and captured client surfaces (copied out of the shared memory once at commit, converted to RGBA, solid ones blit as row copies). 9 unit tests; a full frame matches the native software renderer except for text antialiasing (0.3% of pixels). - compositor/raster sends a SceneGraph as ops; compositor.compose_scene() returns it only when something changed. The login session shows the host framebuffer directly (display.present-frame), the nested window gets it as a memfd (raster.export-memfd), --gfx-out reads it (read-frame). - Client buffers never enter wasm: snapshot_shm_buffer captures in the host and keeps an id. - Loop pacing sleeps the rest of the frame budget instead of a fixed 16/8 ms. Full-screen terminal flooding output at 1080p: ~2 fps / 94% CPU -> ~57 fps; idle ~9%. The native build keeps the software renderer. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
98 lines
3.3 KiB
MoonBit
98 lines
3.3 KiB
MoonBit
///| Send a scene to the host to draw (`moonplasma:host/raster`).
|
|
///
|
|
/// The scene is the same one the software renderer takes (`@scene.SceneGraph`); here it is turned
|
|
/// into the interface's records and handed over. The host owns the framebuffer and does the pixel
|
|
/// work natively; client window buffers are already there (captured at commit, by id).
|
|
|
|
///|
|
|
fn conv_rect(r : @scene.Rect) -> @hostraster.Rect {
|
|
{ x: r.x, y: r.y, w: r.w, h: r.h }
|
|
}
|
|
|
|
///|
|
|
fn conv_color(c : @scene.Rgba) -> @hostraster.Color {
|
|
{ r: c.r, g: c.g, b: c.b, a: c.a }
|
|
}
|
|
|
|
///|
|
|
fn conv_align(a : @scene.TextAlign) -> Byte {
|
|
match a {
|
|
Left => b'\x00'
|
|
Center => b'\x01'
|
|
Right => b'\x02'
|
|
}
|
|
}
|
|
|
|
///|
|
|
fn conv_op(op : @scene.DrawOp) -> @hostraster.Op {
|
|
match op {
|
|
FillRect(r, c, radius) => FillRect({ area: conv_rect(r), color: conv_color(c), radius })
|
|
StrokeRect(r, c, width, radius) => StrokeRect({ area: conv_rect(r), color: conv_color(c), width, radius })
|
|
Line(x0, y0, x1, y1, c, width) => DrawLine({ x0, y0, x1, y1, color: conv_color(c), width })
|
|
Circle(cx, cy, radius, c, filled) => DrawCircle({ cx, cy, radius, color: conv_color(c), filled })
|
|
Text(x, y, text, size, c, align, bold) =>
|
|
DrawText({ x, y, text, size, color: conv_color(c), align: conv_align(align), bold, mono: false })
|
|
MonoText(x, y, text, size, c, align, bold) =>
|
|
DrawText({ x, y, text, size, color: conv_color(c), align: conv_align(align), bold, mono: true })
|
|
PushClip(r) => PushClip(conv_rect(r))
|
|
PopClip => PopClip
|
|
}
|
|
}
|
|
|
|
///|
|
|
fn conv_ops(ops : Array[@scene.DrawOp]) -> Array[@hostraster.Op] {
|
|
ops.map(conv_op)
|
|
}
|
|
|
|
///| The backdrop (wallpaper and the desktop card on it) the host last drew, and the size it was
|
|
/// drawn for. While neither changes the frame says "unchanged" and the host reuses its cached
|
|
/// pixels instead of being sent about two thousand ops again and drawing them.
|
|
let last_backdrop : Ref[Array[@scene.DrawOp]?] = { val: None }
|
|
|
|
///|
|
|
let last_size : Ref[(Int, Int)] = { val: (0, 0) }
|
|
|
|
///| Draw `scene` into the host framebuffer.
|
|
pub fn submit(scene : @scene.SceneGraph) -> Unit {
|
|
let backdrop = scene.wallpaper_ops + scene.background_ops
|
|
let same = match last_backdrop.val {
|
|
Some(prev) => prev == backdrop && last_size.val == (scene.output_w, scene.output_h)
|
|
None => false
|
|
}
|
|
if !same {
|
|
last_backdrop.val = Some(backdrop)
|
|
last_size.val = (scene.output_w, scene.output_h)
|
|
}
|
|
let windows : Array[@hostraster.Window] = scene.windows.map(w => {
|
|
let (top, right, bottom, left) = w.deco_insets
|
|
{
|
|
geometry: conv_rect(w.geometry),
|
|
inset_top: top,
|
|
inset_right: right,
|
|
inset_bottom: bottom,
|
|
inset_left: left,
|
|
deco: conv_ops(w.deco_ops),
|
|
fullscreen: w.fullscreen,
|
|
surface: match w.surface {
|
|
Some(s) => s.host_id
|
|
None => 0U
|
|
},
|
|
}
|
|
})
|
|
@hostraster.submit({
|
|
width: scene.output_w,
|
|
height: scene.output_h,
|
|
wallpaper: if same { None } else { Some(conv_ops(backdrop)) },
|
|
background: [],
|
|
windows,
|
|
panel: conv_ops(scene.panel_ops),
|
|
popups: scene.popups.map(p => { area: conv_rect(p.0), surface: p.1.host_id }),
|
|
})
|
|
}
|
|
|
|
///| The host framebuffer as a pixmap (screenshots and tests; the display path never needs it).
|
|
pub fn read_frame(width : Int, height : Int) -> @renderer.Pixmap {
|
|
let data = @hostraster.read_frame()
|
|
{ width, height, data }
|
|
}
|