Faster busy-client frames: read only the buffer's bytes, cache the wallpaper, cheaper strokes
CI / test (push) Failing after 18s
CI / test (push) Failing after 18s
Profiling a full-screen terminal at 1080p (about 2 fps): - snapshot_shm_buffer asked the host to copy the pool from byte 0 to the end of the buffer; foot puts its buffers deep in a ~135 MB pool, so every commit moved ~135 MB (~185 ms). New sys.mmap-read-at(fd, offset, len) copies just the buffer: step 200 ms -> 5 ms per frame. - The wallpaper (gradient + discs) is rendered once and copied back each frame while unchanged; it is split from the desktop card, which changes every second. - stroke_rounded_rect walked every pixel of the window to draw a 1px outline; it now only draws the border strips (exact per-pixel path kept for the corner bands). - Window shadows only blend the strips that stick out from under the window. Rasteriser: ~256 ms -> ~93 ms per full-screen frame. Tests compare strokes and fills with the old per-pixel code, and check the wallpaper cache. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
70ad87f2d2
commit
66bf293085
21 files changed
+302
-136
No files matched your search
@@ -252,17 +252,29 @@ fn stroke_rounded_rect(
|
||||
let inner_w = rect.w - width * 2
|
||||
let inner_h = rect.h - width * 2
|
||||
let inner_r = if radius > width { radius - width } else { 0 }
|
||||
// Visible columns and rows after the clip, for the span path below.
|
||||
let (cx0, cx1, cy0, cy1) = match clip {
|
||||
Some(c) => (c.x, c.x + c.w, c.y, c.y + c.h)
|
||||
None => (0, dst.width, 0, dst.height)
|
||||
}
|
||||
// Rows where the inner rectangle is full width (clear of its rounded corners) only have the
|
||||
// two side strips to draw; every pixel between them is the interior. The other rows (the top
|
||||
// and bottom bands) take the exact per-pixel test.
|
||||
let mid_a = inner_y + inner_r
|
||||
let mid_b = inner_y + inner_h - inner_r
|
||||
for y = y0; y < y1; y = y + 1 {
|
||||
if inner_w > 0 && inner_h > 0 && y >= mid_a && y < mid_b {
|
||||
if y >= cy0 && y < cy1 {
|
||||
let l0 = if x0 > cx0 { x0 } else { cx0 }
|
||||
let l1 = if inner_x < x1 { inner_x } else { x1 }
|
||||
blend_span(dst, y, l0, if l1 < cx1 { l1 } else { cx1 }, cr, cg, cb, ca)
|
||||
let r0 = if inner_x + inner_w > x0 { inner_x + inner_w } else { x0 }
|
||||
blend_span(dst, y, if r0 > cx0 { r0 } else { cx0 }, if x1 < cx1 { x1 } else { cx1 }, cr, cg, cb, ca)
|
||||
}
|
||||
continue
|
||||
}
|
||||
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_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)
|
||||
@@ -732,11 +744,26 @@ pub fn blit_shm_surface(
|
||||
}
|
||||
}
|
||||
|
||||
///| The last rendered wallpaper and the ops it was drawn from.
|
||||
let wallpaper_cache : Ref[(Array[@scene.DrawOp], Pixmap)?] = { val: None }
|
||||
|
||||
///|
|
||||
pub fn render_scene(scene : @scene.SceneGraph) -> Pixmap {
|
||||
let pixmap = Pixmap::new(scene.output_w, scene.output_h)
|
||||
|
||||
// 1. Background layer
|
||||
// 1. Background layer: the wallpaper is rendered once and copied while it is unchanged.
|
||||
if scene.wallpaper_ops.length() > 0 {
|
||||
match wallpaper_cache.val {
|
||||
Some((ops, cached)) if cached.width == pixmap.width && cached.height == pixmap.height && ops == scene.wallpaper_ops =>
|
||||
pixmap.data.unsafe_blit(0, cached.data, 0, cached.data.length())
|
||||
_ => {
|
||||
draw_ops(pixmap, scene.wallpaper_ops, 0, 0)
|
||||
let copy = Pixmap::new(pixmap.width, pixmap.height)
|
||||
copy.data.unsafe_blit(0, pixmap.data, 0, pixmap.data.length())
|
||||
wallpaper_cache.val = Some((scene.wallpaper_ops, copy))
|
||||
}
|
||||
}
|
||||
}
|
||||
draw_ops(pixmap, scene.background_ops, 0, 0)
|
||||
|
||||
// 2. Windows layer (bottom-to-top)
|
||||
@@ -748,14 +775,14 @@ pub fn render_scene(scene : @scene.SceneGraph) -> Pixmap {
|
||||
let outer_w = win.geometry.w + left + right
|
||||
let outer_h = win.geometry.h + top + bottom
|
||||
|
||||
// Subtle drop shadow
|
||||
fill_rounded_rect(
|
||||
pixmap,
|
||||
@scene.Rect::new(outer_x + 4, outer_y + 6, outer_w, outer_h),
|
||||
@scene.Rgba::new(0, 0, 0, 80),
|
||||
8,
|
||||
None,
|
||||
)
|
||||
// Subtle drop shadow. The window covers most of it, so only the strips that stick out
|
||||
// (right and bottom) are blended instead of the whole shadow rectangle.
|
||||
let shadow = @scene.Rect::new(outer_x + 4, outer_y + 6, outer_w, outer_h)
|
||||
let shadow_col = @scene.Rgba::new(0, 0, 0, 80)
|
||||
fill_rounded_rect(pixmap, shadow, shadow_col, 8, Some(@scene.Rect::new(outer_x + outer_w, outer_y, 4, outer_h + 6)))
|
||||
fill_rounded_rect(pixmap, shadow, shadow_col, 8, Some(@scene.Rect::new(outer_x, outer_y + outer_h, outer_w + 4, 6)))
|
||||
// The title bar is slightly translucent when unfocused, so keep the shadow under it.
|
||||
fill_rounded_rect(pixmap, shadow, shadow_col, 8, Some(@scene.Rect::new(outer_x, outer_y, outer_w, top + 2)))
|
||||
|
||||
// Breeze SSD decoration draw-ops
|
||||
draw_ops(pixmap, win.deco_ops, outer_x, outer_y)
|
||||
|
||||
Reference in new issue
Block a user