Files
chandra/interface/moonplasma/host/display/top.mbt
T
nandiandClaude Sonnet 5.5 c6e31b4a8f
CI / test (push) Failing after 29s
Draw in the host: the wasm compositor sends draw ops, the host rasterises natively
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>
2026-11-25 04:39:40 -08:00

139 lines
4.2 KiB
MoonBit

// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Output {
width : UInt; height : UInt; keymap : FixedArray[Byte]
}
///|
pub(all) struct PointerPos {
x : Double; y : Double
}
///|
/// A button or key as an evdev code, pressed or released.
pub(all) struct KeyState {
code : UInt; pressed : Bool
}
///|
pub(all) struct Modifiers {
depressed : UInt; latched : UInt; locked : UInt; group : UInt
}
///|
pub(all) enum SeatEvent {
PointerMove(PointerPos)
PointerButton(KeyState)
Key(KeyState)
Modifiers(Modifiers)
}
///|
/// Take over the first connected output and the seat's input. None, with the reason on the
/// host's stderr, when this is not an active login VT.
pub fn open() -> Output? {
let return_area = mbt_ffi_malloc(20)
wasmImportOpen(return_area);
let lifted : Output? = match mbt_ffi_load8_u((return_area) + 0) {
0 => Option::None
1 => {
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16))
Option::Some(Output::{width : (mbt_ffi_load32((return_area) + 4)).reinterpret_as_uint(), height : (mbt_ffi_load32((return_area) + 8)).reinterpret_as_uint(), keymap : result})
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(return_area)
return ret
}
///|
/// Service the seat, DRM and input fds without blocking. False once the user asked to quit
/// (Ctrl+Alt+Backspace).
pub fn poll() -> Bool {
let result : Int = wasmImportPoll();
let ret = (result != 0)
return ret
}
///|
/// True when a new frame can be presented (seat active, no page flip in flight).
pub fn frame_ready() -> Bool {
let result : Int = wasmImportFrameReady();
let ret = (result != 0)
return ret
}
///|
/// Show an RGBA8888 frame of `width` x `height` (it must match the output mode).
pub fn present(pixels : FixedArray[Byte], width : UInt, height : UInt) -> Unit {
let ptr = mbt_ffi_bytes2ptr(pixels)
wasmImportPresent(ptr, pixels.length(), (width).reinterpret_as_int(), (height).reinterpret_as_int());
mbt_ffi_free(ptr)
}
///|
/// Show the host framebuffer (what `raster.submit` drew) on the output.
pub fn present_frame() -> Unit {
wasmImportPresentFrame();
}
///|
/// Show the cursor for a wp_cursor_shape_v1 value.
pub fn set_cursor_shape(shape : UInt) -> Unit {
wasmImportSetCursorShape((shape).reinterpret_as_int());
}
///|
/// Input queued since the last call.
pub fn take_input() -> Array[SeatEvent] {
let return_area = mbt_ffi_malloc(8)
wasmImportTakeInput(return_area);
let array : Array[SeatEvent] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 24)
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => {
SeatEvent::PointerMove(PointerPos::{x : mbt_ffi_loadf64((iter_base) + 8), y : mbt_ffi_loadf64((iter_base) + 16)})
}
1 => {
SeatEvent::PointerButton(KeyState::{code : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), pressed : (mbt_ffi_load8_u((iter_base) + 12) != 0)})
}
2 => {
SeatEvent::Key(KeyState::{code : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), pressed : (mbt_ffi_load8_u((iter_base) + 12) != 0)})
}
3 => {
SeatEvent::Modifiers(Modifiers::{depressed : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), latched : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), locked : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint(), group : (mbt_ffi_load32((iter_base) + 20)).reinterpret_as_uint()})
}
_ => panic()
}
array.push(lifted)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Restore the previous video mode and release the seat.
pub fn close() -> Unit {
wasmImportClose();
}