gpu/internal/rendertest: test textured strokes, including clipping

The new compute renderer can draw simple strokes. Test that clipping
works with a stroke basis, and that images can be drawn into strokes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-03-19 21:44:29 +01:00
parent ac800a9d8f
commit 60bab15164
4 changed files with 42 additions and 5 deletions
+33
View File
@@ -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)
Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

+9 -5
View File
@@ -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) {