mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
all: [API] split operation stack into per-state stacks
The op.Save and Load methods exist to support the need for
transformation, clip, pointer area state to behave as stacks. For
example, layout needs to apply an offset to its children but not
subsequent operations.
Before this change, op.Save and Load were used to save and restore the
state:
ops := new(op.Ops)
// Save state.
state := op.Save(ops)
// Apply offset.
op.Offset(...).Add(ops)
// Draw with offset applied.
draw(ops)
// Restore state.
state.Load()
A drawback with the op.Save mechanism is that there is no direct
connection between the state change and the saving and loading of state.
This causes confusion as to when a Save/Load is needed and who is
responsible for performing them, which leads to subtle bugs and over-use
of Save/Loads.
This change gets rid of the general state stack and replaces it with
per-state stacks. There is now a stack for transformation, clip, pointer
areas, and they can only be restored by the code pushing state to them.
The example above now becomes:
ops := new(op.Ops)
// Push offset to the transformation stack.
stack := op.Offset(...).Push(ops)
// Draw with offset applied.
draw(ops)
// Restore state.
stack.Pop()
For convenience, transformation also be Add'ed if the stack operation is
not required.
Simple state such as the current material no longer has a way to be
restored; it is assumed the client of a PaintOp adds their desired
material operation before it.
API change: replace op.Save/Load with explicit Push/Pop scopes for
op.TransformOps, pointer.AreaOps, clip.Ops.
To ease porting, this change retains a version of op.Save/Load that
saves and restores the transformation and clip stacks. It also retains
an Add method for clip.Op.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -84,13 +84,12 @@ func BenchmarkDrawUI(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
resetOps(gtx)
|
||||
|
||||
p := op.Save(gtx.Ops)
|
||||
off := float32(math.Mod(float64(i)/10, 10))
|
||||
op.Offset(f32.Pt(off, off)).Add(gtx.Ops)
|
||||
t := op.Offset(f32.Pt(off, off)).Push(gtx.Ops)
|
||||
|
||||
drawCore(gtx, th)
|
||||
|
||||
p.Load()
|
||||
t.Pop()
|
||||
w.Frame(gtx.Ops)
|
||||
}
|
||||
finishBenchmark(b, w)
|
||||
@@ -107,14 +106,13 @@ func BenchmarkDrawUITransformed(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
resetOps(gtx)
|
||||
|
||||
p := op.Save(gtx.Ops)
|
||||
angle := float32(math.Mod(float64(i)/1000, 0.05))
|
||||
a := f32.Affine2D{}.Shear(f32.Point{}, angle, angle).Rotate(f32.Point{}, angle)
|
||||
op.Affine(a).Add(gtx.Ops)
|
||||
t := op.Affine(a).Push(gtx.Ops)
|
||||
|
||||
drawCore(gtx, th)
|
||||
|
||||
p.Load()
|
||||
t.Pop()
|
||||
w.Frame(gtx.Ops)
|
||||
}
|
||||
finishBenchmark(b, w)
|
||||
@@ -158,7 +156,6 @@ func Benchmark1000CirclesInstanced(b *testing.B) {
|
||||
func draw1000Circles(gtx layout.Context) {
|
||||
ops := gtx.Ops
|
||||
for x := 0; x < 100; x++ {
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
||||
for y := 0; y < 10; y++ {
|
||||
paint.FillShape(ops,
|
||||
@@ -167,7 +164,6 @@ func draw1000Circles(gtx layout.Context) {
|
||||
)
|
||||
op.Offset(f32.Pt(0, float32(100))).Add(ops)
|
||||
}
|
||||
p.Load()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,21 +171,18 @@ func draw1000CirclesInstanced(gtx layout.Context) {
|
||||
ops := gtx.Ops
|
||||
|
||||
r := op.Record(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
||||
cl := clip.RRect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
cl.Pop()
|
||||
c := r.Stop()
|
||||
|
||||
for x := 0; x < 100; x++ {
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
||||
for y := 0; y < 10; y++ {
|
||||
pi := op.Save(ops)
|
||||
paint.ColorOp{Color: color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||
c.Add(ops)
|
||||
pi.Load()
|
||||
op.Offset(f32.Pt(0, float32(100))).Add(ops)
|
||||
}
|
||||
p.Load()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +202,6 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp
|
||||
ops := &op1
|
||||
c := op.Record(ops)
|
||||
for x := 0; x < 9; x++ {
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*50), 0)).Add(ops)
|
||||
for y := 0; y < 9; y++ {
|
||||
paint.FillShape(ops,
|
||||
@@ -218,7 +210,6 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp
|
||||
)
|
||||
op.Offset(f32.Pt(0, float32(50))).Add(ops)
|
||||
}
|
||||
p.Load()
|
||||
}
|
||||
c1 <- c.Stop()
|
||||
}()
|
||||
@@ -232,18 +223,18 @@ func drawShapeInstances(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
||||
co := op.Record(ops)
|
||||
|
||||
r := op.Record(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
||||
cl := clip.RRect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
cl.Pop()
|
||||
c := r.Stop()
|
||||
|
||||
squares.Add(ops)
|
||||
rad := float32(0)
|
||||
for x := 0; x < 20; x++ {
|
||||
for y := 0; y < 20; y++ {
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*50+25), float32(y*50+25))).Add(ops)
|
||||
t := op.Offset(f32.Pt(float32(x*50+25), float32(y*50+25))).Push(ops)
|
||||
c.Add(ops)
|
||||
p.Load()
|
||||
t.Pop()
|
||||
rad += math.Pi * 2 / 400
|
||||
}
|
||||
}
|
||||
@@ -261,11 +252,10 @@ func drawText(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
||||
txt := material.H6(th, "")
|
||||
for x := 0; x < 40; x++ {
|
||||
txt.Text = textRows[x]
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(0), float32(24*x))).Add(ops)
|
||||
t := op.Offset(f32.Pt(float32(0), float32(24*x))).Push(ops)
|
||||
gtx.Ops = ops
|
||||
txt.Layout(gtx)
|
||||
p.Load()
|
||||
t.Pop()
|
||||
}
|
||||
c3 <- c.Stop()
|
||||
}()
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestPaintRect(t *testing.T) {
|
||||
|
||||
func TestPaintClippedRect(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
clip.RRect{Rect: f32.Rect(25, 25, 60, 60)}.Add(o)
|
||||
defer clip.RRect{Rect: f32.Rect(25, 25, 60, 60)}.Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 50, 50)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
@@ -42,8 +42,8 @@ func TestPaintClippedRect(t *testing.T) {
|
||||
func TestPaintClippedCircle(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
r := float32(10)
|
||||
clip.RRect{Rect: f32.Rect(20, 20, 40, 40), SE: r, SW: r, NW: r, NE: r}.Add(o)
|
||||
clip.Rect(image.Rect(0, 0, 30, 50)).Add(o)
|
||||
defer clip.RRect{Rect: f32.Rect(20, 20, 40, 40), SE: r, SW: r, NW: r, NE: r}.Push(o).Pop()
|
||||
defer clip.Rect(image.Rect(0, 0, 30, 50)).Push(o).Pop()
|
||||
paint.Fill(o, red)
|
||||
}, func(r result) {
|
||||
r.expect(21, 21, transparent)
|
||||
@@ -72,9 +72,9 @@ func TestPaintArc(t *testing.T) {
|
||||
p.Line(f32.Pt(0, -10))
|
||||
p.Line(f32.Pt(-50, 0))
|
||||
p.Close()
|
||||
clip.Outline{
|
||||
defer clip.Outline{
|
||||
Path: p.End(),
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o).Pop()
|
||||
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 128, 128)).Op())
|
||||
}, func(r result) {
|
||||
@@ -94,9 +94,9 @@ func TestPaintAbsolute(t *testing.T) {
|
||||
p.LineTo(f32.Pt(80, 20))
|
||||
p.QuadTo(f32.Pt(80, 80), f32.Pt(20, 80))
|
||||
p.Close()
|
||||
clip.Outline{
|
||||
defer clip.Outline{
|
||||
Path: p.End(),
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o).Pop()
|
||||
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 128, 128)).Op())
|
||||
}, func(r result) {
|
||||
@@ -110,7 +110,7 @@ func TestPaintAbsolute(t *testing.T) {
|
||||
func TestPaintTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
scale(80.0/512, 80.0/512).Add(o)
|
||||
defer scale(80.0/512, 80.0/512).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.Blue)
|
||||
@@ -123,15 +123,15 @@ 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{
|
||||
defer op.Offset(f32.Pt(50, 50)).Push(o).Pop()
|
||||
defer 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)
|
||||
}.Op().Push(o).Pop()
|
||||
defer clip.RRect{Rect: f32.Rect(-30, -30, 60, 60)}.Push(o).Pop()
|
||||
defer op.Offset(f32.Pt(-10, -10)).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
})
|
||||
@@ -140,14 +140,14 @@ func TestTexturedStrokeClipped(t *testing.T) {
|
||||
func TestTexturedStroke(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
smallSquares.Add(o)
|
||||
op.Offset(f32.Pt(50, 50)).Add(o)
|
||||
clip.Stroke{
|
||||
defer op.Offset(f32.Pt(50, 50)).Push(o).Pop()
|
||||
defer 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)
|
||||
}.Op().Push(o).Pop()
|
||||
defer op.Offset(f32.Pt(-10, -10)).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
})
|
||||
@@ -156,8 +156,8 @@ func TestTexturedStroke(t *testing.T) {
|
||||
func TestPaintClippedTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 40, 40)}.Add(o)
|
||||
scale(80.0/512, 80.0/512).Add(o)
|
||||
defer clip.RRect{Rect: f32.Rect(0, 0, 40, 40)}.Push(o).Pop()
|
||||
defer scale(80.0/512, 80.0/512).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(40, 40, transparent)
|
||||
@@ -168,14 +168,14 @@ func TestPaintClippedTexture(t *testing.T) {
|
||||
func TestStrokedPathBevelFlat(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
p := newStrokedPath(o)
|
||||
clip.Stroke{
|
||||
defer clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2.5,
|
||||
Cap: clip.FlatCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o).Pop()
|
||||
|
||||
paint.Fill(o, red)
|
||||
}, func(r result) {
|
||||
@@ -187,14 +187,14 @@ func TestStrokedPathBevelFlat(t *testing.T) {
|
||||
func TestStrokedPathBevelRound(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
p := newStrokedPath(o)
|
||||
clip.Stroke{
|
||||
defer clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2.5,
|
||||
Cap: clip.RoundCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o).Pop()
|
||||
|
||||
paint.Fill(o, red)
|
||||
}, func(r result) {
|
||||
@@ -206,14 +206,14 @@ func TestStrokedPathBevelRound(t *testing.T) {
|
||||
func TestStrokedPathBevelSquare(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
p := newStrokedPath(o)
|
||||
clip.Stroke{
|
||||
defer clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2.5,
|
||||
Cap: clip.SquareCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o).Pop()
|
||||
|
||||
paint.Fill(o, red)
|
||||
}, func(r result) {
|
||||
@@ -225,14 +225,14 @@ func TestStrokedPathBevelSquare(t *testing.T) {
|
||||
func TestStrokedPathRoundRound(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
p := newStrokedPath(o)
|
||||
clip.Stroke{
|
||||
defer clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2.5,
|
||||
Cap: clip.RoundCap,
|
||||
Join: clip.RoundJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o).Pop()
|
||||
|
||||
paint.Fill(o, red)
|
||||
}, func(r result) {
|
||||
@@ -244,9 +244,8 @@ func TestStrokedPathRoundRound(t *testing.T) {
|
||||
func TestStrokedPathFlatMiter(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 10,
|
||||
@@ -254,23 +253,22 @@ func TestStrokedPathFlatMiter(t *testing.T) {
|
||||
Join: clip.BevelJoin,
|
||||
Miter: 5,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2,
|
||||
Cap: clip.FlatCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
@@ -283,9 +281,8 @@ func TestStrokedPathFlatMiter(t *testing.T) {
|
||||
func TestStrokedPathFlatMiterInf(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 10,
|
||||
@@ -293,25 +290,23 @@ func TestStrokedPathFlatMiterInf(t *testing.T) {
|
||||
Join: clip.BevelJoin,
|
||||
Miter: float32(math.Inf(+1)),
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2,
|
||||
Cap: clip.FlatCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
r.expect(40, 10, colornames.Black)
|
||||
@@ -322,36 +317,34 @@ func TestStrokedPathFlatMiterInf(t *testing.T) {
|
||||
func TestStrokedPathZeroWidth(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := new(clip.Path)
|
||||
p.Begin(o)
|
||||
p.Move(f32.Pt(10, 50))
|
||||
p.Line(f32.Pt(50, 0))
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p.End(),
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2,
|
||||
Cap: clip.FlatCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
|
||||
paint.Fill(o, black)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := new(clip.Path)
|
||||
p.Begin(o)
|
||||
p.Move(f32.Pt(10, 50))
|
||||
p.Line(f32.Pt(30, 0))
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p.End(),
|
||||
}.Op().Add(o) // width=0, disable stroke
|
||||
}.Op().Push(o) // width=0, disable stroke
|
||||
|
||||
paint.Fill(o, red)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
@@ -365,7 +358,6 @@ func TestStrokedPathZeroWidth(t *testing.T) {
|
||||
func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newEllipsePath(o)
|
||||
|
||||
var dash clip.Dash
|
||||
@@ -373,7 +365,7 @@ func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
dash.Dash(5)
|
||||
dash.Dash(3)
|
||||
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 10,
|
||||
@@ -382,29 +374,28 @@ func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
Miter: float32(math.Inf(+1)),
|
||||
},
|
||||
Dashes: dash.End(),
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
|
||||
paint.Fill(
|
||||
o,
|
||||
red,
|
||||
)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newEllipsePath(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
|
||||
paint.Fill(
|
||||
o,
|
||||
black,
|
||||
)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
@@ -417,14 +408,13 @@ func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
func TestDashedPathFlatCapZ(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
var dash clip.Dash
|
||||
dash.Begin(o)
|
||||
dash.Dash(5)
|
||||
dash.Dash(3)
|
||||
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 10,
|
||||
@@ -433,24 +423,23 @@ func TestDashedPathFlatCapZ(t *testing.T) {
|
||||
Miter: float32(math.Inf(+1)),
|
||||
},
|
||||
Dashes: dash.End(),
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2,
|
||||
Cap: clip.FlatCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
@@ -463,13 +452,12 @@ func TestDashedPathFlatCapZ(t *testing.T) {
|
||||
func TestDashedPathFlatCapZNoDash(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
var dash clip.Dash
|
||||
dash.Begin(o)
|
||||
dash.Phase(1)
|
||||
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 10,
|
||||
@@ -478,22 +466,21 @@ func TestDashedPathFlatCapZNoDash(t *testing.T) {
|
||||
Miter: float32(math.Inf(+1)),
|
||||
},
|
||||
Dashes: dash.End(),
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
{
|
||||
stk := op.Save(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: newZigZagPath(o),
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2,
|
||||
Cap: clip.FlatCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
@@ -506,11 +493,10 @@ func TestDashedPathFlatCapZNoDash(t *testing.T) {
|
||||
func TestDashedPathFlatCapZNoPath(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Save(o)
|
||||
var dash clip.Dash
|
||||
dash.Begin(o)
|
||||
dash.Dash(0)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: newZigZagPath(o),
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 10,
|
||||
@@ -519,23 +505,22 @@ func TestDashedPathFlatCapZNoPath(t *testing.T) {
|
||||
Miter: float32(math.Inf(+1)),
|
||||
},
|
||||
Dashes: dash.End(),
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
{
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
cl := clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{
|
||||
Width: 2,
|
||||
Cap: clip.FlatCap,
|
||||
Join: clip.BevelJoin,
|
||||
},
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Load()
|
||||
cl.Pop()
|
||||
}
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
|
||||
@@ -35,26 +35,24 @@ func TestTransformMacro(t *testing.T) {
|
||||
m2 := op.Record(o)
|
||||
paint.ColorOp{Color: red}.Add(o)
|
||||
// Simulate a draw text call
|
||||
stack := op.Save(o)
|
||||
op.Offset(f32.Pt(0, 10)).Add(o)
|
||||
t := op.Offset(f32.Pt(0, 10)).Push(o)
|
||||
|
||||
// Apply the clip-path.
|
||||
c.Add(o)
|
||||
cl := c.Push(o)
|
||||
|
||||
paint.PaintOp{}.Add(o)
|
||||
stack.Load()
|
||||
cl.Pop()
|
||||
t.Pop()
|
||||
|
||||
c2 := m2.Stop()
|
||||
|
||||
// Call each of them in a transform
|
||||
s1 := op.Save(o)
|
||||
op.Offset(f32.Pt(0, 0)).Add(o)
|
||||
t = op.Offset(f32.Pt(0, 0)).Push(o)
|
||||
c1.Add(o)
|
||||
s1.Load()
|
||||
s2 := op.Save(o)
|
||||
op.Offset(f32.Pt(0, 0)).Add(o)
|
||||
t.Pop()
|
||||
t = op.Offset(f32.Pt(0, 0)).Push(o)
|
||||
c2.Add(o)
|
||||
s2.Load()
|
||||
t.Pop()
|
||||
}, func(r result) {
|
||||
r.expect(5, 15, colornames.Red)
|
||||
r.expect(15, 15, colornames.Black)
|
||||
@@ -75,9 +73,9 @@ func TestRepeatedPaintsZ(t *testing.T) {
|
||||
builder.Line(f32.Pt(-10, 0))
|
||||
builder.Line(f32.Pt(0, -10))
|
||||
p := builder.End()
|
||||
clip.Outline{
|
||||
defer clip.Outline{
|
||||
Path: p,
|
||||
}.Op().Add(o)
|
||||
}.Op().Push(o).Pop()
|
||||
paint.Fill(o, red)
|
||||
}, func(r result) {
|
||||
r.expect(5, 5, colornames.Red)
|
||||
@@ -91,10 +89,10 @@ func TestNoClipFromPaint(t *testing.T) {
|
||||
// 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)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
paint.FillShape(o, 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)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
|
||||
paint.FillShape(o, black, clip.Rect(image.Rect(0, 0, 50, 50)).Op())
|
||||
}, func(r result) {
|
||||
@@ -107,31 +105,31 @@ func TestNoClipFromPaint(t *testing.T) {
|
||||
|
||||
func TestDeferredPaint(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
state := op.Save(o)
|
||||
clip.Rect(image.Rect(0, 0, 80, 80)).Op().Add(o)
|
||||
cl := clip.Rect(image.Rect(0, 0, 80, 80)).Op().Push(o)
|
||||
paint.ColorOp{Color: color.NRGBA{A: 0x60, G: 0xff}}.Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
cl.Pop()
|
||||
|
||||
op.Affine(f32.Affine2D{}.Offset(f32.Pt(20, 20))).Add(o)
|
||||
t := op.Affine(f32.Affine2D{}.Offset(f32.Pt(20, 20))).Push(o)
|
||||
m := op.Record(o)
|
||||
clip.Rect(image.Rect(0, 0, 80, 80)).Op().Add(o)
|
||||
cl2 := clip.Rect(image.Rect(0, 0, 80, 80)).Op().Push(o)
|
||||
paint.ColorOp{Color: color.NRGBA{A: 0x60, R: 0xff, G: 0xff}}.Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
cl2.Pop()
|
||||
paintMacro := m.Stop()
|
||||
op.Defer(o, paintMacro)
|
||||
t.Pop()
|
||||
|
||||
state.Load()
|
||||
op.Affine(f32.Affine2D{}.Offset(f32.Pt(10, 10))).Add(o)
|
||||
clip.Rect(image.Rect(0, 0, 80, 80)).Op().Add(o)
|
||||
defer op.Affine(f32.Affine2D{}.Offset(f32.Pt(10, 10))).Push(o).Pop()
|
||||
defer clip.Rect(image.Rect(0, 0, 80, 80)).Op().Push(o).Pop()
|
||||
paint.ColorOp{Color: color.NRGBA{A: 0x60, B: 0xff}}.Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
})
|
||||
}
|
||||
|
||||
func constSqPath() op.CallOp {
|
||||
func constSqPath() clip.Op {
|
||||
innerOps := new(op.Ops)
|
||||
m := op.Record(innerOps)
|
||||
builder := clip.Path{}
|
||||
builder.Begin(innerOps)
|
||||
builder.Move(f32.Pt(0, 0))
|
||||
@@ -140,22 +138,20 @@ func constSqPath() op.CallOp {
|
||||
builder.Line(f32.Pt(-10, 0))
|
||||
builder.Line(f32.Pt(0, -10))
|
||||
p := builder.End()
|
||||
clip.Outline{Path: p}.Op().Add(innerOps)
|
||||
return m.Stop()
|
||||
return clip.Outline{Path: p}.Op()
|
||||
}
|
||||
|
||||
func constSqCirc() op.CallOp {
|
||||
func constSqCirc() clip.Op {
|
||||
innerOps := new(op.Ops)
|
||||
m := op.Record(innerOps)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 40, 40),
|
||||
NW: 20, NE: 20, SW: 20, SE: 20}.Add(innerOps)
|
||||
return m.Stop()
|
||||
return clip.RRect{Rect: f32.Rect(0, 0, 40, 40),
|
||||
NW: 20, NE: 20, SW: 20, SE: 20}.Op(innerOps)
|
||||
}
|
||||
|
||||
func drawChild(ops *op.Ops, text op.CallOp) op.CallOp {
|
||||
func drawChild(ops *op.Ops, text clip.Op) op.CallOp {
|
||||
r1 := op.Record(ops)
|
||||
text.Add(ops)
|
||||
cl := text.Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
cl.Pop()
|
||||
return r1.Stop()
|
||||
}
|
||||
|
||||
@@ -166,14 +162,10 @@ func TestReuseStencil(t *testing.T) {
|
||||
c2 := drawChild(ops, txt)
|
||||
|
||||
// lay out the children
|
||||
stack1 := op.Save(ops)
|
||||
c1.Add(ops)
|
||||
stack1.Load()
|
||||
|
||||
stack2 := op.Save(ops)
|
||||
op.Offset(f32.Pt(0, 50)).Add(ops)
|
||||
defer op.Offset(f32.Pt(0, 50)).Push(ops).Pop()
|
||||
c2.Add(ops)
|
||||
stack2.Load()
|
||||
}, func(r result) {
|
||||
r.expect(5, 5, colornames.Black)
|
||||
r.expect(5, 55, colornames.Black)
|
||||
@@ -187,11 +179,9 @@ func TestBuildOffscreen(t *testing.T) {
|
||||
|
||||
txt := constSqCirc()
|
||||
draw := func(off float32, o *op.Ops) {
|
||||
s := op.Save(o)
|
||||
op.Offset(f32.Pt(0, off)).Add(o)
|
||||
txt.Add(o)
|
||||
defer op.Offset(f32.Pt(0, off)).Push(o).Pop()
|
||||
defer txt.Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
s.Load()
|
||||
}
|
||||
|
||||
multiRun(t,
|
||||
@@ -214,8 +204,8 @@ func TestBuildOffscreen(t *testing.T) {
|
||||
|
||||
func TestNegativeOverlaps(t *testing.T) {
|
||||
run(t, func(ops *op.Ops) {
|
||||
clip.RRect{Rect: f32.Rect(50, 50, 100, 100)}.Add(ops)
|
||||
clip.Rect(image.Rect(0, 120, 100, 122)).Add(ops)
|
||||
defer clip.RRect{Rect: f32.Rect(50, 50, 100, 100)}.Push(ops).Pop()
|
||||
clip.Rect(image.Rect(0, 120, 100, 122)).Push(ops).Pop()
|
||||
paint.PaintOp{}.Add(ops)
|
||||
}, func(r result) {
|
||||
r.expect(60, 60, transparent)
|
||||
@@ -227,13 +217,8 @@ func TestNegativeOverlaps(t *testing.T) {
|
||||
|
||||
func TestDepthOverlap(t *testing.T) {
|
||||
run(t, func(ops *op.Ops) {
|
||||
stack := op.Save(ops)
|
||||
paint.FillShape(ops, red, clip.Rect{Max: image.Pt(128, 64)}.Op())
|
||||
stack.Load()
|
||||
|
||||
stack = op.Save(ops)
|
||||
paint.FillShape(ops, green, clip.Rect{Max: image.Pt(64, 128)}.Op())
|
||||
stack.Load()
|
||||
}, func(r result) {
|
||||
r.expect(96, 32, colornames.Red)
|
||||
r.expect(32, 96, colornames.Green)
|
||||
@@ -272,12 +257,13 @@ func TestLinearGradient(t *testing.T) {
|
||||
Stop2: f32.Pt(gr.Max.X, gr.Min.Y),
|
||||
Color2: g.To,
|
||||
}.Add(ops)
|
||||
st := op.Save(ops)
|
||||
clip.RRect{Rect: gr}.Add(ops)
|
||||
op.Affine(f32.Affine2D{}.Offset(pixelAligned.Min)).Add(ops)
|
||||
scale(pixelAligned.Dx()/128, 1).Add(ops)
|
||||
cl := clip.RRect{Rect: gr}.Push(ops)
|
||||
t1 := op.Affine(f32.Affine2D{}.Offset(pixelAligned.Min)).Push(ops)
|
||||
t2 := scale(pixelAligned.Dx()/128, 1).Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Load()
|
||||
t2.Pop()
|
||||
t1.Pop()
|
||||
cl.Pop()
|
||||
gr = gr.Add(f32.Pt(0, gradienth))
|
||||
}
|
||||
}, func(r result) {
|
||||
@@ -302,10 +288,9 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(0, 0),
|
||||
Color2: red,
|
||||
}.Add(ops)
|
||||
st := op.Save(ops)
|
||||
clip.Rect(image.Rect(0, 0, 64, 64)).Add(ops)
|
||||
cl := clip.Rect(image.Rect(0, 0, 64, 64)).Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Load()
|
||||
cl.Pop()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -313,10 +298,9 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(128, 0),
|
||||
Color2: green,
|
||||
}.Add(ops)
|
||||
st = op.Save(ops)
|
||||
clip.Rect(image.Rect(64, 0, 128, 64)).Add(ops)
|
||||
cl = clip.Rect(image.Rect(64, 0, 128, 64)).Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Load()
|
||||
cl.Pop()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -324,10 +308,9 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(128, 128),
|
||||
Color2: blue,
|
||||
}.Add(ops)
|
||||
st = op.Save(ops)
|
||||
clip.Rect(image.Rect(64, 64, 128, 128)).Add(ops)
|
||||
cl = clip.Rect(image.Rect(64, 64, 128, 128)).Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Load()
|
||||
cl.Pop()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -335,10 +318,9 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(0, 128),
|
||||
Color2: magenta,
|
||||
}.Add(ops)
|
||||
st = op.Save(ops)
|
||||
clip.Rect(image.Rect(0, 64, 64, 128)).Add(ops)
|
||||
cl = clip.Rect(image.Rect(0, 64, 64, 128)).Push(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Load()
|
||||
cl.Pop()
|
||||
}, func(r result) {})
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
func TestPaintOffset(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
op.Offset(f32.Pt(10, 20)).Add(o)
|
||||
defer op.Offset(f32.Pt(10, 20)).Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 50, 50)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
@@ -30,7 +30,7 @@ func TestPaintOffset(t *testing.T) {
|
||||
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)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(20, 20, 60, 60)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(40, 40, colornames.Red)
|
||||
@@ -43,7 +43,7 @@ func TestPaintRotate(t *testing.T) {
|
||||
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)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 40, 40)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(10, 30, transparent)
|
||||
@@ -52,8 +52,8 @@ func TestPaintShear(t *testing.T) {
|
||||
|
||||
func TestClipPaintOffset(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o)
|
||||
op.Offset(f32.Pt(20, 20)).Add(o)
|
||||
defer clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Push(o).Pop()
|
||||
defer op.Offset(f32.Pt(20, 20)).Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 100, 100)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
@@ -65,8 +65,8 @@ func TestClipPaintOffset(t *testing.T) {
|
||||
|
||||
func TestClipOffset(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
op.Offset(f32.Pt(20, 20)).Add(o)
|
||||
clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o)
|
||||
defer op.Offset(f32.Pt(20, 20)).Push(o).Pop()
|
||||
defer clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 100, 100)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
@@ -80,8 +80,8 @@ func TestClipOffset(t *testing.T) {
|
||||
func TestClipScale(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
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)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
defer clip.RRect{Rect: f32.Rect(10, 10, 20, 20)}.Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 1000, 1000)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(19+10, 19+10, transparent)
|
||||
@@ -93,8 +93,8 @@ func TestClipScale(t *testing.T) {
|
||||
|
||||
func TestClipRotate(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
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)
|
||||
defer op.Affine(f32.Affine2D{}.Rotate(f32.Pt(40, 40), -math.Pi/4)).Push(o).Pop()
|
||||
defer clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 40, 100, 100)).Op())
|
||||
}, func(r result) {
|
||||
r.expect(39, 39, transparent)
|
||||
@@ -105,9 +105,9 @@ func TestClipRotate(t *testing.T) {
|
||||
|
||||
func TestOffsetTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
op.Offset(f32.Pt(15, 15)).Add(o)
|
||||
defer op.Offset(f32.Pt(15, 15)).Push(o).Pop()
|
||||
squares.Add(o)
|
||||
scale(50.0/512, 50.0/512).Add(o)
|
||||
defer scale(50.0/512, 50.0/512).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(14, 20, transparent)
|
||||
@@ -119,10 +119,10 @@ func TestOffsetTexture(t *testing.T) {
|
||||
|
||||
func TestOffsetScaleTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
op.Offset(f32.Pt(15, 15)).Add(o)
|
||||
defer op.Offset(f32.Pt(15, 15)).Push(o).Pop()
|
||||
squares.Add(o)
|
||||
op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(2, 1))).Add(o)
|
||||
scale(50.0/512, 50.0/512).Add(o)
|
||||
defer op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(2, 1))).Push(o).Pop()
|
||||
defer scale(50.0/512, 50.0/512).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(114, 64, colornames.Blue)
|
||||
@@ -132,11 +132,10 @@ func TestOffsetScaleTexture(t *testing.T) {
|
||||
|
||||
func TestRotateTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
defer op.Save(o).Load()
|
||||
squares.Add(o)
|
||||
a := f32.Affine2D{}.Offset(f32.Pt(30, 30)).Rotate(f32.Pt(40, 40), math.Pi/4)
|
||||
op.Affine(a).Add(o)
|
||||
scale(20.0/512, 20.0/512).Add(o)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
defer scale(20.0/512, 20.0/512).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(40, 40-12, colornames.Blue)
|
||||
@@ -148,10 +147,10 @@ func TestRotateClipTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
a := f32.Affine2D{}.Rotate(f32.Pt(40, 40), math.Pi/8)
|
||||
op.Affine(a).Add(o)
|
||||
clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o)
|
||||
op.Affine(f32.Affine2D{}.Offset(f32.Pt(10, 10))).Add(o)
|
||||
scale(60.0/512, 60.0/512).Add(o)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
defer clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Push(o).Pop()
|
||||
defer op.Affine(f32.Affine2D{}.Offset(f32.Pt(10, 10))).Push(o).Pop()
|
||||
defer scale(60.0/512, 60.0/512).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, transparent)
|
||||
@@ -167,13 +166,13 @@ func TestComplicatedTransform(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 100, 100), SE: 50, SW: 50, NW: 50, NE: 50}.Add(o)
|
||||
defer clip.RRect{Rect: f32.Rect(0, 0, 100, 100), SE: 50, SW: 50, NW: 50, NE: 50}.Push(o).Pop()
|
||||
|
||||
a := f32.Affine2D{}.Shear(f32.Point{}, math.Pi/4, 0)
|
||||
op.Affine(a).Add(o)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 50, 40)}.Add(o)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
defer clip.RRect{Rect: f32.Rect(0, 0, 50, 40)}.Push(o).Pop()
|
||||
|
||||
scale(50.0/512, 50.0/512).Add(o)
|
||||
defer scale(50.0/512, 50.0/512).Push(o).Pop()
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(20, 5, transparent)
|
||||
@@ -184,13 +183,13 @@ func TestTransformOrder(t *testing.T) {
|
||||
// check the ordering of operations bot in affine and in gpu stack.
|
||||
run(t, func(o *op.Ops) {
|
||||
a := f32.Affine2D{}.Offset(f32.Pt(64, 64))
|
||||
op.Affine(a).Add(o)
|
||||
defer op.Affine(a).Push(o).Pop()
|
||||
|
||||
b := f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(8, 8))
|
||||
op.Affine(b).Add(o)
|
||||
defer op.Affine(b).Push(o).Pop()
|
||||
|
||||
c := f32.Affine2D{}.Offset(f32.Pt(-10, -10)).Scale(f32.Point{}, f32.Pt(0.5, 0.5))
|
||||
op.Affine(c).Add(o)
|
||||
defer op.Affine(c).Push(o).Pop()
|
||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 20, 20)).Op())
|
||||
}, func(r result) {
|
||||
// centered and with radius 40
|
||||
|
||||
Reference in New Issue
Block a user