From f1ae923a89ecdd5e5b16923691c3c26168e76a5c Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 11 Mar 2021 18:15:38 +0100 Subject: [PATCH] gpu,op/clip: encode lines as compute line commands, not quads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new renderer supports lines natively; encode them as such and convert them to a quadratic beziér. Signed-off-by: Elias Naur --- gpu/gpu.go | 15 +++++++++++++++ op/clip/clip.go | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gpu/gpu.go b/gpu/gpu.go index 4095b021..0ecc2f92 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -1393,6 +1393,12 @@ func decodeToOutlineQuads(qs *quadSplitter, tr f32.Affine2D, pathData []byte) { qs.contour = bo.Uint32(pathData) cmd := ops.DecodeCommand(pathData[4:]) switch cmd.Op() { + case scene.OpFillLine: + var q quadSegment + q.From, q.To = scene.DecodeLine(cmd) + q.Ctrl = q.From.Add(q.To).Mul(.5) + q = q.Transform(tr) + qs.splitAndEncode(q) case scene.OpFillQuad: var q quadSegment q.From, q.Ctrl, q.To = scene.DecodeQuad(cmd) @@ -1413,6 +1419,15 @@ func decodeToStrokeQuads(pathData []byte) strokeQuads { contour := bo.Uint32(pathData) cmd := ops.DecodeCommand(pathData[4:]) switch cmd.Op() { + case scene.OpFillLine: + var q quadSegment + q.From, q.To = scene.DecodeLine(cmd) + q.Ctrl = q.From.Add(q.To).Mul(.5) + quad := strokeQuad{ + contour: contour, + quad: q, + } + quads = append(quads, quad) case scene.OpFillQuad: var q quadSegment q.From, q.Ctrl, q.To = scene.DecodeQuad(cmd) diff --git a/op/clip/clip.go b/op/clip/clip.go index 0477e637..0d79975e 100644 --- a/op/clip/clip.go +++ b/op/clip/clip.go @@ -138,8 +138,12 @@ func (p *Path) Line(delta f32.Point) { // LineTo moves the pen to the absolute point specified, recording a line. func (p *Path) LineTo(to f32.Point) { - // Model lines as degenerate quadratic Béziers. - p.QuadTo(to.Add(p.pen).Mul(.5), to) + data := p.ops.Write(scene.CommandSize + 4) + bo := binary.LittleEndian + bo.PutUint32(data[0:], uint32(p.contour)) + ops.EncodeCommand(data[4:], scene.Line(p.pen, to, false, 0)) + p.pen = to + p.hasSegments = true } // Quad records a quadratic Bézier from the pen to end