diff --git a/gpu/internal/rendertest/clip_test.go b/gpu/internal/rendertest/clip_test.go index a2fcb768..c8d73508 100644 --- a/gpu/internal/rendertest/clip_test.go +++ b/gpu/internal/rendertest/clip_test.go @@ -118,6 +118,39 @@ func TestPaintTexture(t *testing.T) { }) } +func TestTexturedStrokeClipped(t *testing.T) { + run(t, func(o *op.Ops) { + smallSquares.Add(o) + op.Offset(f32.Pt(50, 50)).Add(o) + clip.Stroke{ + Path: clip.RRect{Rect: f32.Rect(0, 0, 30, 30)}.Path(o), + Style: clip.StrokeStyle{ + Width: 10, + }, + }.Op().Add(o) + clip.RRect{Rect: f32.Rect(-30, -30, 60, 60)}.Add(o) + op.Offset(f32.Pt(-10, -10)).Add(o) + paint.PaintOp{}.Add(o) + }, func(r result) { + }) +} + +func TestTexturedStroke(t *testing.T) { + run(t, func(o *op.Ops) { + smallSquares.Add(o) + op.Offset(f32.Pt(50, 50)).Add(o) + clip.Stroke{ + Path: clip.RRect{Rect: f32.Rect(0, 0, 30, 30)}.Path(o), + Style: clip.StrokeStyle{ + Width: 10, + }, + }.Op().Add(o) + op.Offset(f32.Pt(-10, -10)).Add(o) + paint.PaintOp{}.Add(o) + }, func(r result) { + }) +} + func TestPaintClippedTexture(t *testing.T) { run(t, func(o *op.Ops) { squares.Add(o) diff --git a/gpu/internal/rendertest/refs/TestTexturedStroke.png b/gpu/internal/rendertest/refs/TestTexturedStroke.png new file mode 100644 index 00000000..c7f94431 Binary files /dev/null and b/gpu/internal/rendertest/refs/TestTexturedStroke.png differ diff --git a/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png b/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png new file mode 100644 index 00000000..c7f94431 Binary files /dev/null and b/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png differ diff --git a/gpu/internal/rendertest/util_test.go b/gpu/internal/rendertest/util_test.go index 5e87d284..812963f0 100644 --- a/gpu/internal/rendertest/util_test.go +++ b/gpu/internal/rendertest/util_test.go @@ -25,8 +25,9 @@ import ( ) var ( - dumpImages = flag.Bool("saveimages", false, "save test images") - squares paint.ImageOp + dumpImages = flag.Bool("saveimages", false, "save test images") + squares paint.ImageOp + smallSquares paint.ImageOp ) var ( @@ -39,8 +40,11 @@ var ( ) func init() { - // build the texture we use for testing - size := 512 + squares = buildSquares(512) + smallSquares = buildSquares(50) +} + +func buildSquares(size int) paint.ImageOp { sub := size / 4 im := image.NewNRGBA(image.Rect(0, 0, size, size)) c1, c2 := image.NewUniform(colornames.Green), image.NewUniform(colornames.Blue) @@ -51,7 +55,7 @@ func init() { } c1, c2 = c2, c1 } - squares = paint.NewImageOp(im) + return paint.NewImageOp(im) } func drawImage(t *testing.T, size int, ops *op.Ops, draw func(o *op.Ops)) (im *image.RGBA, err error) {