op/clip,gpu,internal/opconst: remove quad count from Path op

The check for path segments in gpu is redundant; clip.Op.Add doesn't add
the Path op if there were no segments.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-03-11 18:11:28 +01:00
parent 2328ddfeca
commit b8bdb96d35
3 changed files with 23 additions and 37 deletions
-13
View File
@@ -168,20 +168,10 @@ func decodeStrokeOp(data []byte) clip.StrokeStyle {
} }
type quadsOp struct { type quadsOp struct {
quads uint32
key ops.Key key ops.Key
aux []byte aux []byte
} }
func decodeQuadsOp(data []byte) uint32 {
_ = data[:1+4]
if opconst.OpType(data[0]) != opconst.TypePath {
panic("invalid op")
}
bo := binary.LittleEndian
return bo.Uint32(data[1:])
}
type material struct { type material struct {
material materialType material materialType
opaque bool opaque bool
@@ -922,15 +912,12 @@ loop:
stroke = decodeStrokeOp(encOp.Data) stroke = decodeStrokeOp(encOp.Data)
case opconst.TypePath: case opconst.TypePath:
quads.quads = decodeQuadsOp(encOp.Data)
if quads.quads > 0 {
encOp, ok = r.Decode() encOp, ok = r.Decode()
if !ok { if !ok {
break loop break loop
} }
quads.aux = encOp.Data[opconst.TypeAuxLen:] quads.aux = encOp.Data[opconst.TypeAuxLen:]
quads.key = encOp.Key quads.key = encOp.Key
}
case opconst.TypeClip: case opconst.TypeClip:
var op clipOp var op clipOp
+1 -1
View File
@@ -60,7 +60,7 @@ const (
TypeClipLen = 1 + 4*4 + 1 TypeClipLen = 1 + 4*4 + 1
TypeProfileLen = 1 TypeProfileLen = 1
TypeCursorLen = 1 + 1 TypeCursorLen = 1 + 1
TypePathLen = 1 + 4 TypePathLen = 1
TypeStrokeLen = 1 + 4 + 4 + 1 + 1 TypeStrokeLen = 1 + 4 + 4 + 1 + 1
TypeDashLen = 1 + 4 + 1 TypeDashLen = 1 + 4 + 1
) )
+6 -7
View File
@@ -25,11 +25,9 @@ type Op struct {
} }
func (p Op) Add(o *op.Ops) { func (p Op) Add(o *op.Ops) {
if p.path.quads > 0 { if p.path.hasSegments {
data := o.Write(opconst.TypePathLen) data := o.Write(opconst.TypePathLen)
data[0] = byte(opconst.TypePath) data[0] = byte(opconst.TypePath)
bo := binary.LittleEndian
bo.PutUint32(data[1:], p.path.quads)
p.path.spec.Add(o) p.path.spec.Add(o)
} }
@@ -69,7 +67,8 @@ type PathSpec struct {
// open is true if any path contour is not closed. A closed contour starts // open is true if any path contour is not closed. A closed contour starts
// and ends in the same point. // and ends in the same point.
open bool open bool
quads uint32 // quads is the number Bézier segments in the path. // hasSegments tracks whether there is more than one path segment in the path.
hasSegments bool
} }
// Path constructs a Op clip path described by lines and // Path constructs a Op clip path described by lines and
@@ -86,7 +85,7 @@ type Path struct {
pen f32.Point pen f32.Point
macro op.MacroOp macro op.MacroOp
start f32.Point start f32.Point
quads uint32 hasSegments bool
} }
// Pos returns the current pen position. // Pos returns the current pen position.
@@ -107,7 +106,7 @@ func (p *Path) End() PathSpec {
return PathSpec{ return PathSpec{
spec: c, spec: c,
open: p.open || p.pen != p.start, open: p.open || p.pen != p.start,
quads: p.quads, hasSegments: p.hasSegments,
} }
} }
@@ -162,7 +161,7 @@ func (p *Path) QuadTo(ctrl, to f32.Point) {
To: to, To: to,
}) })
p.pen = to p.pen = to
p.quads++ p.hasSegments = true
} }
// Arc adds an elliptical arc to the path. The implied ellipse is defined // Arc adds an elliptical arc to the path. The implied ellipse is defined