mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 08:55:35 +00:00
op: change CallOp to be a return value from MacroOp.Stop
Converting macro := op.Record(ops) ... macro.Stop() macro.Add() to macro := op.Record(ops) ... call := macro.Stop() call.Add(ops) Which is more general (call.Add can take a different ops than the op.Record that started it), and enforced the order between Stop and the subsequent Add. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+4
-4
@@ -35,12 +35,12 @@ type Path struct {
|
||||
// If you need to reset the clip to its previous values after
|
||||
// applying a Op, use op.StackOp.
|
||||
type Op struct {
|
||||
macro op.MacroOp
|
||||
call op.CallOp
|
||||
bounds f32.Rectangle
|
||||
}
|
||||
|
||||
func (p Op) Add(o *op.Ops) {
|
||||
p.macro.Add()
|
||||
p.call.Add(o)
|
||||
data := o.Write(opconst.TypeClipLen)
|
||||
data[0] = byte(opconst.TypeClip)
|
||||
bo := binary.LittleEndian
|
||||
@@ -281,9 +281,9 @@ func (p *Path) simpleQuadTo(ctrl, to f32.Point) {
|
||||
// End the path and return a clip operation that represents it.
|
||||
func (p *Path) End() Op {
|
||||
p.end()
|
||||
p.macro.Stop()
|
||||
c := p.macro.Stop()
|
||||
return Op{
|
||||
macro: p.macro,
|
||||
call: c,
|
||||
bounds: p.bounds,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,6 @@ end of a function :
|
||||
|
||||
defer op.Push(ops).Pop()
|
||||
|
||||
The CallOp invokes another operation list:
|
||||
|
||||
ops := new(op.Ops)
|
||||
ops2 := new(op.Ops)
|
||||
op.CallOp{Ops: ops2}.Add(ops)
|
||||
|
||||
The MacroOp records a list of operations to be executed later:
|
||||
|
||||
ops := new(op.Ops)
|
||||
@@ -63,10 +57,10 @@ The MacroOp records a list of operations to be executed later:
|
||||
op.InvalidateOp{}.Add(ops)
|
||||
...
|
||||
// End recording.
|
||||
macro.Stop()
|
||||
call := macro.Stop()
|
||||
|
||||
// replay the recorded operations by calling Add:
|
||||
macro.Add()
|
||||
// replay the recorded operations:
|
||||
call.Add(ops)
|
||||
|
||||
*/
|
||||
package op
|
||||
@@ -110,11 +104,11 @@ type MacroOp struct {
|
||||
pc pc
|
||||
}
|
||||
|
||||
// CallOp invokes all the operations from a separate
|
||||
// operations list.
|
||||
// CallOp invokes the operations recorded by Record.
|
||||
type CallOp struct {
|
||||
// Ops is the list of operations to invoke.
|
||||
Ops *Ops
|
||||
ops *Ops
|
||||
pc pc
|
||||
}
|
||||
|
||||
// InvalidateOp requests a redraw at the given time. Use
|
||||
@@ -146,15 +140,6 @@ type pc struct {
|
||||
refs int
|
||||
}
|
||||
|
||||
// Add the call to the operation list.
|
||||
func (c CallOp) Add(o *Ops) {
|
||||
if c.Ops == nil {
|
||||
return
|
||||
}
|
||||
data := o.Write(opconst.TypeCallLen, c.Ops)
|
||||
data[0] = byte(opconst.TypeCall)
|
||||
}
|
||||
|
||||
// Push (save) the current operations state.
|
||||
func Push(o *Ops) StackOp {
|
||||
s := StackOp{
|
||||
@@ -224,38 +209,43 @@ func Record(o *Ops) MacroOp {
|
||||
pc: o.pc(),
|
||||
}
|
||||
// Reserve room for a macro definition. Updated in Stop.
|
||||
m.ops.Write(opconst.TypeMacroDefLen)
|
||||
m.ops.Write(opconst.TypeMacroLen)
|
||||
m.fill()
|
||||
return m
|
||||
}
|
||||
|
||||
// Stop ends a previously started recording.
|
||||
func (m MacroOp) Stop() {
|
||||
// Stop ends a previously started recording and returns an
|
||||
// operation for replaying it.
|
||||
func (m MacroOp) Stop() CallOp {
|
||||
m.ops.macroStack.pop(m.id)
|
||||
m.fill()
|
||||
return CallOp{
|
||||
ops: m.ops,
|
||||
pc: m.pc,
|
||||
}
|
||||
}
|
||||
|
||||
func (m MacroOp) fill() {
|
||||
pc := m.ops.pc()
|
||||
// Fill out the macro definition reserved in Record.
|
||||
data := m.ops.data[m.pc.data:]
|
||||
data = data[:opconst.TypeMacroDefLen]
|
||||
data[0] = byte(opconst.TypeMacroDef)
|
||||
data = data[:opconst.TypeMacroLen]
|
||||
data[0] = byte(opconst.TypeMacro)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], uint32(pc.data))
|
||||
bo.PutUint32(data[5:], uint32(pc.refs))
|
||||
}
|
||||
|
||||
// Add the recorded list of operations.
|
||||
func (m MacroOp) Add() {
|
||||
if m.ops == nil {
|
||||
func (c CallOp) Add(o *Ops) {
|
||||
if c.ops == nil {
|
||||
return
|
||||
}
|
||||
data := m.ops.Write(opconst.TypeMacroLen)
|
||||
data[0] = byte(opconst.TypeMacro)
|
||||
data := o.Write(opconst.TypeCallLen, c.ops)
|
||||
data[0] = byte(opconst.TypeCall)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], uint32(m.pc.data))
|
||||
bo.PutUint32(data[5:], uint32(m.pc.refs))
|
||||
bo.PutUint32(data[1:], uint32(c.pc.data))
|
||||
bo.PutUint32(data[5:], uint32(c.pc.refs))
|
||||
}
|
||||
|
||||
func (r InvalidateOp) Add(o *Ops) {
|
||||
|
||||
Reference in New Issue
Block a user