mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
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 <mail@eliasnaur.com>
This commit is contained in:
@@ -78,10 +78,6 @@ type Ops struct {
|
|||||||
|
|
||||||
stackDepth int
|
stackDepth int
|
||||||
macroDepth int
|
macroDepth int
|
||||||
|
|
||||||
inAux bool
|
|
||||||
auxOff int
|
|
||||||
auxLen int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StackOp can save and restore the operation state
|
// StackOp can save and restore the operation state
|
||||||
@@ -150,7 +146,6 @@ func (s *StackOp) Pop() {
|
|||||||
|
|
||||||
// Reset the Ops, preparing it for re-use.
|
// Reset the Ops, preparing it for re-use.
|
||||||
func (o *Ops) Reset() {
|
func (o *Ops) Reset() {
|
||||||
o.inAux = false
|
|
||||||
o.stackDepth = 0
|
o.stackDepth = 0
|
||||||
// Leave references to the GC.
|
// Leave references to the GC.
|
||||||
for i := range o.refs {
|
for i := range o.refs {
|
||||||
@@ -161,62 +156,30 @@ func (o *Ops) Reset() {
|
|||||||
o.version++
|
o.version++
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal use only.
|
// Data is for internal use only.
|
||||||
func (o *Ops) Data() []byte {
|
func (o *Ops) Data() []byte {
|
||||||
return o.data
|
return o.data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal use only.
|
// Refs is for internal use only.
|
||||||
func (o *Ops) Refs() []interface{} {
|
func (o *Ops) Refs() []interface{} {
|
||||||
return o.refs
|
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 {
|
func (o *Ops) Version() int {
|
||||||
return o.version
|
return o.version
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal use only.
|
// Write is for 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.
|
|
||||||
func (o *Ops) Write(op []byte, refs ...interface{}) {
|
func (o *Ops) Write(op []byte, refs ...interface{}) {
|
||||||
t := opconst.OpType(op[0])
|
o.data = append(o.data, op...)
|
||||||
if len(refs) != t.NumRefs() {
|
o.refs = append(o.refs, refs...)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Ops) pc() pc {
|
func (o *Ops) pc() pc {
|
||||||
@@ -242,7 +205,6 @@ func (m *MacroOp) Stop() {
|
|||||||
if !m.recording {
|
if !m.recording {
|
||||||
panic("not recording")
|
panic("not recording")
|
||||||
}
|
}
|
||||||
m.ops.endAux()
|
|
||||||
m.ops.macroDepth--
|
m.ops.macroDepth--
|
||||||
m.recording = false
|
m.recording = false
|
||||||
m.fill()
|
m.fill()
|
||||||
|
|||||||
+16
-14
@@ -19,6 +19,7 @@ import (
|
|||||||
// supplied to Begin.
|
// supplied to Begin.
|
||||||
type Path struct {
|
type Path struct {
|
||||||
ops *op.Ops
|
ops *op.Ops
|
||||||
|
pc int
|
||||||
firstVert int
|
firstVert int
|
||||||
nverts int
|
nverts int
|
||||||
maxy float32
|
maxy float32
|
||||||
@@ -50,6 +51,8 @@ func (p ClipOp) Add(o *op.Ops) {
|
|||||||
func (p *Path) Begin(ops *op.Ops) {
|
func (p *Path) Begin(ops *op.Ops) {
|
||||||
p.ops = ops
|
p.ops = ops
|
||||||
p.macro.Record(ops)
|
p.macro.Record(ops)
|
||||||
|
ops.Write([]byte{byte(opconst.TypeAux)})
|
||||||
|
p.pc = ops.PC()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveTo moves the pen to the given position.
|
// MoveTo moves the pen to the given position.
|
||||||
@@ -62,7 +65,7 @@ func (p *Path) Move(to f32.Point) {
|
|||||||
|
|
||||||
// end completes the current contour.
|
// end completes the current contour.
|
||||||
func (p *Path) end() {
|
func (p *Path) end() {
|
||||||
aux := p.ops.Aux()
|
aux := p.ops.Data()[p.pc:]
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
// Fill in maximal Y coordinates of the NW and NE corners.
|
// Fill in maximal Y coordinates of the NW and NE corners.
|
||||||
for i := p.firstVert; i < p.nverts; i++ {
|
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,
|
ToX: to.X,
|
||||||
ToY: to.Y,
|
ToY: to.Y,
|
||||||
}
|
}
|
||||||
data := make([]byte, path.VertStride+1)
|
data := make([]byte, path.VertStride)
|
||||||
data[0] = byte(opconst.TypeAux)
|
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
data[1] = byte(uint16(v.CornerX))
|
data[0] = byte(uint16(v.CornerX))
|
||||||
data[2] = byte(uint16(v.CornerX) >> 8)
|
data[1] = byte(uint16(v.CornerX) >> 8)
|
||||||
data[3] = byte(uint16(v.CornerY))
|
data[2] = byte(uint16(v.CornerY))
|
||||||
data[4] = byte(uint16(v.CornerY) >> 8)
|
data[3] = byte(uint16(v.CornerY) >> 8)
|
||||||
bo.PutUint32(data[5:], math.Float32bits(v.MaxY))
|
bo.PutUint32(data[6:], math.Float32bits(v.MaxY))
|
||||||
bo.PutUint32(data[9:], math.Float32bits(v.FromX))
|
bo.PutUint32(data[8:], math.Float32bits(v.FromX))
|
||||||
bo.PutUint32(data[13:], math.Float32bits(v.FromY))
|
bo.PutUint32(data[12:], math.Float32bits(v.FromY))
|
||||||
bo.PutUint32(data[17:], math.Float32bits(v.CtrlX))
|
bo.PutUint32(data[16:], math.Float32bits(v.CtrlX))
|
||||||
bo.PutUint32(data[21:], math.Float32bits(v.CtrlY))
|
bo.PutUint32(data[20:], math.Float32bits(v.CtrlY))
|
||||||
bo.PutUint32(data[25:], math.Float32bits(v.ToX))
|
bo.PutUint32(data[24:], math.Float32bits(v.ToX))
|
||||||
bo.PutUint32(data[29:], math.Float32bits(v.ToY))
|
bo.PutUint32(data[28:], math.Float32bits(v.ToY))
|
||||||
p.ops.Write(data)
|
p.ops.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user