spikes/gpui: the GPUI spikes' workspace, environment and meter
Plan section 6 step 1. A Cargo workspace of its own under spikes/gpui (own lock, not a member of the root workspace, so the root's lock, deny policy, notices and CI are untouched; it builds into the checkout's target/), on gpui-kit pinned to =0.8.0. No gpui-kit release builds on Rust 1.94 (every gpui-pre 0.3.x calls std::hint::cold_path, stable since 1.95), so the workspace says rust-version 1.95. - shell.sh: the toolchain (1.95.0, 1.94, stable or nightly, all from one pinned fenix), the native libraries, Mesa's lavapipe as the only Vulkan driver, Xvfb, openbox and the X tools, Noto Color Emoji and Noto Sans CJK. - headless.sh: a private Xvfb display with openbox and a private session bus, never the desktop's; headless-wayland.sh: sway's headless backend. - spike-common: CPU by thread group and memory from /proc once a second with the spike's counters (meter), proc-meter and damage-count for programs without a meter (the Slint app), Inter and the emoji/CJK fonts, the client's Lucide icons as GPUI assets, and the BGRA twin of voelin_media::convert::to_rgba. From the interrupted 2026-10-25 attempt, kept; changed here: shell.sh takes 1.94 and nightly from the pinned fenix (the store paths it named were garbage-collected), the README's headless-wayland.sh paragraph (sway, not weston), its fmt command (-p, not --all), its toolchain and nixpkgs lines, and the font docs (GPUI drops Noto Color Emoji from a fallback chain). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3930ef2945
commit
c9859bcfb4
15 files changed
+10058
No files matched your search
@@ -0,0 +1,134 @@
|
||||
//! Frames as BGRA, the byte order GPUI's `RenderImage` holds: the BGRA twin
|
||||
//! of `voelin_media::convert::to_rgba` (the same `yuv` calls with the
|
||||
//! channels swapped, BT.601 limited range), and the picture GPUI shows.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui_kit::RenderImage;
|
||||
use voelin_media::frame::{FrameRef, PixelsRef, VideoFrame};
|
||||
use yuv::{YuvBiPlanarImage, YuvConversionMode, YuvPlanarImage, YuvRange, YuvStandardMatrix};
|
||||
|
||||
const RANGE: YuvRange = YuvRange::Limited;
|
||||
const MATRIX: YuvStandardMatrix = YuvStandardMatrix::Bt601;
|
||||
|
||||
fn u32_of(n: usize) -> Result<u32, String> {
|
||||
u32::try_from(n).map_err(|_| format!("{n} does not fit a stride"))
|
||||
}
|
||||
|
||||
/// Write `frame` as BGRA (alpha 255) into `out`, `stride` bytes per row.
|
||||
pub fn to_bgra(frame: &VideoFrame, out: &mut [u8], stride: usize) -> Result<(), String> {
|
||||
to_bgra_ref(&frame.view(), out, stride)
|
||||
}
|
||||
|
||||
/// [`to_bgra`] of a borrowed frame; allocates nothing.
|
||||
pub fn to_bgra_ref(frame: &FrameRef<'_>, out: &mut [u8], stride: usize) -> Result<(), String> {
|
||||
frame.validate().map_err(|e| e.to_string())?;
|
||||
let (w, h) = (frame.width, frame.height);
|
||||
let row = w as usize * 4;
|
||||
if stride < row || out.len() < stride * (h as usize - 1) + row {
|
||||
return Err(format!("BGRA output of {} bytes is too small for {w}x{h}", out.len()));
|
||||
}
|
||||
let out_stride = u32_of(stride)?;
|
||||
match &frame.pixels {
|
||||
PixelsRef::I420 { y, u, v } => {
|
||||
let image = YuvPlanarImage {
|
||||
y_plane: y.data,
|
||||
y_stride: u32_of(y.stride)?,
|
||||
u_plane: u.data,
|
||||
u_stride: u32_of(u.stride)?,
|
||||
v_plane: v.data,
|
||||
v_stride: u32_of(v.stride)?,
|
||||
width: w,
|
||||
height: h,
|
||||
};
|
||||
yuv::yuv420_to_bgra(&image, out, out_stride, RANGE, MATRIX).map_err(|e| e.to_string())
|
||||
}
|
||||
PixelsRef::Nv12 { y, uv } => {
|
||||
let image = YuvBiPlanarImage {
|
||||
y_plane: y.data,
|
||||
y_stride: u32_of(y.stride)?,
|
||||
uv_plane: uv.data,
|
||||
uv_stride: u32_of(uv.stride)?,
|
||||
width: w,
|
||||
height: h,
|
||||
};
|
||||
yuv::yuv_nv12_to_bgra(
|
||||
&image,
|
||||
out,
|
||||
out_stride,
|
||||
RANGE,
|
||||
MATRIX,
|
||||
YuvConversionMode::Balanced,
|
||||
)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
PixelsRef::Bgra(p) => {
|
||||
for y in 0..h as usize {
|
||||
out[y * stride..y * stride + row].copy_from_slice(p.row(y, row));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
PixelsRef::Rgba(p) => {
|
||||
for y in 0..h as usize {
|
||||
let (src, dst) = (p.row(y, row), &mut out[y * stride..y * stride + row]);
|
||||
for (d, s) in dst.chunks_exact_mut(4).zip(src.chunks_exact(4)) {
|
||||
d.copy_from_slice(&[s[2], s[1], s[0], 255]);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The pixels as GPUI's image: one frame, BGRA, `width * 4` bytes per row.
|
||||
pub fn render_image(width: u32, height: u32, bgra: Vec<u8>) -> Arc<RenderImage> {
|
||||
let buffer = image::RgbaImage::from_raw(width, height, bgra).expect("a buffer of the size");
|
||||
Arc::new(RenderImage::new([image::Frame::new(buffer)]))
|
||||
}
|
||||
|
||||
/// `frame` converted into a new picture.
|
||||
pub fn picture(frame: &VideoFrame) -> Result<Arc<RenderImage>, String> {
|
||||
let stride = frame.width as usize * 4;
|
||||
let mut bgra = vec![0u8; stride * frame.height as usize];
|
||||
to_bgra(frame, &mut bgra, stride)?;
|
||||
Ok(render_image(frame.width, frame.height, bgra))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use voelin_media::capture::synthetic::{Pattern, SyntheticScreen};
|
||||
use voelin_media::convert;
|
||||
|
||||
/// BGRA is RGBA with red and blue swapped, pixel for pixel, for I420 and
|
||||
/// for packed input.
|
||||
#[test]
|
||||
fn bgra_is_rgba_swapped() {
|
||||
let picture = SyntheticScreen::with_pattern(64, 36, Pattern::Desktop).frame(3, 30);
|
||||
let i420 = convert::to_i420(&picture).unwrap().into_owned();
|
||||
let rgba_in =
|
||||
VideoFrame::from_rgba(64, 36, 64 * 4, convert::to_rgba_vec(&picture).unwrap()).unwrap();
|
||||
for frame in [&picture, &i420, &rgba_in] {
|
||||
let mut rgba = vec![0; 64 * 36 * 4];
|
||||
let mut bgra = vec![0; 64 * 36 * 4];
|
||||
convert::to_rgba(frame, &mut rgba, 64 * 4).unwrap();
|
||||
to_bgra(frame, &mut bgra, 64 * 4).unwrap();
|
||||
for (r, b) in rgba.chunks_exact(4).zip(bgra.chunks_exact(4)) {
|
||||
assert_eq!([r[2], r[1], r[0], r[3]], b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn small_output_is_refused() {
|
||||
let picture = SyntheticScreen::new(32, 32).frame(0, 30);
|
||||
assert!(to_bgra(&picture, &mut [0; 16], 32 * 4).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pictures_have_the_frame_size() {
|
||||
let picture = SyntheticScreen::new(40, 20).frame(0, 30);
|
||||
let image = super::picture(&picture).unwrap();
|
||||
assert_eq!((image.size(0).width.0, image.size(0).height.0), (40, 20));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user