mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app/headless,internal/rendertest: replace PaintOps with Fill/FillShape
We're about to remove PaintOp.Rect. Replacing PaintOps with Fill or FillShape where possible will ease the transition. Using Fill in tests exposed a problem with the infinity in paint.Fill. Adjust it for now; it will be removed later. Updates gio#167 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user