mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
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:
@@ -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:]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user