Screenshots, recording and --gfx-out keep the screen's pixels on the host
CI / test (push) Failing after 17s

New chandra:host/raster functions, on both hosts: write-frame-png (--gfx-out),
grab-recording-frame / send-recording-frame (the recorder streams frames from the
host to ffmpeg) and snapshot-frame / snapshot-png / snapshot-pixels (screenshots
freeze, crop and encode the screen there; the magnifier and the notification's
thumbnail read small scaled copies). The wasm compositor sets them up through
frame_recorder and frame_shots; the native compositor keeps its pixel path.

Moving whole frames as list<u8> is cheap for the Rust host but costs about
0.4 s a 720p frame through the wasmtime C API. A full-screen screenshot now takes
45 ms on the MoonBit host (was 472) and 8 ms on the Rust host (was 112);
recording runs at 30 fps on both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiNfjrw2edja7LiRLB
This commit is contained in:
Claude committed 2026-11-25 20:03:34 +00:00
1 parent 3b15248124
commit caa12058fd
13 files changed
+668 -26

No files matched your search

+115 -3
View File
@@ -175,6 +175,59 @@ extern "C" fn rs_read_frame(out : FixedArray[Byte]) = "rs_read_frame"
///|
extern "C" fn rs_export_memfd() -> Int = "rs_export_memfd"
///|
extern "C" fn rs_grab_recording(
x : Int,
y : Int,
w : Int,
h : Int,
pointer : Int,
px : Int,
py : Int,
) -> Int = "rs_grab_recording"
///|
extern "C" fn rs_send_recording(fd : Int) -> Int = "rs_send_recording"
///|
extern "C" fn rs_snapshot() -> Int = "rs_snapshot"
///|
extern "C" fn rs_snapshot_w() -> Int = "rs_snapshot_w"
///|
extern "C" fn rs_snapshot_h() -> Int = "rs_snapshot_h"
///|
#borrow(out)
extern "C" fn rs_snapshot_pixels(
x : Int,
y : Int,
w : Int,
h : Int,
out_w : Int,
out_h : Int,
out : FixedArray[Byte],
) -> Unit = "rs_snapshot_pixels"
///| `x`, `y`, `w` x `h` of the screenshot snapshot scaled to `out_w` x `out_h`, opaque.
fn snapshot_pixels(x : Int, y : Int, w : Int, h : Int, out_w : Int, out_h : Int) -> FixedArray[Byte] {
if out_w <= 0 || out_h <= 0 || out_w > 16384 || out_h > 16384 {
return FixedArray::make(0, b'\x00')
}
let out = FixedArray::make(out_w * out_h * 4, b'\x00')
rs_snapshot_pixels(x, y, w, h, out_w, out_h, out)
out
}
///| The framebuffer as a pixmap.
fn frame_pixmap() -> @renderer.Pixmap {
let (width, height) = (rs_width(), rs_height())
let data = FixedArray::make(width * height * 4, b'\x00')
rs_read_frame(data)
{ width, height, data }
}
// ---------------------------------------------------------------- geometry
///|
@@ -764,11 +817,70 @@ fn raster_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] {
(
"read-frame",
_ => {
let out = FixedArray::make(rs_width() * rs_height() * 4, b'\x00')
rs_read_frame(out)
[@wt.Val::bytes(Bytes::from_fixedarray(out))]
[@wt.Val::bytes(Bytes::from_fixedarray(frame_pixmap().data))]
},
),
("export-memfd", _ => s32(rs_export_memfd())),
(
"write-frame-png",
a => {
let p = frame_pixmap()
let ok = p.width > 0 &&
@sys.write_file_bytes(a[0].to_string(), @renderer.encode_png(p)) == 0
[Bool(ok)]
},
),
(
"grab-recording-frame",
a => {
let n = rs_grab_recording(
a[0].to_int(),
a[1].to_int(),
a[2].to_int(),
a[3].to_int(),
if a[4].to_bool() { 1 } else { 0 },
a[5].to_int(),
a[6].to_int(),
)
[Bool(n != 0)]
},
),
("send-recording-frame", a => s32(rs_send_recording(a[0].to_int()))),
("snapshot-frame", _ => [Bool(rs_snapshot() != 0)]),
(
"snapshot-png",
a => {
// Clipped to the snapshot; a 1:1 copy is a scale by one.
let (sw, sh) = (rs_snapshot_w(), rs_snapshot_h())
let x0 = a[0].to_int().max(0)
let y0 = a[1].to_int().max(0)
let x1 = (a[0].to_int() + a[2].to_int()).min(sw)
let y1 = (a[1].to_int() + a[3].to_int()).min(sh)
if x1 <= x0 || y1 <= y0 {
return [@wt.Val::bytes(b"")]
}
let (w, h) = (x1 - x0, y1 - y0)
let p : @renderer.Pixmap = {
width: w,
height: h,
data: snapshot_pixels(x0, y0, w, h, w, h),
}
[@wt.Val::bytes(@renderer.encode_png_compressed(p))]
},
),
(
"snapshot-pixels",
a => {
let px = snapshot_pixels(
a[0].to_int(),
a[1].to_int(),
a[2].to_int(),
a[3].to_int(),
a[4].to_int(),
a[5].to_int(),
)
[@wt.Val::bytes(Bytes::from_fixedarray(px))]
},
),
]
}