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
+24
View File
@@ -227,3 +227,27 @@ func TestPathReuse(t *testing.T) {
}, func(r result) {
})
}
func TestPathInterleave(t *testing.T) {
t.Run("interleave op in clip.Path", func(t *testing.T) {
defer func() {
if err := recover(); err == nil {
t.Error("expected panic did not occur")
}
}()
ops := new(op.Ops)
var path clip.Path
path.Begin(ops)
path.LineTo(f32.Point{X: 123, Y: 456})
paint.ColorOp{}.Add(ops)
path.End()
})
t.Run("use ops after clip.Path", func(t *testing.T) {
ops := new(op.Ops)
var path clip.Path
path.Begin(ops)
path.LineTo(f32.Point{X: 123, Y: 456})
path.End()
paint.ColorOp{}.Add(ops)
})
}