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
@@ -37,6 +37,14 @@ pub(all) struct Recording {
|
||||
mut frames : Int
|
||||
}
|
||||
|
||||
///| Screen recording done by the host that draws the screen: `grab` copies a rectangle of the
|
||||
/// screen (with the pointer at a screen position when asked) into the host's frame, and `send`
|
||||
/// writes what is left of it to the encoder's socket (the bytes still left, or -1).
|
||||
pub(all) struct FrameRecorder {
|
||||
grab : (@scene.Rect, Bool, Int, Int) -> Bool
|
||||
send : (Int) -> Int
|
||||
}
|
||||
|
||||
///| Whether a recording is running.
|
||||
pub fn ChandraCompositor::recording(self : ChandraCompositor) -> Bool {
|
||||
self.rec is Some(_)
|
||||
@@ -95,7 +103,7 @@ pub fn ChandraCompositor::toggle_recording(self : ChandraCompositor, mode : Shot
|
||||
|
||||
///| The overlay, picking what to record.
|
||||
fn ChandraCompositor::open_record_overlay(self : ChandraCompositor, pick : Bool) -> Unit {
|
||||
match self.grab_screen() {
|
||||
match self.freeze_screen() {
|
||||
Some(frame) => {
|
||||
self.open_overlay(frame, pick)
|
||||
match self.shot {
|
||||
@@ -225,6 +233,33 @@ fn ChandraCompositor::recording_tick(self : ChandraCompositor) -> Unit {
|
||||
return
|
||||
}
|
||||
}
|
||||
match self.frame_recorder {
|
||||
Some(host) => {
|
||||
// The host holds the frame in flight.
|
||||
if rec.sent > 0 {
|
||||
let left = (host.send)(rec.fd)
|
||||
if left < 0 {
|
||||
self.stop_recording()
|
||||
return
|
||||
}
|
||||
if left > 0 {
|
||||
return
|
||||
}
|
||||
rec.sent = 0
|
||||
}
|
||||
if now < rec.next_at {
|
||||
return
|
||||
}
|
||||
rec.next_at = now + 33UL
|
||||
if (host.grab)(rec.rect, self.rec_pointer, self.ptr_x.to_int(), self.ptr_y.to_int()) {
|
||||
rec.sent = 1 // a frame is waiting on the host
|
||||
rec.frames = rec.frames + 1
|
||||
}
|
||||
self.damage.mark_full()
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
// The frame in flight.
|
||||
while rec.sent < rec.pending.length() {
|
||||
let len = (rec.pending.length() - rec.sent).min(1 << 20)
|
||||
|
||||
Reference in new issue
Block a user