CI / test (push) Failing after 19s
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
140 lines
5.1 KiB
MoonBit
140 lines
5.1 KiB
MoonBit
///|
|
|
test "software renderer alpha blending, rounded rect, shm blit, and png encoding" {
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let scene = @scene.SceneGraph::new(320, 200)
|
|
let (bg, panel) = @scene.build_shell_ops(
|
|
320,
|
|
200,
|
|
theme,
|
|
"BSP Tiling",
|
|
["MoonTerm"],
|
|
)
|
|
scene.background_ops = bg
|
|
scene.panel_ops = panel
|
|
|
|
let (insets, deco_ops) = @scene.build_breeze_decoration(
|
|
"MoonTerm",
|
|
"org.chandra.term",
|
|
true,
|
|
false,
|
|
200,
|
|
120,
|
|
theme,
|
|
)
|
|
// 100x60 ARGB8888 cyan buffer
|
|
let buf_bytes : Array[Byte] = Array(capacity=100 * 60 * 4)
|
|
for _i = 0; _i < 100 * 60; _i = _i + 1 {
|
|
buf_bytes.push(b'\xf8') // B
|
|
buf_bytes.push(b'\xbd') // G
|
|
buf_bytes.push(b'\x38') // R
|
|
buf_bytes.push(b'\xff') // A
|
|
}
|
|
scene.windows.push({
|
|
id: 1UL,
|
|
title: "MoonTerm",
|
|
app_id: "org.chandra.term",
|
|
focused: true,
|
|
fullscreen: false,
|
|
geometry: @scene.Rect::new(20, 40, 100, 60),
|
|
deco_insets: insets,
|
|
deco_ops,
|
|
surface: Some({
|
|
width: 100,
|
|
height: 60,
|
|
stride: 400,
|
|
format: 0,
|
|
bytes: Bytes::from_array(buf_bytes),
|
|
host_id: 0U,
|
|
}),
|
|
})
|
|
|
|
let pm = @renderer.render_scene(scene)
|
|
assert_eq(pm.pixel(70, 70), Some(@scene.Rgba::new(0x38, 0xbd, 0xf8, 0xff)))
|
|
let png = @renderer.encode_png(pm)
|
|
assert_eq(png[0], b'\x89')
|
|
assert_eq(png[1], b'\x50')
|
|
assert_eq(png[2], b'\x4e')
|
|
assert_eq(png[3], b'\x47')
|
|
let ppm = @renderer.encode_ppm(pm)
|
|
assert_eq(ppm[0], b'\x50') // 'P'
|
|
assert_eq(ppm[1], b'\x36') // '6'
|
|
}
|
|
|
|
///|
|
|
test "a cached wallpaper renders the same pixels, and a changed one is redrawn" {
|
|
let mk = fn(col : @scene.Rgba) {
|
|
let sg = @scene.SceneGraph::new(64, 48)
|
|
sg.wallpaper_ops = [@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, 64, 48), col, 0)]
|
|
sg.background_ops = [@scene.DrawOp::FillRect(@scene.Rect::new(4, 4, 10, 10), @scene.Rgba::new(255, 0, 0, 255), 0)]
|
|
sg
|
|
}
|
|
let a = render_scene(mk(@scene.Rgba::new(10, 20, 30, 255)))
|
|
let b = render_scene(mk(@scene.Rgba::new(10, 20, 30, 255))) // served from the cache
|
|
assert_eq(a.data, b.data)
|
|
assert_eq(b.pixel(30, 30).unwrap().g.to_int(), 20)
|
|
assert_eq(b.pixel(6, 6).unwrap().r.to_int(), 255) // what is drawn over it still shows
|
|
let c = render_scene(mk(@scene.Rgba::new(90, 80, 70, 255)))
|
|
assert_eq(c.pixel(30, 30).unwrap().g.to_int(), 80)
|
|
// Changing the size does not reuse the old pixels.
|
|
let sg = @scene.SceneGraph::new(32, 32)
|
|
sg.wallpaper_ops = [@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, 32, 32), @scene.Rgba::new(10, 20, 30, 255), 0)]
|
|
assert_eq(render_scene(sg).width, 32)
|
|
}
|
|
|
|
///|
|
|
test "a compressed PNG is far smaller than the stored one for a desktop-like picture" {
|
|
let pm = @renderer.Pixmap::new(320, 200)
|
|
@renderer.draw_ops(pm, [
|
|
@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, 320, 200), @scene.Rgba::new(20, 30, 60, 255), 0),
|
|
@scene.DrawOp::FillRect(@scene.Rect::new(20, 20, 200, 120), @scene.Rgba::new(240, 240, 240, 255), 8),
|
|
@scene.DrawOp::Line(0, 199, 319, 0, @scene.Rgba::new(255, 0, 0, 255), 2),
|
|
], 0, 0)
|
|
let plain = @renderer.encode_png(pm)
|
|
let packed = @renderer.encode_png_compressed(pm)
|
|
assert_eq(packed[0], b'\x89')
|
|
assert_eq(packed[1], b'\x50')
|
|
assert_true(packed.length() * 10 < plain.length())
|
|
// It decodes back to the same pixels.
|
|
let back = @renderer.decode_png(packed).unwrap()
|
|
assert_eq(back.width, 320)
|
|
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)))
|
|
}
|