- scripts/test-native.py (just t WORD): builds once, runs each test in its own process in parallel, longest first, with a timeout; CI and just test use it. - Tests no longer search this machine's apps and icon themes. - Compiled wasm modules are cached between test processes (CHANDRA_WASM_CACHE). - draw_circle fills its middle with spans (same pixels); encode_png writes into one buffer, with a CRC table. - The ffprobe helper always waited out its 20 s: its done file was empty. - The fake polkit helper no longer depends on which shell sh is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
179 lines
7.0 KiB
MoonBit
179 lines
7.0 KiB
MoonBit
///| The old per-pixel fill, kept as the reference the span-based fill must match exactly.
|
|
fn reference_fill(dst : Pixmap, rect : @scene.Rect, color : @scene.Rgba, radius : Int, clip : @scene.Rect?) -> Unit {
|
|
let x0 = if rect.x < 0 { 0 } else { rect.x }
|
|
let y0 = if rect.y < 0 { 0 } else { rect.y }
|
|
let x1 = if rect.x + rect.w > dst.width { dst.width } else { rect.x + rect.w }
|
|
let y1 = if rect.y + rect.h > dst.height { dst.height } else { rect.y + rect.h }
|
|
for y = y0; y < y1; y = y + 1 {
|
|
for x = x0; x < x1; x = x + 1 {
|
|
if radius == 0 || in_rounded_rect(x, y, rect.x, rect.y, rect.w, rect.h, radius) {
|
|
blend_pixel(dst, x, y, color.r.to_int(), color.g.to_int(), color.b.to_int(), color.a.to_int(), clip)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "span-based rounded fills match the per-pixel reference" {
|
|
let rects = [
|
|
(0, 0, 40, 30), (5, 7, 33, 21), (-6, -4, 30, 20), (30, 20, 40, 30), (10, 10, 3, 3),
|
|
(2, 2, 1, 9), (12, 3, 26, 2), (-10, 15, 80, 8), (20, 5, 7, 40),
|
|
]
|
|
let colors = [
|
|
@scene.Rgba::new(200, 40, 90, 255), @scene.Rgba::new(10, 200, 120, 128), @scene.Rgba::new(255, 255, 255, 17),
|
|
]
|
|
let clips : Array[@scene.Rect?] = [None, Some(@scene.Rect::new(8, 6, 25, 20)), Some(@scene.Rect::new(-5, -5, 20, 20))]
|
|
for rc in rects {
|
|
for radius in [0, 1, 4, 9, 40] {
|
|
for col in colors {
|
|
for clip in clips {
|
|
let a = Pixmap::new(64, 48)
|
|
let b = Pixmap::new(64, 48)
|
|
for i = 0; i < a.data.length(); i = i + 1 {
|
|
let v = ((i * 37 + 11) % 251).to_byte()
|
|
a.data[i] = v
|
|
b.data[i] = v
|
|
}
|
|
let r = @scene.Rect::new(rc.0, rc.1, rc.2, rc.3)
|
|
fill_rounded_rect(a, r, col, radius, clip)
|
|
if col.a.to_int() > 0 {
|
|
reference_fill(b, r, col, radius, clip)
|
|
}
|
|
assert_eq(a.data, b.data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "blitting a client buffer blends premultiplied alpha per pixel, even partly off screen" {
|
|
let w = 20
|
|
let h = 12
|
|
let bytes = FixedArray::make(w * h * 4, b'\x00')
|
|
for i = 0; i < bytes.length(); i = i + 1 {
|
|
bytes[i] = ((i * 53 + 7) % 256).to_byte()
|
|
}
|
|
let raw = Bytes::from_fixedarray(bytes)
|
|
for format in [0, 1] {
|
|
for pos in [(0, 0), (5, 4), (-7, -3), (50, 40), (60, 30)] {
|
|
let buf : @scene.ShmBufferSnapshot = { width: w, height: h, stride: w * 4, format, bytes: raw, host_id: 0U }
|
|
let a = Pixmap::new(64, 48)
|
|
let b = Pixmap::new(64, 48)
|
|
for i = 0; i < a.data.length(); i = i + 1 {
|
|
a.data[i] = ((i * 29 + 3) % 253).to_byte()
|
|
b.data[i] = a.data[i]
|
|
}
|
|
blit_shm_surface(a, buf, @scene.Rect::new(pos.0, pos.1, w, h))
|
|
for row = 0; row < h; row = row + 1 {
|
|
for col = 0; col < w; col = col + 1 {
|
|
let o = row * w * 4 + col * 4
|
|
let al = if format == 1 { 255 } else { raw[o + 3].to_int() }
|
|
let x = pos.0 + col
|
|
let y = pos.1 + row
|
|
if x < 0 || y < 0 || x >= 64 || y >= 48 || al == 0 {
|
|
continue
|
|
}
|
|
let d = (y * 64 + x) * 4
|
|
let inv = 255 - al
|
|
for k in [0, 1, 2] {
|
|
let s = raw[o + 2 - k].to_int()
|
|
let v = if al >= 255 { s } else { s + (b.data[d + k].to_int() * inv + 127) / 255 }
|
|
b.data[d + k] = v.clamp(min=0, max=255).to_byte()
|
|
}
|
|
b.data[d + 3] = if al >= 255 { b'\xff' } else { (al + (b.data[d + 3].to_int() * inv + 127) / 255).clamp(min=0, max=255).to_byte() }
|
|
}
|
|
}
|
|
assert_eq(a.data, b.data)
|
|
}
|
|
}
|
|
}
|
|
|
|
///| The old per-pixel stroke, as the reference for the span-based one.
|
|
fn reference_stroke(dst : Pixmap, rect : @scene.Rect, color : @scene.Rgba, width : Int, radius : Int, clip : @scene.Rect?) -> Unit {
|
|
let x0 = if rect.x < 0 { 0 } else { rect.x }
|
|
let y0 = if rect.y < 0 { 0 } else { rect.y }
|
|
let x1 = if rect.x + rect.w > dst.width { dst.width } else { rect.x + rect.w }
|
|
let y1 = if rect.y + rect.h > dst.height { dst.height } else { rect.y + rect.h }
|
|
let inner_x = rect.x + width
|
|
let inner_y = rect.y + width
|
|
let inner_w = rect.w - width * 2
|
|
let inner_h = rect.h - width * 2
|
|
let inner_r = if radius > width { radius - width } else { 0 }
|
|
for y = y0; y < y1; y = y + 1 {
|
|
for x = x0; x < x1; x = x + 1 {
|
|
let in_outer = in_rounded_rect(x, y, rect.x, rect.y, rect.w, rect.h, radius)
|
|
let in_inner = inner_w > 0 && inner_h > 0 && in_rounded_rect(x, y, inner_x, inner_y, inner_w, inner_h, inner_r)
|
|
if in_outer && !in_inner {
|
|
blend_pixel(dst, x, y, color.r.to_int(), color.g.to_int(), color.b.to_int(), color.a.to_int(), clip)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "span-based strokes match the per-pixel reference" {
|
|
let rects = [(0, 0, 40, 30), (5, 7, 33, 21), (-6, -4, 30, 20), (30, 20, 40, 30), (2, 2, 5, 5), (3, 3, 2, 9), (-10, 15, 80, 8), (10, 2, 20, 44)]
|
|
let colors = [@scene.Rgba::new(200, 40, 90, 255), @scene.Rgba::new(10, 200, 120, 128)]
|
|
let clips : Array[@scene.Rect?] = [None, Some(@scene.Rect::new(8, 6, 25, 20)), Some(@scene.Rect::new(-5, -5, 20, 20))]
|
|
for rc in rects {
|
|
for radius in [0, 1, 4, 9, 40] {
|
|
for width in [1, 2, 3, 7] {
|
|
for col in colors {
|
|
for clip in clips {
|
|
let a = Pixmap::new(64, 48)
|
|
let b = Pixmap::new(64, 48)
|
|
for i = 0; i < a.data.length(); i = i + 1 {
|
|
let v = ((i * 41 + 5) % 251).to_byte()
|
|
a.data[i] = v
|
|
b.data[i] = v
|
|
}
|
|
let r = @scene.Rect::new(rc.0, rc.1, rc.2, rc.3)
|
|
stroke_rounded_rect(a, r, col, width, radius, clip)
|
|
reference_stroke(b, r, col, width, radius, clip)
|
|
assert_eq(a.data, b.data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///|
|
|
/// What draw_circle must look like: the coverage of every pixel on its own, no spans.
|
|
fn plain_circle(dst : Pixmap, cx : Int, cy : Int, radius : Int, c : @scene.Rgba, filled : Bool, clip : @scene.Rect?) -> Unit {
|
|
for dy = -radius - 1; dy <= radius + 1; dy = dy + 1 {
|
|
for dx = -radius - 1; dx <= radius + 1; dx = dx + 1 {
|
|
let d = (dx * dx + dy * dy).to_double().sqrt()
|
|
let mut cov = (radius.to_double() + 0.5 - d).min(1.0)
|
|
if !filled {
|
|
cov = cov.min((d - (radius.to_double() - 1.5)).min(1.0))
|
|
}
|
|
if cov > 0.02 {
|
|
let a = (c.a.to_int().to_double() * cov).round().to_int()
|
|
blend_pixel(dst, cx + dx, cy + dy, c.r.to_int(), c.g.to_int(), c.b.to_int(), a, clip)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "draw_circle's spans give the same pixels as one at a time" {
|
|
for radius in [1, 2, 3, 7, 20, 33] {
|
|
for at in [(20, 15), (-3, 4), (38, 29)] {
|
|
for alpha in [b'\xff', b'\x50'] {
|
|
for filled in [true, false] {
|
|
for clip in [None, Some(@scene.Rect::new(5, 6, 20, 13))] {
|
|
let c : @scene.Rgba = { r: b'\xd0', g: b'\x40', b: b'\x11', a: alpha }
|
|
let one = Pixmap::new(40, 30)
|
|
let two = Pixmap::new(40, 30)
|
|
draw_circle(one, at.0, at.1, radius, c, filled, clip)
|
|
plain_circle(two, at.0, at.1, radius, c, filled, clip)
|
|
assert_true(one.data == two.data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|