clip: check Path ops are not mixed with others

Multiple operations Op, such as clip.Path, cannot
be interleaved with other ops. This patch adds a
mechanism to ensure that is the case by starting
multi ops with ops.BeginMulti and ending them with
ops.EndMulti while operations are written to op.Ops
with ops.WriteMulti.
This mechanism is applied to clip.Path.

Fixes: https://todo.sr.ht/~eliasnaur/gio/336
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2022-01-15 18:52:51 +01:00
committed by Elias Naur
parent 2879fe8b41
commit 2ce9ad36af
3 changed files with 58 additions and 5 deletions
+27
View File
@@ -22,6 +22,8 @@ type Ops struct {
// nextStateID is the id allocated for the next
// StateOp.
nextStateID int
// multipOp indicates a multi-op such as clip.Path is being added.
multipOp bool
macroStack stack
stacks [5]stack
@@ -192,6 +194,31 @@ func Reset(o *Ops) {
}
func Write(o *Ops, n int) []byte {
if o.multipOp {
panic("cannot mix multi ops with single ones")
}
o.data = append(o.data, make([]byte, n)...)
return o.data[len(o.data)-n:]
}
func BeginMulti(o *Ops) {
if o.multipOp {
panic("cannot interleave multi ops")
}
o.multipOp = true
}
func EndMulti(o *Ops) {
if !o.multipOp {
panic("cannot end non multi ops")
}
o.multipOp = false
}
func WriteMulti(o *Ops, n int) []byte {
if !o.multipOp {
panic("cannot use multi ops in single ops")
}
o.data = append(o.data, make([]byte, n)...)
return o.data[len(o.data)-n:]
}