From 60bab15164d7f1d0763f8ea85929e8df11661ae0 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 19 Mar 2021 21:44:29 +0100 Subject: [PATCH] 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 --- gpu/internal/rendertest/clip_test.go | 33 ++++++++++++++++++ .../rendertest/refs/TestTexturedStroke.png | Bin 0 -> 732 bytes .../refs/TestTexturedStrokeClipped.png | Bin 0 -> 732 bytes gpu/internal/rendertest/util_test.go | 14 +++++--- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 gpu/internal/rendertest/refs/TestTexturedStroke.png create mode 100644 gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png 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 0000000000000000000000000000000000000000..c7f944317187b3625a9f63b400daa94c6d5552b3 GIT binary patch literal 732 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRh7^U|Q_y;uumf=gl2QFX>#FhL8Vi zl;ackIEv@RNSq0~Aicx$z{$>>^1WwN1k7!l6xO+UD~$+Dig&s%Nw z$2w2?f8cUuWxCMj>n6S(pXF;AcAsM~U_QXZV9aoaMvU8w`4e1Yk5|Zqikh4I|KE4! zUftQJV)kaA-qiZp&FSHDf0}vI`o&hOYvq%ce$Lhm4=*ef>~4*!?Vf6tVzWRZ~VYgl*y#M1EhPS7wYj@4qUV&D7n=a$o*mosH#OD#X7 za>jP>o?|PQf4}N=)+d9Vf9rn#2-tV_^|p#jo0ot2-T(jNX`?F7KU1@e#FMPGr>bV8 mqk9DIBPuYy88a~a|G!{m)0;_$=Sc!nErX}4pUXO@geCy>j3F@q literal 0 HcmV?d00001 diff --git a/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png b/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png new file mode 100644 index 0000000000000000000000000000000000000000..c7f944317187b3625a9f63b400daa94c6d5552b3 GIT binary patch literal 732 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRh7^U|Q_y;uumf=gl2QFX>#FhL8Vi zl;ackIEv@RNSq0~Aicx$z{$>>^1WwN1k7!l6xO+UD~$+Dig&s%Nw z$2w2?f8cUuWxCMj>n6S(pXF;AcAsM~U_QXZV9aoaMvU8w`4e1Yk5|Zqikh4I|KE4! zUftQJV)kaA-qiZp&FSHDf0}vI`o&hOYvq%ce$Lhm4=*ef>~4*!?Vf6tVzWRZ~VYgl*y#M1EhPS7wYj@4qUV&D7n=a$o*mosH#OD#X7 za>jP>o?|PQf4}N=)+d9Vf9rn#2-tV_^|p#jo0ot2-T(jNX`?F7KU1@e#FMPGr>bV8 mqk9DIBPuYy88a~a|G!{m)0;_$=Sc!nErX}4pUXO@geCy>j3F@q literal 0 HcmV?d00001 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) {