The switcher is now a grid of cards: a scaled-down picture of each window's last frame over its app icon and title, the selected card lit. Cards wrap into rows and shrink to fit small screens. - Previews keep the buffer's aspect ratio and are never enlarged. - Minimized windows show the last frame they drew, dimmed, marked "minimized". A window with no buffer yet shows its app icon (or its initial) on a plain tile. - Cheap: nothing is scaled while the switcher is closed. A preview is made when the switcher opens and again only when that window commits a new buffer (or its shown size changes), into the same image handle; handles of closed windows are reused. The native scaler samples at most 3x3 points per preview pixel, so big windows cost about the same as small. - Both hosts: native scales the wl_shm snapshot in the software renderer (renderer.shm_thumbnail + set_image); the wasm compositor asks the host with the new chandra:host/raster thumbnail(surface, w, h, reuse), which scales the captured surface natively, so no pixels cross the boundary. - Frames the screenshot overlay held back mark previews stale too. Tests: switcher_test (preview pixels, aspect, no-buffer, stale and remade into the same handle, minimized), renderer shm_thumbnail/set_image, host-wasm thumbnail scaling and handle reuse. Pre-existing failures on main are unchanged (6 panel-module host tests, the screenshot panel module test, host-wasm translucent_surfaces_blend). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjDvAsSQUdTTUGA3n5
This commit is contained in:
16 files changed
+528
-50
No files matched your search
@@ -373,6 +373,10 @@ impl chandra::host::raster::Host for State {
|
||||
self.raster.images.load(&path)
|
||||
}
|
||||
|
||||
fn thumbnail(&mut self, surface: u32, w: i32, h: i32, reuse: u32) -> u32 {
|
||||
self.raster.thumbnail(surface, w, h, reuse)
|
||||
}
|
||||
|
||||
fn submit(&mut self, f: chandra::host::raster::Frame) {
|
||||
self.raster.submit(&f, &mut self.fonts);
|
||||
}
|
||||
|
||||
@@ -548,6 +548,19 @@ impl Images {
|
||||
h
|
||||
}
|
||||
|
||||
/// Store `w` x `h` RGBA pixels as an image: overwrite `reuse` when it is a handle from an earlier
|
||||
/// call (its cached sizes are dropped), else add a new one. Returns the handle.
|
||||
pub fn put_pixels(&mut self, reuse: u32, w: i32, h: i32, rgba: Vec<u8>) -> u32 {
|
||||
let src = ImageSrc::Pixels { w, h, rgba };
|
||||
if reuse > 0 && (reuse as usize) <= self.srcs.len() && !self.by_path.values().any(|&v| v == reuse) {
|
||||
self.srcs[reuse as usize - 1] = src;
|
||||
self.sized.borrow_mut().retain(|k, _| k.0 != reuse);
|
||||
return reuse;
|
||||
}
|
||||
self.srcs.push(src);
|
||||
self.srcs.len() as u32
|
||||
}
|
||||
|
||||
/// Image `handle` at `w` x `h` (cached), or None for an unknown handle or a silly size.
|
||||
fn sized(&self, handle: u32, w: i32, h: i32) -> Option<Rc<Vec<u8>>> {
|
||||
if w <= 0 || h <= 0 || w > MAX_IMAGE || h > MAX_IMAGE {
|
||||
@@ -711,6 +724,17 @@ impl Raster {
|
||||
self.surfaces.remove(&id);
|
||||
}
|
||||
|
||||
/// A `w` x `h` scaled copy of surface `id` as an image (see `Images::put_pixels` for `reuse`).
|
||||
/// 0 for an unknown surface or a silly size.
|
||||
pub fn thumbnail(&mut self, id: u32, w: i32, h: i32, reuse: u32) -> u32 {
|
||||
if w <= 0 || h <= 0 || w > MAX_IMAGE || h > MAX_IMAGE {
|
||||
return 0;
|
||||
}
|
||||
let Some(s) = self.surfaces.get(&id) else { return 0 };
|
||||
let px = scale_rgba(&s.rgba, s.w, s.h, w, h);
|
||||
self.images.put_pixels(reuse, w, h, px)
|
||||
}
|
||||
|
||||
pub fn surface_count(&self) -> usize {
|
||||
self.surfaces.len()
|
||||
}
|
||||
@@ -953,6 +977,32 @@ mod tests {
|
||||
assert_eq!(&r.to_argb8888()[..4], &[3, 2, 1, 255]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thumbnails_scale_a_surface_and_reuse_their_handle() {
|
||||
let mut r = Raster::default();
|
||||
// A 4x2 surface: left half red, right half blue (BGRA in, RGBA out).
|
||||
let mut src = Vec::new();
|
||||
for _ in 0..2 {
|
||||
for x in 0..4 {
|
||||
src.extend_from_slice(if x < 2 { &[0, 0, 255, 255] } else { &[255, 0, 0, 255] });
|
||||
}
|
||||
}
|
||||
let s = r.add_surface(Surface::from_bgra(&src, 16, 4, 2, true).unwrap());
|
||||
assert_eq!(r.thumbnail(999, 2, 1, 0), 0);
|
||||
assert_eq!(r.thumbnail(s, 0, 1, 0), 0);
|
||||
let t = r.thumbnail(s, 2, 1, 0);
|
||||
assert_ne!(t, 0);
|
||||
r.submit(&wt::Frame { panel: vec![wt::Op::DrawImage(wt::Picture { area: rect(0, 0, 2, 1), image: t })], ..frame(4, 4) }, &mut Fonts::default());
|
||||
assert_eq!(px(&r, 0, 0), [255, 0, 0, 255]);
|
||||
assert_eq!(px(&r, 1, 0), [0, 0, 255, 255]);
|
||||
// Refreshing overwrites the same handle, and the old pixels are not served from the cache.
|
||||
let blue = [255u8, 0, 0, 255].repeat(8);
|
||||
let s2 = r.add_surface(Surface::from_bgra(&blue, 16, 4, 2, true).unwrap());
|
||||
assert_eq!(r.thumbnail(s2, 2, 1, t), t);
|
||||
r.submit(&wt::Frame { panel: vec![wt::Op::DrawImage(wt::Picture { area: rect(0, 0, 2, 1), image: t })], ..frame(4, 4) }, &mut Fonts::default());
|
||||
assert_eq!(px(&r, 0, 0), [0, 0, 255, 255]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn images_load_once_by_path_and_draw_scaled_png_and_svg() {
|
||||
let dir = std::env::temp_dir().join(format!("chandra-img-{}", std::process::id()));
|
||||
|
||||
Reference in new issue
Block a user