mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
internal/stroke, gpu: reuse slice when splitting cubics
When building GPU vertices from paths, we call stroke.SplitCubic once per OpCubic. Before this change, each call to stroke.SplitCubic would allocate a slice, which we would only use to iterate over. This allocation can be easily avoided by reusing the slice. We can conveniently store it in gpu.quadSplitter. In a real application that renders hundreds of paths with tens of rounded rectangles per path, this saved roughly 4500 allocations (or 1 MB worth) per frame. Signed-off-by: Dominik Honnef <dominik@honnef.co>
This commit is contained in:
committed by
Elias Naur
parent
90e57c2b18
commit
b183774063
+3
-1
@@ -1327,7 +1327,9 @@ func decodeToOutlineQuads(qs *quadSplitter, tr f32.Affine2D, pathData []byte) {
|
||||
q = q.Transform(tr)
|
||||
qs.splitAndEncode(q)
|
||||
case scene.OpCubic:
|
||||
for _, q := range stroke.SplitCubic(scene.DecodeCubic(cmd)) {
|
||||
from, ctrl0, ctrl1, to := scene.DecodeCubic(cmd)
|
||||
qs.scratch = stroke.SplitCubic(from, ctrl0, ctrl1, to, qs.scratch[:0])
|
||||
for _, q := range qs.scratch {
|
||||
q = q.Transform(tr)
|
||||
qs.splitAndEncode(q)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user