diff --git a/app/headless/headless_test.go b/app/headless/headless_test.go index 7774dcd9..cbd9c878 100644 --- a/app/headless/headless_test.go +++ b/app/headless/headless_test.go @@ -22,10 +22,7 @@ func TestHeadless(t *testing.T) { var ops op.Ops paint.ColorOp{Color: col}.Add(&ops) // Paint only part of the screen to avoid the glClear optimization. - paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{ - X: float32(sz.X) - 100, - Y: float32(sz.Y) - 100, - }}}.Add(&ops) + paint.FillShape(&ops, col, clip.Rect(image.Rect(0, 0, sz.X-100, sz.Y-100)).Op()) if err := w.Frame(&ops); err != nil { t.Fatal(err) } @@ -108,15 +105,9 @@ func TestDepth(t *testing.T) { var ops op.Ops blue := color.RGBA{B: 0xFF, A: 0xFF} - paint.ColorOp{Color: blue}.Add(&ops) - paint.PaintOp{Rect: f32.Rectangle{ - Max: f32.Point{X: 50, Y: 100}, - }}.Add(&ops) + paint.FillShape(&ops, blue, clip.Rect(image.Rect(0, 0, 50, 100)).Op()) red := color.RGBA{R: 0xFF, A: 0xFF} - paint.ColorOp{Color: red}.Add(&ops) - paint.PaintOp{Rect: f32.Rectangle{ - Max: f32.Point{X: 100, Y: 50}, - }}.Add(&ops) + paint.FillShape(&ops, red, clip.Rect(image.Rect(0, 0, 100, 50)).Op()) if err := w.Frame(&ops); err != nil { t.Fatal(err) } diff --git a/internal/rendertest/bench_test.go b/internal/rendertest/bench_test.go index c49a7ed0..fe580670 100644 --- a/internal/rendertest/bench_test.go +++ b/internal/rendertest/bench_test.go @@ -156,11 +156,10 @@ func draw1000Circles(gtx layout.Context) { p := op.Push(ops) op.Offset(f32.Pt(float32(x*10), 0)).Add(ops) for y := 0; y < 10; y++ { - pi := op.Push(ops) - paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops) - clip.RRect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops) - paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(ops) - pi.Pop() + paint.FillShape(ops, + color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}, + clip.RRect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Op(ops), + ) op.Offset(f32.Pt(0, float32(100))).Add(ops) } p.Pop() @@ -208,11 +207,10 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp p := op.Push(ops) op.Offset(f32.Pt(float32(x*50), 0)).Add(ops) for y := 0; y < 9; y++ { - pi := op.Push(ops) - paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops) - clip.RRect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops) - paint.PaintOp{Rect: f32.Rect(0, 0, 25, 25)}.Add(ops) - pi.Pop() + paint.FillShape(ops, + color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}, + clip.RRect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Op(ops), + ) op.Offset(f32.Pt(0, float32(50))).Add(ops) } p.Pop() diff --git a/internal/rendertest/clip_test.go b/internal/rendertest/clip_test.go index b996d816..debf6666 100644 --- a/internal/rendertest/clip_test.go +++ b/internal/rendertest/clip_test.go @@ -1,6 +1,7 @@ package rendertest import ( + "image" "math" "testing" @@ -13,8 +14,7 @@ import ( func TestPaintRect(t *testing.T) { run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 50, 50)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 50, 50)).Op()) }, func(r result) { r.expect(0, 0, colornames.Red) r.expect(49, 0, colornames.Red) @@ -25,9 +25,8 @@ func TestPaintRect(t *testing.T) { func TestPaintClippedRect(t *testing.T) { run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) clip.RRect{Rect: f32.Rect(25, 25, 60, 60)}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 50, 50)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 50, 50)).Op()) }, func(r result) { r.expect(0, 0, colornames.White) r.expect(24, 35, colornames.White) @@ -39,10 +38,10 @@ func TestPaintClippedRect(t *testing.T) { func TestPaintClippedCirle(t *testing.T) { run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) r := float32(10) clip.RRect{Rect: f32.Rect(20, 20, 40, 40), SE: r, SW: r, NW: r, NE: r}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 30, 50)}.Add(o) + clip.Rect(image.Rect(0, 0, 30, 50)).Add(o) + paint.Fill(o, colornames.Red) }, func(r result) { r.expect(21, 21, colornames.White) r.expect(25, 30, colornames.Red) @@ -71,8 +70,7 @@ func TestPaintArc(t *testing.T) { p.Line(f32.Pt(-50, 0)) p.End().Add(o) - paint.ColorOp{Color: colornames.Red}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 128, 128)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 128, 128)).Op()) }, func(r result) { r.expect(0, 0, colornames.White) r.expect(0, 25, colornames.Red) diff --git a/internal/rendertest/render_test.go b/internal/rendertest/render_test.go index 2c9d710e..80e72109 100644 --- a/internal/rendertest/render_test.go +++ b/internal/rendertest/render_test.go @@ -1,6 +1,7 @@ package rendertest import ( + "image" "image/color" "math" "testing" @@ -16,16 +17,15 @@ import ( func TestTransformMacro(t *testing.T) { // testcase resulting from original bug when rendering layout.Stacked - // pre-build the text + // Build clip-path. c := constSqPath() run(t, func(o *op.Ops) { // render the first Stacked item m1 := op.Record(o) - dr := f32.Rect(0, 0, 128, 50) - paint.ColorOp{Color: colornames.Black}.Add(o) - paint.PaintOp{Rect: dr}.Add(o) + dr := image.Rect(0, 0, 128, 50) + paint.FillShape(o, colornames.Black, clip.Rect(dr).Op()) c1 := m1.Stop() // Render the second stacked item @@ -62,8 +62,7 @@ func TestTransformMacro(t *testing.T) { func TestRepeatedPaintsZ(t *testing.T) { run(t, func(o *op.Ops) { // Draw a rectangle - paint.ColorOp{Color: colornames.Black}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 128, 50)}.Add(o) + paint.FillShape(o, colornames.Black, clip.Rect(image.Rect(0, 0, 128, 50)).Op()) builder := clip.Path{} builder.Begin(o) @@ -73,8 +72,7 @@ func TestRepeatedPaintsZ(t *testing.T) { builder.Line(f32.Pt(-10, 0)) builder.Line(f32.Pt(0, -10)) builder.End().Add(o) - paint.ColorOp{Color: colornames.Red}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(o) + paint.Fill(o, colornames.Red) }, func(r result) { r.expect(5, 5, colornames.Red) r.expect(11, 15, colornames.Black) @@ -84,17 +82,15 @@ func TestRepeatedPaintsZ(t *testing.T) { func TestNoClipFromPaint(t *testing.T) { // ensure that a paint operation does not polute the state - // by leaving any clip paths i place. + // by leaving any clip paths in place. run(t, func(o *op.Ops) { a := f32.Affine2D{}.Rotate(f32.Pt(20, 20), math.Pi/4) op.Affine(a).Add(o) - paint.ColorOp{Color: colornames.Red}.Add(o) - paint.PaintOp{Rect: f32.Rect(10, 10, 30, 30)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(10, 10, 30, 30)).Op()) a = f32.Affine2D{}.Rotate(f32.Pt(20, 20), -math.Pi/4) op.Affine(a).Add(o) - paint.ColorOp{Color: colornames.Black}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 50, 50)}.Add(o) + paint.FillShape(o, colornames.Black, clip.Rect(image.Rect(0, 0, 50, 50)).Op()) }, func(r result) { r.expect(1, 1, colornames.Black) r.expect(20, 20, colornames.Black) diff --git a/internal/rendertest/transform_test.go b/internal/rendertest/transform_test.go index 67a6f0a6..c39302e9 100644 --- a/internal/rendertest/transform_test.go +++ b/internal/rendertest/transform_test.go @@ -1,6 +1,7 @@ package rendertest import ( + "image" "math" "testing" @@ -14,8 +15,7 @@ import ( func TestPaintOffset(t *testing.T) { run(t, func(o *op.Ops) { op.Offset(f32.Pt(10, 20)).Add(o) - paint.ColorOp{Color: colornames.Red}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 50, 50)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 50, 50)).Op()) }, func(r result) { r.expect(0, 0, colornames.White) r.expect(59, 30, colornames.Red) @@ -28,8 +28,7 @@ func TestPaintRotate(t *testing.T) { run(t, func(o *op.Ops) { a := f32.Affine2D{}.Rotate(f32.Pt(40, 40), -math.Pi/8) op.Affine(a).Add(o) - paint.ColorOp{Color: colornames.Red}.Add(o) - paint.PaintOp{Rect: f32.Rect(20, 20, 60, 60)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(20, 20, 60, 60)).Op()) }, func(r result) { r.expect(40, 40, colornames.Red) r.expect(50, 19, colornames.Red) @@ -42,8 +41,7 @@ func TestPaintShear(t *testing.T) { run(t, func(o *op.Ops) { a := f32.Affine2D{}.Shear(f32.Point{}, math.Pi/4, 0) op.Affine(a).Add(o) - paint.ColorOp{Color: colornames.Red}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 40, 40)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 40, 40)).Op()) }, func(r result) { r.expect(10, 30, colornames.White) }) @@ -51,10 +49,9 @@ func TestPaintShear(t *testing.T) { func TestClipPaintOffset(t *testing.T) { run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o) op.Offset(f32.Pt(20, 20)).Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 100, 100)).Op()) }, func(r result) { r.expect(0, 0, colornames.White) r.expect(19, 19, colornames.White) @@ -65,10 +62,9 @@ func TestClipPaintOffset(t *testing.T) { func TestClipOffset(t *testing.T) { run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) op.Offset(f32.Pt(20, 20)).Add(o) clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 100, 100)).Op()) }, func(r result) { r.expect(0, 0, colornames.White) r.expect(29, 29, colornames.White) @@ -80,11 +76,10 @@ func TestClipOffset(t *testing.T) { func TestClipScale(t *testing.T) { run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) a := f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(2, 2)).Offset(f32.Pt(10, 10)) op.Affine(a).Add(o) clip.RRect{Rect: f32.Rect(10, 10, 20, 20)}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 1000, 1000)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 1000, 1000)).Op()) }, func(r result) { r.expect(19+10, 19+10, colornames.White) r.expect(20+10, 20+10, colornames.Red) @@ -95,10 +90,9 @@ func TestClipScale(t *testing.T) { func TestClipRotate(t *testing.T) { run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) op.Affine(f32.Affine2D{}.Rotate(f32.Pt(40, 40), -math.Pi/4)).Add(o) clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o) - paint.PaintOp{Rect: f32.Rect(0, 40, 100, 100)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 40, 100, 100)).Op()) }, func(r result) { r.expect(39, 39, colornames.White) r.expect(41, 41, colornames.Red) @@ -180,8 +174,6 @@ func TestComplicatedTransform(t *testing.T) { func TestTransformOrder(t *testing.T) { // check the ordering of operations bot in affine and in gpu stack. run(t, func(o *op.Ops) { - paint.ColorOp{Color: colornames.Red}.Add(o) - a := f32.Affine2D{}.Offset(f32.Pt(64, 64)) op.Affine(a).Add(o) @@ -190,7 +182,7 @@ func TestTransformOrder(t *testing.T) { c := f32.Affine2D{}.Offset(f32.Pt(-10, -10)).Scale(f32.Point{}, f32.Pt(0.5, 0.5)) op.Affine(c).Add(o) - paint.PaintOp{Rect: f32.Rect(0, 0, 20, 20)}.Add(o) + paint.FillShape(o, colornames.Red, clip.Rect(image.Rect(0, 0, 20, 20)).Op()) }, func(r result) { // centered and with radius 40 r.expect(64-41, 64, colornames.White) diff --git a/op/paint/paint.go b/op/paint/paint.go index bd596b57..e3cbfedf 100644 --- a/op/paint/paint.go +++ b/op/paint/paint.go @@ -160,7 +160,7 @@ func FillShape(ops *op.Ops, c color.RGBA, shape clip.Op) { func Fill(ops *op.Ops, c color.RGBA) { defer op.Push(ops).Pop() ColorOp{Color: c}.Add(ops) - inf := float32(math.Inf(+1)) + inf := float32(1e6) PaintOp{ Rect: f32.Rectangle{ Min: f32.Pt(-inf, -inf),