refactor(vulkan): share fillRounded between hint, inner border and ring
- commit
- 06479663a2cc197a631e6954c1b2cc9e67eb890c
- author
- brice · · 2026-10-21 08:22 UTC
- parent
- 038e199
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +19 -17
M internal/adapters/vulkan/position_hint.go +1 -6
| @@ -42,10 +42,5 @@ func (w *sceneWalk) positionHint() { | |||
| 42 | 42 | // so alpha stays exact. | |
| 43 | 43 | func (w *sceneWalk) hintRound(r image.Rectangle, radius int, color [3]uint8) { | |
| 44 | 44 | radius = min(radius, r.Dx()/2, r.Dy()/2) | |
| 45 | - | n := len(w.draws) | |
| 46 | - | w.fill(r, color) | |
| 47 | - | if radius <= 0 || len(w.draws) == n { | |
| 48 | - | return | |
| 49 | - | } | |
| 50 | - | roundedDraw(&w.draws[n], r, float32(radius)) | |
| 45 | + | w.fillRounded(r, color, float32(radius)) | |
| 51 | 46 | } | |
| @@ -42,10 +42,5 @@ func (w *sceneWalk) positionHint() { | |||||
| 42 | // so alpha stays exact. | 42 | // so alpha stays exact. | ||
| 43 | func (w *sceneWalk) hintRound(r image.Rectangle, radius int, color [3]uint8) { | 43 | func (w *sceneWalk) hintRound(r image.Rectangle, radius int, color [3]uint8) { | ||
| 44 | radius = min(radius, r.Dx()/2, r.Dy()/2) | 44 | radius = min(radius, r.Dx()/2, r.Dy()/2) | ||
| 45 | - | n := len(w.draws) | 45 | + | w.fillRounded(r, color, float32(radius)) |
| 46 | - | w.fill(r, color) | |||
| 47 | - | if radius <= 0 || len(w.draws) == n { | |||
| 48 | - | return | |||
| 49 | - | } | |||
| 50 | - | roundedDraw(&w.draws[n], r, float32(radius)) | |||
| 51 | } | 46 | } | ||
M internal/adapters/vulkan/scene.go +18 -11
| @@ -92,14 +92,11 @@ func (w *sceneWalk) focusFlash() { | |||
| 92 | 92 | // radius, minus a hole inset by b with radius max(radius-b, 0). | |
| 93 | 93 | func (w *sceneWalk) roundedInnerBorder(t ports.Rect, b, radius int, col [3]uint8) { | |
| 94 | 94 | outer := w.physRect(t.X, t.Y, t.W, t.H) | |
| 95 | - | n := len(w.draws) | |
| 96 | - | w.fill(outer, col) | |
| 97 | - | if len(w.draws) == n { | |
| 95 | + | r := float32(math.Round(float64(radius) * w.scale)) | |
| 96 | + | dr := w.fillRounded(outer, col, r) | |
| 97 | + | if dr == nil { | |
| 98 | 98 | return | |
| 99 | 99 | } | |
| 100 | - | r := float32(math.Round(float64(radius) * w.scale)) | |
| 101 | - | dr := &w.draws[n] | |
| 102 | - | roundedDraw(dr, outer, r) | |
| 103 | 100 | dr.pc.misc[1] |= flagRing | |
| 104 | 101 | hole := w.physRect(t.X+b, t.Y+b, t.W-2*b, t.H-2*b) | |
| 105 | 102 | bPhys := min(hole.Min.X-outer.Min.X, hole.Min.Y-outer.Min.Y, outer.Max.X-hole.Max.X, outer.Max.Y-hole.Max.Y) | |
| @@ -196,6 +193,20 @@ func (w *sceneWalk) fill(rect image.Rectangle, c [3]uint8) { | |||
| 196 | 193 | w.draws = append(w.draws, dr) | |
| 197 | 194 | } | |
| 198 | 195 | ||
| 196 | + | // fillRounded is fill with rounded corners of radius (physical pixels). It | |
| 197 | + | // returns the new draw, or nil when fill emitted nothing or radius <= 0 (the | |
| 198 | + | // plain fill is kept). The pointer is valid only until the next append. | |
| 199 | + | func (w *sceneWalk) fillRounded(r image.Rectangle, c [3]uint8, radius float32) *draw { | |
| 200 | + | n := len(w.draws) | |
| 201 | + | w.fill(r, c) | |
| 202 | + | if len(w.draws) == n || radius <= 0 { | |
| 203 | + | return nil | |
| 204 | + | } | |
| 205 | + | dr := &w.draws[n] | |
| 206 | + | roundedDraw(dr, r, radius) | |
| 207 | + | return dr | |
| 208 | + | } | |
| 209 | + | ||
| 199 | 210 | // dim paints a translucent black quad over rect (physical), clipped to the | |
| 200 | 211 | // output, at alpha scaled by the walk's alpha. Damage clipping later limits | |
| 201 | 212 | // it to the region being repainted, just like other fills. | |
| @@ -293,11 +304,7 @@ func (w *sceneWalk) windows() { | |||
| 293 | 304 | bPhys := min(body.Min.X-outer.Min.X, body.Min.Y-outer.Min.Y, outer.Max.X-body.Max.X, outer.Max.Y-body.Max.Y) | |
| 294 | 305 | innerRadius = max(radius-float32(max(bPhys, 0)), 0) | |
| 295 | 306 | if col := w.ringColor(win.ID); col != "" && b > 0 { | |
| 296 | - | n := len(w.draws) | |
| 297 | - | w.fill(outer, parseColor(col)) | |
| 298 | - | if len(w.draws) > n { | |
| 299 | - | dr := &w.draws[n] | |
| 300 | - | roundedDraw(dr, outer, radius) | |
| 307 | + | if dr := w.fillRounded(outer, parseColor(col), radius); dr != nil { | |
| 301 | 308 | dr.pc.misc[1] |= flagRing | |
| 302 | 309 | // Opaque, the ring runs 1px under the body so no seam | |
| 303 | 310 | // shows; faded, that overlap would double up: the hole | |
| @@ -92,14 +92,11 @@ func (w *sceneWalk) focusFlash() { | |||||
| 92 | // radius, minus a hole inset by b with radius max(radius-b, 0). | 92 | // radius, minus a hole inset by b with radius max(radius-b, 0). | ||
| 93 | func (w *sceneWalk) roundedInnerBorder(t ports.Rect, b, radius int, col [3]uint8) { | 93 | func (w *sceneWalk) roundedInnerBorder(t ports.Rect, b, radius int, col [3]uint8) { | ||
| 94 | outer := w.physRect(t.X, t.Y, t.W, t.H) | 94 | outer := w.physRect(t.X, t.Y, t.W, t.H) | ||
| 95 | - | n := len(w.draws) | 95 | + | r := float32(math.Round(float64(radius) * w.scale)) |
| 96 | - | w.fill(outer, col) | 96 | + | dr := w.fillRounded(outer, col, r) |
| 97 | - | if len(w.draws) == n { | 97 | + | if dr == nil { |
| 98 | return | 98 | return | ||
| 99 | } | 99 | } | ||
| 100 | - | r := float32(math.Round(float64(radius) * w.scale)) | |||
| 101 | - | dr := &w.draws[n] | |||
| 102 | - | roundedDraw(dr, outer, r) | |||
| 103 | dr.pc.misc[1] |= flagRing | 100 | dr.pc.misc[1] |= flagRing | ||
| 104 | hole := w.physRect(t.X+b, t.Y+b, t.W-2*b, t.H-2*b) | 101 | hole := w.physRect(t.X+b, t.Y+b, t.W-2*b, t.H-2*b) | ||
| 105 | bPhys := min(hole.Min.X-outer.Min.X, hole.Min.Y-outer.Min.Y, outer.Max.X-hole.Max.X, outer.Max.Y-hole.Max.Y) | 102 | bPhys := min(hole.Min.X-outer.Min.X, hole.Min.Y-outer.Min.Y, outer.Max.X-hole.Max.X, outer.Max.Y-hole.Max.Y) | ||
| @@ -196,6 +193,20 @@ func (w *sceneWalk) fill(rect image.Rectangle, c [3]uint8) { | |||||
| 196 | w.draws = append(w.draws, dr) | 193 | w.draws = append(w.draws, dr) | ||
| 197 | } | 194 | } | ||
| 198 | 195 | ||||
| 196 | + | // fillRounded is fill with rounded corners of radius (physical pixels). It | |||
| 197 | + | // returns the new draw, or nil when fill emitted nothing or radius <= 0 (the | |||
| 198 | + | // plain fill is kept). The pointer is valid only until the next append. | |||
| 199 | + | func (w *sceneWalk) fillRounded(r image.Rectangle, c [3]uint8, radius float32) *draw { | |||
| 200 | + | n := len(w.draws) | |||
| 201 | + | w.fill(r, c) | |||
| 202 | + | if len(w.draws) == n || radius <= 0 { | |||
| 203 | + | return nil | |||
| 204 | + | } | |||
| 205 | + | dr := &w.draws[n] | |||
| 206 | + | roundedDraw(dr, r, radius) | |||
| 207 | + | return dr | |||
| 208 | + | } | |||
| 209 | + | ||||
| 199 | // dim paints a translucent black quad over rect (physical), clipped to the | 210 | // dim paints a translucent black quad over rect (physical), clipped to the | ||
| 200 | // output, at alpha scaled by the walk's alpha. Damage clipping later limits | 211 | // output, at alpha scaled by the walk's alpha. Damage clipping later limits | ||
| 201 | // it to the region being repainted, just like other fills. | 212 | // it to the region being repainted, just like other fills. | ||
| @@ -293,11 +304,7 @@ func (w *sceneWalk) windows() { | |||||
| 293 | bPhys := min(body.Min.X-outer.Min.X, body.Min.Y-outer.Min.Y, outer.Max.X-body.Max.X, outer.Max.Y-body.Max.Y) | 304 | bPhys := min(body.Min.X-outer.Min.X, body.Min.Y-outer.Min.Y, outer.Max.X-body.Max.X, outer.Max.Y-body.Max.Y) | ||
| 294 | innerRadius = max(radius-float32(max(bPhys, 0)), 0) | 305 | innerRadius = max(radius-float32(max(bPhys, 0)), 0) | ||
| 295 | if col := w.ringColor(win.ID); col != "" && b > 0 { | 306 | if col := w.ringColor(win.ID); col != "" && b > 0 { | ||
| 296 | - | n := len(w.draws) | 307 | + | if dr := w.fillRounded(outer, parseColor(col), radius); dr != nil { |
| 297 | - | w.fill(outer, parseColor(col)) | |||
| 298 | - | if len(w.draws) > n { | |||
| 299 | - | dr := &w.draws[n] | |||
| 300 | - | roundedDraw(dr, outer, radius) | |||
| 301 | dr.pc.misc[1] |= flagRing | 308 | dr.pc.misc[1] |= flagRing | ||
| 302 | // Opaque, the ring runs 1px under the body so no seam | 309 | // Opaque, the ring runs 1px under the body so no seam | ||
| 303 | // shows; faded, that overlap would double up: the hole | 310 | // shows; faded, that overlap would double up: the hole | ||