Screenshots, recording and --gfx-out keep the screen's pixels on the host
CI / test (push) Failing after 17s
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:
13 files changed
+668
-26
No files matched your search
@@ -21,6 +21,24 @@ fn wasmImportReadFrame(p0 : Int) = "chandra:host/raster@0.1.0" "read-frame"
|
||||
///|
|
||||
fn wasmImportExportMemfd() -> Int = "chandra:host/raster@0.1.0" "export-memfd"
|
||||
|
||||
///|
|
||||
fn wasmImportWriteFramePng(p0 : Int, p1 : Int) -> Int = "chandra:host/raster@0.1.0" "write-frame-png"
|
||||
|
||||
///|
|
||||
fn wasmImportGrabRecordingFrame(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int) -> Int = "chandra:host/raster@0.1.0" "grab-recording-frame"
|
||||
|
||||
///|
|
||||
fn wasmImportSendRecordingFrame(p0 : Int) -> Int = "chandra:host/raster@0.1.0" "send-recording-frame"
|
||||
|
||||
///|
|
||||
fn wasmImportSnapshotFrame() -> Int = "chandra:host/raster@0.1.0" "snapshot-frame"
|
||||
|
||||
///|
|
||||
fn wasmImportSnapshotPng(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) = "chandra:host/raster@0.1.0" "snapshot-png"
|
||||
|
||||
///|
|
||||
fn wasmImportSnapshotPixels(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int) = "chandra:host/raster@0.1.0" "snapshot-pixels"
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
|
||||
@@ -35,6 +35,36 @@ fn wasmImportExportMemfd() -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportWriteFramePng(p0 : Int, p1 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportGrabRecordingFrame(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSendRecordingFrame(p0 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSnapshotFrame() -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSnapshotPng(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSnapshotPixels(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_str2ptr(str : String) -> Int {
|
||||
abort("wasm-only")
|
||||
|
||||
@@ -616,4 +616,75 @@ pub fn export_memfd() -> Int {
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// 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.
|
||||
pub fn write_frame_png(path : String) -> Bool {
|
||||
|
||||
let ptr = mbt_ffi_str2ptr(path)
|
||||
let result : Int = wasmImportWriteFramePng(ptr, path.length());
|
||||
let ret = (result != 0)
|
||||
mbt_ffi_free(ptr)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// 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 frame as opaque RGBA8888, with an
|
||||
/// arrow pointer drawn at screen position (`px`, `py`) when `pointer`. It replaces a frame
|
||||
/// still being sent. False when the rectangle is not on screen.
|
||||
pub fn grab_recording_frame(x : Int, y : Int, w : Int, h : Int, pointer : Bool, px : Int, py : Int) -> Bool {
|
||||
|
||||
let result : Int = wasmImportGrabRecordingFrame(x, y, w, h, if pointer { 1 } else { 0 }, px, py);
|
||||
let ret = (result != 0)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// Write what is left of the recording frame to `fd` (a socket; made non-blocking): the bytes
|
||||
/// still left after this (0: it all went out), or -1 when the write failed.
|
||||
pub fn send_recording_frame(fd : Int) -> Int {
|
||||
|
||||
let result : Int = wasmImportSendRecordingFrame(fd);
|
||||
let ret = result
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// 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.
|
||||
pub fn snapshot_frame() -> Bool {
|
||||
|
||||
let result : Int = wasmImportSnapshotFrame();
|
||||
let ret = (result != 0)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// The snapshot's `x`, `y`, `w` x `h` (clipped to it), made opaque, as PNG file bytes. Empty
|
||||
/// when the rectangle misses it.
|
||||
pub fn snapshot_png(x : Int, y : Int, w : Int, h : Int) -> FixedArray[Byte] {
|
||||
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
wasmImportSnapshotPng(x, y, w, h, return_area);
|
||||
|
||||
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
|
||||
let ret = result
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// 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.
|
||||
pub fn snapshot_pixels(x : Int, y : Int, w : Int, h : Int, out_w : Int, out_h : Int) -> FixedArray[Byte] {
|
||||
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
wasmImportSnapshotPixels(x, y, w, h, out_w, out_h, return_area);
|
||||
|
||||
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
|
||||
let ret = result
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user