op,internal/ops: support CallOps without macros

A recorded macro is prefixed with an internal macro op that stores
the end of the macro. The end is used to efficiently skip the macro
when not calling it. The call a macro, the CallOp stores the start
position of the macro.

To support seamless wrapping of Ops lists, this change removes the
dependency on the macro op prefix from CallOp. Internal code can
now call an Ops like this:

    var ops op.Ops
    var wrapper op.Ops

    ops.AddCall(&wrapper.Internal, &ops.Internal, ops.PC{}, ops.PCFor(&ops.Internal))

References: https://todo.sr.ht/~eliasnaur/gio/318
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-01-20 09:50:25 +01:00
parent c0f3ec88e9
commit 65199a2274
3 changed files with 32 additions and 25 deletions
+7 -4
View File
@@ -92,8 +92,9 @@ type MacroOp struct {
// CallOp invokes the operations recorded by Record.
type CallOp struct {
// Ops is the list of operations to invoke.
ops *ops.Ops
pc ops.PC
ops *ops.Ops
start ops.PC
end ops.PC
}
// InvalidateOp requests a redraw at the given time. Use
@@ -165,7 +166,9 @@ func (m MacroOp) Stop() CallOp {
ops.FillMacro(m.ops, m.pc)
return CallOp{
ops: m.ops,
pc: m.pc,
// Skip macro header.
start: m.pc.Add(ops.TypeMacro),
end: ops.PCFor(m.ops),
}
}
@@ -176,7 +179,7 @@ func (c CallOp) Add(o *Ops) {
if c.ops == nil {
return
}
ops.AddCall(&o.Internal, c.ops, c.pc)
ops.AddCall(&o.Internal, c.ops, c.start, c.end)
}
func (r InvalidateOp) Add(o *Ops) {