From d9100b506ffcb0378fe33ee7dc171efc72b96fd5 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 14 Oct 2019 20:20:56 +0200 Subject: [PATCH] op,op/paint: remove aux awareness from Ops Aux data is now entirely confined to the writers (Path) and the ops Reader parser. Signed-off-by: Elias Naur --- op/op.go | 60 +++++++++--------------------------------------- op/paint/path.go | 30 +++++++++++++----------- 2 files changed, 27 insertions(+), 63 deletions(-) diff --git a/op/op.go b/op/op.go index 6ac3da1b..2ea29918 100644 --- a/op/op.go +++ b/op/op.go @@ -78,10 +78,6 @@ type Ops struct { stackDepth int macroDepth int - - inAux bool - auxOff int - auxLen int } // StackOp can save and restore the operation state @@ -150,7 +146,6 @@ func (s *StackOp) Pop() { // Reset the Ops, preparing it for re-use. func (o *Ops) Reset() { - o.inAux = false o.stackDepth = 0 // Leave references to the GC. for i := range o.refs { @@ -161,62 +156,30 @@ func (o *Ops) Reset() { o.version++ } -// Internal use only. +// Data is for internal use only. func (o *Ops) Data() []byte { return o.data } -// Internal use only. +// Refs is for internal use only. func (o *Ops) Refs() []interface{} { return o.refs } -// Internal use only. +// PC is for internal use only. +func (o *Ops) PC() int { + return o.pc().data +} + +// Version is for internal use only. func (o *Ops) Version() int { return o.version } -// Internal use only. -func (o *Ops) Aux() []byte { - if !o.inAux { - return nil - } - aux := o.data[o.auxOff+opconst.TypeAuxLen:] - return aux[:o.auxLen] -} - -func (d *Ops) write(op []byte, refs ...interface{}) { - d.data = append(d.data, op...) - d.refs = append(d.refs, refs...) -} - -// Internal use only. +// Write is for internal use only. func (o *Ops) Write(op []byte, refs ...interface{}) { - t := opconst.OpType(op[0]) - if len(refs) != t.NumRefs() { - panic("invalid ref count") - } - switch t { - case opconst.TypeAux: - // Write only the data. - op = op[1:] - if !o.inAux { - o.inAux = true - o.auxOff = o.pc().data - o.auxLen = 0 - header := make([]byte, opconst.TypeAuxLen) - header[0] = byte(opconst.TypeAux) - o.write(header) - } - o.auxLen += len(op) - default: - o.endAux() - } - o.write(op, refs...) -} - -func (o *Ops) endAux() { - o.inAux = false + o.data = append(o.data, op...) + o.refs = append(o.refs, refs...) } func (o *Ops) pc() pc { @@ -242,7 +205,6 @@ func (m *MacroOp) Stop() { if !m.recording { panic("not recording") } - m.ops.endAux() m.ops.macroDepth-- m.recording = false m.fill() diff --git a/op/paint/path.go b/op/paint/path.go index b259aea3..5f70c46f 100644 --- a/op/paint/path.go +++ b/op/paint/path.go @@ -19,6 +19,7 @@ import ( // supplied to Begin. type Path struct { ops *op.Ops + pc int firstVert int nverts int maxy float32 @@ -50,6 +51,8 @@ func (p ClipOp) Add(o *op.Ops) { func (p *Path) Begin(ops *op.Ops) { p.ops = ops p.macro.Record(ops) + ops.Write([]byte{byte(opconst.TypeAux)}) + p.pc = ops.PC() } // MoveTo moves the pen to the given position. @@ -62,7 +65,7 @@ func (p *Path) Move(to f32.Point) { // end completes the current contour. func (p *Path) end() { - aux := p.ops.Aux() + aux := p.ops.Data()[p.pc:] bo := binary.LittleEndian // Fill in maximal Y coordinates of the NW and NE corners. for i := p.firstVert; i < p.nverts; i++ { @@ -246,20 +249,19 @@ func (p *Path) vertex(cornerx, cornery int16, ctrl, to f32.Point) { ToX: to.X, ToY: to.Y, } - data := make([]byte, path.VertStride+1) - data[0] = byte(opconst.TypeAux) + data := make([]byte, path.VertStride) bo := binary.LittleEndian - data[1] = byte(uint16(v.CornerX)) - data[2] = byte(uint16(v.CornerX) >> 8) - data[3] = byte(uint16(v.CornerY)) - data[4] = byte(uint16(v.CornerY) >> 8) - bo.PutUint32(data[5:], math.Float32bits(v.MaxY)) - bo.PutUint32(data[9:], math.Float32bits(v.FromX)) - bo.PutUint32(data[13:], math.Float32bits(v.FromY)) - bo.PutUint32(data[17:], math.Float32bits(v.CtrlX)) - bo.PutUint32(data[21:], math.Float32bits(v.CtrlY)) - bo.PutUint32(data[25:], math.Float32bits(v.ToX)) - bo.PutUint32(data[29:], math.Float32bits(v.ToY)) + data[0] = byte(uint16(v.CornerX)) + data[1] = byte(uint16(v.CornerX) >> 8) + data[2] = byte(uint16(v.CornerY)) + data[3] = byte(uint16(v.CornerY) >> 8) + bo.PutUint32(data[6:], math.Float32bits(v.MaxY)) + bo.PutUint32(data[8:], math.Float32bits(v.FromX)) + bo.PutUint32(data[12:], math.Float32bits(v.FromY)) + bo.PutUint32(data[16:], math.Float32bits(v.CtrlX)) + bo.PutUint32(data[20:], math.Float32bits(v.CtrlY)) + bo.PutUint32(data[24:], math.Float32bits(v.ToX)) + bo.PutUint32(data[28:], math.Float32bits(v.ToY)) p.ops.Write(data) }