gpu,op/clip: encode lines as compute line commands, not quads

The new renderer supports lines natively; encode them as such and
convert them to a quadratic beziér.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-03-11 18:15:38 +01:00
parent a369c408f9
commit f1ae923a89
2 changed files with 21 additions and 2 deletions
+15
View File
@@ -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)
+6 -2
View File
@@ -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