forked from joejulian/gio
op: change signature of Ops.Write
By returning the allocated data buffer, Ops can become an interface in a future change without forcing operations to allocate. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+3
-6
@@ -66,33 +66,30 @@ func (i ImageOp) Add(o *op.Ops) {
|
||||
}.Add(o)
|
||||
return
|
||||
}
|
||||
data := make([]byte, opconst.TypeImageLen)
|
||||
data := o.Write(opconst.TypeImageLen, i.src)
|
||||
data[0] = byte(opconst.TypeImage)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], uint32(i.size.X))
|
||||
bo.PutUint32(data[5:], uint32(i.size.Y))
|
||||
o.Write(data, i.src)
|
||||
}
|
||||
|
||||
func (c ColorOp) Add(o *op.Ops) {
|
||||
data := make([]byte, opconst.TypeColorLen)
|
||||
data := o.Write(opconst.TypeColorLen)
|
||||
data[0] = byte(opconst.TypeColor)
|
||||
data[1] = c.Color.R
|
||||
data[2] = c.Color.G
|
||||
data[3] = c.Color.B
|
||||
data[4] = c.Color.A
|
||||
o.Write(data)
|
||||
}
|
||||
|
||||
func (d PaintOp) Add(o *op.Ops) {
|
||||
data := make([]byte, opconst.TypePaintLen)
|
||||
data := o.Write(opconst.TypePaintLen)
|
||||
data[0] = byte(opconst.TypePaint)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], math.Float32bits(d.Rect.Min.X))
|
||||
bo.PutUint32(data[5:], math.Float32bits(d.Rect.Min.Y))
|
||||
bo.PutUint32(data[9:], math.Float32bits(d.Rect.Max.X))
|
||||
bo.PutUint32(data[13:], math.Float32bits(d.Rect.Max.Y))
|
||||
o.Write(data)
|
||||
}
|
||||
|
||||
// RectClip returns a ClipOp corresponding to a pixel aligned
|
||||
|
||||
+4
-5
@@ -33,14 +33,13 @@ type ClipOp struct {
|
||||
|
||||
func (p ClipOp) Add(o *op.Ops) {
|
||||
p.macro.Add(o)
|
||||
data := make([]byte, opconst.TypeClipLen)
|
||||
data := o.Write(opconst.TypeClipLen)
|
||||
data[0] = byte(opconst.TypeClip)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], math.Float32bits(p.bounds.Min.X))
|
||||
bo.PutUint32(data[5:], math.Float32bits(p.bounds.Min.Y))
|
||||
bo.PutUint32(data[9:], math.Float32bits(p.bounds.Max.X))
|
||||
bo.PutUint32(data[13:], math.Float32bits(p.bounds.Max.Y))
|
||||
o.Write(data)
|
||||
}
|
||||
|
||||
// Begin the path, storing the path data and final ClipOp into ops.
|
||||
@@ -50,7 +49,8 @@ func (p *Path) Begin(ops *op.Ops) {
|
||||
// Write the TypeAux opcode and a byte for marking whether the
|
||||
// path has had its MaxY filled out. If not, the gpu will fill it
|
||||
// before using it.
|
||||
ops.Write([]byte{byte(opconst.TypeAux), 0})
|
||||
data := ops.Write(2)
|
||||
data[0] = byte(opconst.TypeAux)
|
||||
}
|
||||
|
||||
// MoveTo moves the pen to the given position.
|
||||
@@ -238,7 +238,7 @@ func (p *Path) vertex(cornerx, cornery int16, ctrl, to f32.Point) {
|
||||
ToX: to.X,
|
||||
ToY: to.Y,
|
||||
}
|
||||
data := make([]byte, path.VertStride)
|
||||
data := p.ops.Write(path.VertStride)
|
||||
bo := binary.LittleEndian
|
||||
data[0] = byte(uint16(v.CornerX))
|
||||
data[1] = byte(uint16(v.CornerX) >> 8)
|
||||
@@ -252,7 +252,6 @@ func (p *Path) vertex(cornerx, cornery int16, ctrl, to f32.Point) {
|
||||
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)
|
||||
}
|
||||
|
||||
func (p *Path) simpleQuadTo(ctrl, to f32.Point) {
|
||||
|
||||
Reference in New Issue
Block a user