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
@@ -12,6 +12,69 @@ pub fn add_image(p : Pixmap) -> UInt {
|
||||
images.length().reinterpret_as_uint()
|
||||
}
|
||||
|
||||
///| Put `p` in place of image `handle` (from `add_image`), dropping its cached sizes; a handle that
|
||||
/// isn't one gets `p` added instead. Returns the handle `p` is under.
|
||||
pub fn set_image(handle : UInt, p : Pixmap) -> UInt {
|
||||
let i = handle.reinterpret_as_int() - 1
|
||||
if i < 0 || i >= images.length() {
|
||||
return add_image(p)
|
||||
}
|
||||
images[i] = p
|
||||
let stale = scaled.keys().filter(k => k.0 == handle).collect()
|
||||
for k in stale {
|
||||
scaled.remove(k)
|
||||
}
|
||||
handle
|
||||
}
|
||||
|
||||
///| A `w`x`h` preview of a client buffer (wl_shm ARGB8888/XRGB8888, little-endian B, G, R, A).
|
||||
/// Each target pixel averages a few points spread over the source pixels it covers (at most 3x3),
|
||||
/// so a big window costs about the same as a small one: this runs on commits while the Alt+Tab
|
||||
/// switcher is up, not once per source pixel.
|
||||
pub fn shm_thumbnail(buf : @scene.ShmBufferSnapshot, w : Int, h : Int) -> Pixmap? {
|
||||
if w <= 0 || h <= 0 || buf.width <= 0 || buf.height <= 0 || buf.stride < buf.width * 4 ||
|
||||
buf.bytes.length() < buf.stride * (buf.height - 1) + buf.width * 4 {
|
||||
return None
|
||||
}
|
||||
let out = Pixmap::new(w, h)
|
||||
let xrgb = buf.format == 1
|
||||
let src = buf.bytes
|
||||
for y = 0; y < h; y = y + 1 {
|
||||
let y0 = y * buf.height / h
|
||||
let y1 = { let e = (y + 1) * buf.height / h; if e > y0 { e } else { y0 + 1 } }
|
||||
let ny = if y1 - y0 < 3 { y1 - y0 } else { 3 }
|
||||
for x = 0; x < w; x = x + 1 {
|
||||
let x0 = x * buf.width / w
|
||||
let x1 = { let e = (x + 1) * buf.width / w; if e > x0 { e } else { x0 + 1 } }
|
||||
let nx = if x1 - x0 < 3 { x1 - x0 } else { 3 }
|
||||
let mut r = 0
|
||||
let mut g = 0
|
||||
let mut b = 0
|
||||
let mut a = 0
|
||||
for j = 0; j < ny; j = j + 1 {
|
||||
let sy = y0 + (y1 - y0) * (2 * j + 1) / (2 * ny)
|
||||
for i = 0; i < nx; i = i + 1 {
|
||||
let sx = x0 + (x1 - x0) * (2 * i + 1) / (2 * nx)
|
||||
let o = sy * buf.stride + sx * 4
|
||||
let pa = if xrgb { 255 } else { src[o + 3].to_int() }
|
||||
r = r + src[o + 2].to_int() * pa
|
||||
g = g + src[o + 1].to_int() * pa
|
||||
b = b + src[o].to_int() * pa
|
||||
a = a + pa
|
||||
}
|
||||
}
|
||||
let o = (y * w + x) * 4
|
||||
if a > 0 {
|
||||
out.data[o] = (r / a).to_byte()
|
||||
out.data[o + 1] = (g / a).to_byte()
|
||||
out.data[o + 2] = (b / a).to_byte()
|
||||
out.data[o + 3] = (a / (nx * ny)).to_byte()
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
///| Scale `src` to `w`x`h`: each target pixel averages the source pixels it covers (alpha
|
||||
/// weighted, so transparent edges don't darken), or takes the nearest one when enlarging.
|
||||
pub fn scale_pixmap(src : Pixmap, w : Int, h : Int) -> Pixmap {
|
||||
|
||||
@@ -24,8 +24,12 @@ pub fn render_scene(@scene.SceneGraph) -> Pixmap
|
||||
|
||||
pub fn scale_pixmap(Pixmap, Int32, Int32) -> Pixmap
|
||||
|
||||
pub fn set_image(UInt32, Pixmap) -> UInt32
|
||||
|
||||
pub fn set_glyph_source((Int32, Int32, Bool, Bool) -> Glyph) -> Unit
|
||||
|
||||
pub fn shm_thumbnail(@scene.ShmBufferSnapshot, Int32, Int32) -> Pixmap?
|
||||
|
||||
pub fn text_width(String, Int32, Bool, Bool) -> Int32
|
||||
|
||||
pub fn zlib_compress(FixedArray[Byte]) -> Array[Byte]
|
||||
|
||||
@@ -100,3 +100,40 @@ test "a compressed PNG is far smaller than the stored one for a desktop-like pic
|
||||
assert_eq(back.height, 200)
|
||||
assert_true(back.data == pm.data)
|
||||
}
|
||||
|
||||
///|
|
||||
test "shm_thumbnail scales a client buffer; set_image swaps an image in place" {
|
||||
// 4x2 XRGB buffer (B, G, R, X): left half red, right half blue.
|
||||
let px : Array[Byte] = []
|
||||
for _y = 0; _y < 2; _y = _y + 1 {
|
||||
for x = 0; x < 4; x = x + 1 {
|
||||
if x < 2 {
|
||||
px.push(b'\x00'); px.push(b'\x00'); px.push(b'\xff'); px.push(b'\x00')
|
||||
} else {
|
||||
px.push(b'\xff'); px.push(b'\x00'); px.push(b'\x00'); px.push(b'\x00')
|
||||
}
|
||||
}
|
||||
}
|
||||
let buf : @scene.ShmBufferSnapshot = { width: 4, height: 2, stride: 16, format: 1, bytes: Bytes::from_array(px), host_id: 0U }
|
||||
let t = @renderer.shm_thumbnail(buf, 2, 1).unwrap()
|
||||
assert_eq(t.pixel(0, 0), Some(@scene.Rgba::new(255, 0, 0, 255)))
|
||||
assert_eq(t.pixel(1, 0), Some(@scene.Rgba::new(0, 0, 255, 255)))
|
||||
// A buffer shorter than its stride says is refused, not read past.
|
||||
assert_true(@renderer.shm_thumbnail({ ..buf, bytes: Bytes::from_array(px[:20]) }, 2, 1) is None)
|
||||
let h = @renderer.set_image(0U, t)
|
||||
assert_true(h != 0U)
|
||||
let dst = @renderer.Pixmap::new(2, 1)
|
||||
@renderer.draw_ops(dst, [@scene.DrawOp::Image(@scene.Rect::new(0, 0, 2, 1), h)], 0, 0)
|
||||
assert_eq(dst.pixel(0, 0), Some(@scene.Rgba::new(255, 0, 0, 255)))
|
||||
// Swapped: the old size cached for the handle is not drawn again.
|
||||
assert_eq(@renderer.set_image(h, @renderer.shm_thumbnail(buf, 1, 1).unwrap()), h)
|
||||
let blue = @renderer.Pixmap::new(2, 1)
|
||||
for i = 0; i < 2; i = i + 1 {
|
||||
blue.data[i * 4 + 2] = b'\xff'
|
||||
blue.data[i * 4 + 3] = b'\xff'
|
||||
}
|
||||
ignore(@renderer.set_image(h, blue))
|
||||
let dst = @renderer.Pixmap::new(2, 1)
|
||||
@renderer.draw_ops(dst, [@scene.DrawOp::Image(@scene.Rect::new(0, 0, 2, 1), h)], 0, 0)
|
||||
assert_eq(dst.pixel(0, 0), Some(@scene.Rgba::new(0, 0, 255, 255)))
|
||||
}
|
||||
Reference in new issue
Block a user