diff --git a/gpu/headless/headless.go b/gpu/headless/headless.go index a9b9e344..859fdef3 100644 --- a/gpu/headless/headless.go +++ b/gpu/headless/headless.go @@ -110,7 +110,7 @@ func (w *Window) Release() { func (w *Window) Frame(frame *op.Ops) error { return contextDo(w.ctx, func() error { w.dev.BindFramebuffer(w.fbo) - w.gpu.Clear(color.NRGBA{A: 0xff, R: 0xff, G: 0xff, B: 0xff}) + w.gpu.Clear(color.NRGBA{}) w.gpu.Collect(w.size, frame) return w.gpu.Frame() }) diff --git a/gpu/headless/headless_test.go b/gpu/headless/headless_test.go index 516ea0b9..eee55232 100644 --- a/gpu/headless/headless_test.go +++ b/gpu/headless/headless_test.go @@ -78,7 +78,7 @@ func TestClipping(t *testing.T) { t.Fatal(err) } } - bg := color.NRGBA{A: 0xff, R: 0xff, G: 0xff, B: 0xff} + var bg color.NRGBA tests := []struct { x, y int color color.NRGBA diff --git a/gpu/internal/rendertest/clip_test.go b/gpu/internal/rendertest/clip_test.go index c8d73508..c98839d4 100644 --- a/gpu/internal/rendertest/clip_test.go +++ b/gpu/internal/rendertest/clip_test.go @@ -19,8 +19,8 @@ func TestPaintRect(t *testing.T) { }, func(r result) { r.expect(0, 0, colornames.Red) r.expect(49, 0, colornames.Red) - r.expect(50, 0, colornames.White) - r.expect(10, 50, colornames.White) + r.expect(50, 0, transparent) + r.expect(10, 50, transparent) }) } @@ -29,11 +29,11 @@ func TestPaintClippedRect(t *testing.T) { clip.RRect{Rect: f32.Rect(25, 25, 60, 60)}.Add(o) paint.FillShape(o, 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) + r.expect(0, 0, transparent) + r.expect(24, 35, transparent) r.expect(25, 35, colornames.Red) - r.expect(50, 0, colornames.White) - r.expect(10, 50, colornames.White) + r.expect(50, 0, transparent) + r.expect(10, 50, transparent) }) } @@ -44,9 +44,9 @@ func TestPaintClippedCircle(t *testing.T) { clip.Rect(image.Rect(0, 0, 30, 50)).Add(o) paint.Fill(o, red) }, func(r result) { - r.expect(21, 21, colornames.White) + r.expect(21, 21, transparent) r.expect(25, 30, colornames.Red) - r.expect(31, 30, colornames.White) + r.expect(31, 30, transparent) }) } @@ -76,9 +76,9 @@ func TestPaintArc(t *testing.T) { paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 128, 128)).Op()) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(0, 25, colornames.Red) - r.expect(0, 15, colornames.White) + r.expect(0, 15, transparent) }) } @@ -98,10 +98,10 @@ func TestPaintAbsolute(t *testing.T) { paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 128, 128)).Op()) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(30, 30, colornames.Red) - r.expect(79, 79, colornames.White) - r.expect(90, 90, colornames.White) + r.expect(79, 79, transparent) + r.expect(90, 90, transparent) }) } @@ -113,8 +113,8 @@ func TestPaintTexture(t *testing.T) { }, func(r result) { r.expect(0, 0, colornames.Blue) r.expect(79, 10, colornames.Green) - r.expect(80, 0, colornames.White) - r.expect(10, 80, colornames.White) + r.expect(80, 0, transparent) + r.expect(10, 80, transparent) }) } @@ -158,7 +158,7 @@ func TestPaintClippedTexture(t *testing.T) { scale(80.0/512, 80.0/512).Add(o) paint.PaintOp{}.Add(o) }, func(r result) { - r.expect(40, 40, colornames.White) + r.expect(40, 40, transparent) r.expect(25, 35, colornames.Blue) }) } @@ -177,7 +177,7 @@ func TestStrokedPathBevelFlat(t *testing.T) { paint.Fill(o, red) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(10, 50, colornames.Red) }) } @@ -196,7 +196,7 @@ func TestStrokedPathBevelRound(t *testing.T) { paint.Fill(o, red) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(10, 50, colornames.Red) }) } @@ -215,7 +215,7 @@ func TestStrokedPathBevelSquare(t *testing.T) { paint.Fill(o, red) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(10, 50, colornames.Red) }) } @@ -234,7 +234,7 @@ func TestStrokedPathRoundRound(t *testing.T) { paint.Fill(o, red) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(10, 50, colornames.Red) }) } @@ -272,7 +272,7 @@ func TestStrokedPathFlatMiter(t *testing.T) { } }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(40, 10, colornames.Black) r.expect(40, 12, colornames.Red) }) @@ -311,7 +311,7 @@ func TestStrokedPathFlatMiterInf(t *testing.T) { } }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(40, 10, colornames.Black) r.expect(40, 12, colornames.Red) }) @@ -353,10 +353,10 @@ func TestStrokedPathZeroWidth(t *testing.T) { } }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(10, 50, colornames.Black) r.expect(30, 50, colornames.Black) - r.expect(65, 50, colornames.White) + r.expect(65, 50, transparent) }) } @@ -406,7 +406,7 @@ func TestDashedPathFlatCapEllipse(t *testing.T) { } }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(0, 62, colornames.Red) r.expect(0, 65, colornames.Black) }) @@ -451,10 +451,10 @@ func TestDashedPathFlatCapZ(t *testing.T) { stk.Load() } }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(40, 10, colornames.Black) r.expect(40, 12, colornames.Red) - r.expect(46, 12, colornames.White) + r.expect(46, 12, transparent) }) } @@ -494,7 +494,7 @@ func TestDashedPathFlatCapZNoDash(t *testing.T) { stk.Load() } }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(40, 10, colornames.Black) r.expect(40, 12, colornames.Red) r.expect(46, 12, colornames.Red) @@ -536,10 +536,10 @@ func TestDashedPathFlatCapZNoPath(t *testing.T) { stk.Load() } }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(40, 10, colornames.Black) - r.expect(40, 12, colornames.White) - r.expect(46, 12, colornames.White) + r.expect(40, 12, transparent) + r.expect(46, 12, transparent) }) } diff --git a/gpu/internal/rendertest/refs/TestBuildOffscreen.png b/gpu/internal/rendertest/refs/TestBuildOffscreen.png index 9ed91358..fb50427e 100644 Binary files a/gpu/internal/rendertest/refs/TestBuildOffscreen.png and b/gpu/internal/rendertest/refs/TestBuildOffscreen.png differ diff --git a/gpu/internal/rendertest/refs/TestBuildOffscreen_1.png b/gpu/internal/rendertest/refs/TestBuildOffscreen_1.png index 88134115..8ff717ba 100644 Binary files a/gpu/internal/rendertest/refs/TestBuildOffscreen_1.png and b/gpu/internal/rendertest/refs/TestBuildOffscreen_1.png differ diff --git a/gpu/internal/rendertest/refs/TestClipOffset.png b/gpu/internal/rendertest/refs/TestClipOffset.png index 59371e42..6396fb4f 100644 Binary files a/gpu/internal/rendertest/refs/TestClipOffset.png and b/gpu/internal/rendertest/refs/TestClipOffset.png differ diff --git a/gpu/internal/rendertest/refs/TestClipPaintOffset.png b/gpu/internal/rendertest/refs/TestClipPaintOffset.png index f9988440..0fe37e6f 100644 Binary files a/gpu/internal/rendertest/refs/TestClipPaintOffset.png and b/gpu/internal/rendertest/refs/TestClipPaintOffset.png differ diff --git a/gpu/internal/rendertest/refs/TestClipRotate.png b/gpu/internal/rendertest/refs/TestClipRotate.png index e6c0e4e5..e6c15e33 100644 Binary files a/gpu/internal/rendertest/refs/TestClipRotate.png and b/gpu/internal/rendertest/refs/TestClipRotate.png differ diff --git a/gpu/internal/rendertest/refs/TestClipScale.png b/gpu/internal/rendertest/refs/TestClipScale.png index 59371e42..6396fb4f 100644 Binary files a/gpu/internal/rendertest/refs/TestClipScale.png and b/gpu/internal/rendertest/refs/TestClipScale.png differ diff --git a/gpu/internal/rendertest/refs/TestComplicatedTransform.png b/gpu/internal/rendertest/refs/TestComplicatedTransform.png index c1f3aeb9..4a92e3c7 100644 Binary files a/gpu/internal/rendertest/refs/TestComplicatedTransform.png and b/gpu/internal/rendertest/refs/TestComplicatedTransform.png differ diff --git a/gpu/internal/rendertest/refs/TestDashedPathFlatCapEllipse.png b/gpu/internal/rendertest/refs/TestDashedPathFlatCapEllipse.png index 03843489..79bae384 100644 Binary files a/gpu/internal/rendertest/refs/TestDashedPathFlatCapEllipse.png and b/gpu/internal/rendertest/refs/TestDashedPathFlatCapEllipse.png differ diff --git a/gpu/internal/rendertest/refs/TestDashedPathFlatCapZ.png b/gpu/internal/rendertest/refs/TestDashedPathFlatCapZ.png index 10695941..12212e99 100644 Binary files a/gpu/internal/rendertest/refs/TestDashedPathFlatCapZ.png and b/gpu/internal/rendertest/refs/TestDashedPathFlatCapZ.png differ diff --git a/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoDash.png b/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoDash.png index 23a13c3b..d315f0f8 100644 Binary files a/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoDash.png and b/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoDash.png differ diff --git a/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoPath.png b/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoPath.png index 35158fc4..94c160ef 100644 Binary files a/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoPath.png and b/gpu/internal/rendertest/refs/TestDashedPathFlatCapZNoPath.png differ diff --git a/gpu/internal/rendertest/refs/TestDeferredPaint.png b/gpu/internal/rendertest/refs/TestDeferredPaint.png index 1446810f..b562f12a 100644 Binary files a/gpu/internal/rendertest/refs/TestDeferredPaint.png and b/gpu/internal/rendertest/refs/TestDeferredPaint.png differ diff --git a/gpu/internal/rendertest/refs/TestDepthOverlap.png b/gpu/internal/rendertest/refs/TestDepthOverlap.png index 6c5d9980..9d416b9f 100644 Binary files a/gpu/internal/rendertest/refs/TestDepthOverlap.png and b/gpu/internal/rendertest/refs/TestDepthOverlap.png differ diff --git a/gpu/internal/rendertest/refs/TestLinearGradient.png b/gpu/internal/rendertest/refs/TestLinearGradient.png deleted file mode 100644 index e6cb0946..00000000 Binary files a/gpu/internal/rendertest/refs/TestLinearGradient.png and /dev/null differ diff --git a/gpu/internal/rendertest/refs/TestLinearGradientAngled.png b/gpu/internal/rendertest/refs/TestLinearGradientAngled.png index 4665fc65..3ba0734c 100644 Binary files a/gpu/internal/rendertest/refs/TestLinearGradientAngled.png and b/gpu/internal/rendertest/refs/TestLinearGradientAngled.png differ diff --git a/gpu/internal/rendertest/refs/TestNegativeOverlaps.png b/gpu/internal/rendertest/refs/TestNegativeOverlaps.png index 9ed91358..fb50427e 100644 Binary files a/gpu/internal/rendertest/refs/TestNegativeOverlaps.png and b/gpu/internal/rendertest/refs/TestNegativeOverlaps.png differ diff --git a/gpu/internal/rendertest/refs/TestNoClipFromPaint.png b/gpu/internal/rendertest/refs/TestNoClipFromPaint.png index b382f873..e774064b 100644 Binary files a/gpu/internal/rendertest/refs/TestNoClipFromPaint.png and b/gpu/internal/rendertest/refs/TestNoClipFromPaint.png differ diff --git a/gpu/internal/rendertest/refs/TestOffsetScaleTexture.png b/gpu/internal/rendertest/refs/TestOffsetScaleTexture.png index 47df5779..515a4d24 100644 Binary files a/gpu/internal/rendertest/refs/TestOffsetScaleTexture.png and b/gpu/internal/rendertest/refs/TestOffsetScaleTexture.png differ diff --git a/gpu/internal/rendertest/refs/TestOffsetTexture.png b/gpu/internal/rendertest/refs/TestOffsetTexture.png index f8d8e6fb..87386e88 100644 Binary files a/gpu/internal/rendertest/refs/TestOffsetTexture.png and b/gpu/internal/rendertest/refs/TestOffsetTexture.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintAbsolute.png b/gpu/internal/rendertest/refs/TestPaintAbsolute.png index f8680aac..dd097607 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintAbsolute.png and b/gpu/internal/rendertest/refs/TestPaintAbsolute.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintArc.png b/gpu/internal/rendertest/refs/TestPaintArc.png index 8ffb300e..f432914f 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintArc.png and b/gpu/internal/rendertest/refs/TestPaintArc.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintClippedBorder.png b/gpu/internal/rendertest/refs/TestPaintClippedBorder.png deleted file mode 100644 index eb866d2c..00000000 Binary files a/gpu/internal/rendertest/refs/TestPaintClippedBorder.png and /dev/null differ diff --git a/gpu/internal/rendertest/refs/TestPaintClippedCircle.png b/gpu/internal/rendertest/refs/TestPaintClippedCircle.png index 9aa298e9..bdf1fced 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintClippedCircle.png and b/gpu/internal/rendertest/refs/TestPaintClippedCircle.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintClippedCirle.png b/gpu/internal/rendertest/refs/TestPaintClippedCirle.png deleted file mode 100644 index 9aa298e9..00000000 Binary files a/gpu/internal/rendertest/refs/TestPaintClippedCirle.png and /dev/null differ diff --git a/gpu/internal/rendertest/refs/TestPaintClippedRect.png b/gpu/internal/rendertest/refs/TestPaintClippedRect.png index 4bd3e5cb..c1dd7a0a 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintClippedRect.png and b/gpu/internal/rendertest/refs/TestPaintClippedRect.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintClippedTexture.png b/gpu/internal/rendertest/refs/TestPaintClippedTexture.png index ee95e5b8..ae0e0661 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintClippedTexture.png and b/gpu/internal/rendertest/refs/TestPaintClippedTexture.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintOffset.png b/gpu/internal/rendertest/refs/TestPaintOffset.png index aa5d7d8f..82394d57 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintOffset.png and b/gpu/internal/rendertest/refs/TestPaintOffset.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintRect.png b/gpu/internal/rendertest/refs/TestPaintRect.png index 0195a6be..f942601f 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintRect.png and b/gpu/internal/rendertest/refs/TestPaintRect.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintRotate.png b/gpu/internal/rendertest/refs/TestPaintRotate.png index 4cf9c851..fe15d7dc 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintRotate.png and b/gpu/internal/rendertest/refs/TestPaintRotate.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintShear.png b/gpu/internal/rendertest/refs/TestPaintShear.png index 0a7d553c..6d1a4c92 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintShear.png and b/gpu/internal/rendertest/refs/TestPaintShear.png differ diff --git a/gpu/internal/rendertest/refs/TestPaintTexture.png b/gpu/internal/rendertest/refs/TestPaintTexture.png index 33feacd3..91202317 100644 Binary files a/gpu/internal/rendertest/refs/TestPaintTexture.png and b/gpu/internal/rendertest/refs/TestPaintTexture.png differ diff --git a/gpu/internal/rendertest/refs/TestRepeatedPaintsZ.png b/gpu/internal/rendertest/refs/TestRepeatedPaintsZ.png index 1da62245..da201dca 100644 Binary files a/gpu/internal/rendertest/refs/TestRepeatedPaintsZ.png and b/gpu/internal/rendertest/refs/TestRepeatedPaintsZ.png differ diff --git a/gpu/internal/rendertest/refs/TestReuseStencil.png b/gpu/internal/rendertest/refs/TestReuseStencil.png index 7ea05a00..349db1fc 100644 Binary files a/gpu/internal/rendertest/refs/TestReuseStencil.png and b/gpu/internal/rendertest/refs/TestReuseStencil.png differ diff --git a/gpu/internal/rendertest/refs/TestRotateClipTexture.png b/gpu/internal/rendertest/refs/TestRotateClipTexture.png index 8cd211d4..56c3182a 100644 Binary files a/gpu/internal/rendertest/refs/TestRotateClipTexture.png and b/gpu/internal/rendertest/refs/TestRotateClipTexture.png differ diff --git a/gpu/internal/rendertest/refs/TestRotateTexture.png b/gpu/internal/rendertest/refs/TestRotateTexture.png index 874e8384..e56c9725 100644 Binary files a/gpu/internal/rendertest/refs/TestRotateTexture.png and b/gpu/internal/rendertest/refs/TestRotateTexture.png differ diff --git a/gpu/internal/rendertest/refs/TestStrokedPathBevelFlat.png b/gpu/internal/rendertest/refs/TestStrokedPathBevelFlat.png index 861b57f7..9d442f5a 100644 Binary files a/gpu/internal/rendertest/refs/TestStrokedPathBevelFlat.png and b/gpu/internal/rendertest/refs/TestStrokedPathBevelFlat.png differ diff --git a/gpu/internal/rendertest/refs/TestStrokedPathBevelRound.png b/gpu/internal/rendertest/refs/TestStrokedPathBevelRound.png index 36ba27a2..a37235cc 100644 Binary files a/gpu/internal/rendertest/refs/TestStrokedPathBevelRound.png and b/gpu/internal/rendertest/refs/TestStrokedPathBevelRound.png differ diff --git a/gpu/internal/rendertest/refs/TestStrokedPathBevelSquare.png b/gpu/internal/rendertest/refs/TestStrokedPathBevelSquare.png index 597cd496..8d2919d3 100644 Binary files a/gpu/internal/rendertest/refs/TestStrokedPathBevelSquare.png and b/gpu/internal/rendertest/refs/TestStrokedPathBevelSquare.png differ diff --git a/gpu/internal/rendertest/refs/TestStrokedPathFlatMiter.png b/gpu/internal/rendertest/refs/TestStrokedPathFlatMiter.png index 7ad77e3a..ae6472a7 100644 Binary files a/gpu/internal/rendertest/refs/TestStrokedPathFlatMiter.png and b/gpu/internal/rendertest/refs/TestStrokedPathFlatMiter.png differ diff --git a/gpu/internal/rendertest/refs/TestStrokedPathFlatMiterInf.png b/gpu/internal/rendertest/refs/TestStrokedPathFlatMiterInf.png index 23a13c3b..d315f0f8 100644 Binary files a/gpu/internal/rendertest/refs/TestStrokedPathFlatMiterInf.png and b/gpu/internal/rendertest/refs/TestStrokedPathFlatMiterInf.png differ diff --git a/gpu/internal/rendertest/refs/TestStrokedPathRoundRound.png b/gpu/internal/rendertest/refs/TestStrokedPathRoundRound.png index da3be5f0..8ef5a942 100644 Binary files a/gpu/internal/rendertest/refs/TestStrokedPathRoundRound.png and b/gpu/internal/rendertest/refs/TestStrokedPathRoundRound.png differ diff --git a/gpu/internal/rendertest/refs/TestStrokedPathZeroWidth.png b/gpu/internal/rendertest/refs/TestStrokedPathZeroWidth.png index 1d47f68d..0fc6fe87 100644 Binary files a/gpu/internal/rendertest/refs/TestStrokedPathZeroWidth.png and b/gpu/internal/rendertest/refs/TestStrokedPathZeroWidth.png differ diff --git a/gpu/internal/rendertest/refs/TestTexturedStroke.png b/gpu/internal/rendertest/refs/TestTexturedStroke.png index c7f94431..637c9329 100644 Binary files a/gpu/internal/rendertest/refs/TestTexturedStroke.png and b/gpu/internal/rendertest/refs/TestTexturedStroke.png differ diff --git a/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png b/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png index c7f94431..637c9329 100644 Binary files a/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png and b/gpu/internal/rendertest/refs/TestTexturedStrokeClipped.png differ diff --git a/gpu/internal/rendertest/refs/TestTransformMacro.png b/gpu/internal/rendertest/refs/TestTransformMacro.png index 07570593..a9cce29f 100644 Binary files a/gpu/internal/rendertest/refs/TestTransformMacro.png and b/gpu/internal/rendertest/refs/TestTransformMacro.png differ diff --git a/gpu/internal/rendertest/refs/TestTransformOrder.png b/gpu/internal/rendertest/refs/TestTransformOrder.png index 27c91fb0..720ca3c7 100644 Binary files a/gpu/internal/rendertest/refs/TestTransformOrder.png and b/gpu/internal/rendertest/refs/TestTransformOrder.png differ diff --git a/gpu/internal/rendertest/render_test.go b/gpu/internal/rendertest/render_test.go index 3e027eb3..027dfc61 100644 --- a/gpu/internal/rendertest/render_test.go +++ b/gpu/internal/rendertest/render_test.go @@ -56,7 +56,7 @@ func TestTransformMacro(t *testing.T) { }, func(r result) { r.expect(5, 15, colornames.Red) r.expect(15, 15, colornames.Black) - r.expect(11, 51, colornames.White) + r.expect(11, 51, transparent) }) } @@ -80,7 +80,7 @@ func TestRepeatedPaintsZ(t *testing.T) { }, func(r result) { r.expect(5, 5, colornames.Red) r.expect(11, 15, colornames.Black) - r.expect(11, 51, colornames.White) + r.expect(11, 51, transparent) }) } @@ -99,7 +99,7 @@ func TestNoClipFromPaint(t *testing.T) { r.expect(1, 1, colornames.Black) r.expect(20, 20, colornames.Black) r.expect(49, 49, colornames.Black) - r.expect(51, 51, colornames.White) + r.expect(51, 51, transparent) }) } @@ -197,16 +197,16 @@ func TestBuildOffscreen(t *testing.T) { func(ops *op.Ops) { draw(-100, ops) }, func(r result) { - r.expect(5, 5, colornames.White) - r.expect(20, 20, colornames.White) + r.expect(5, 5, transparent) + r.expect(20, 20, transparent) }), frame( func(ops *op.Ops) { draw(0, ops) }, func(r result) { - r.expect(2, 2, colornames.White) + r.expect(2, 2, transparent) r.expect(20, 20, colornames.Black) - r.expect(38, 38, colornames.White) + r.expect(38, 38, transparent) })) } @@ -216,10 +216,10 @@ func TestNegativeOverlaps(t *testing.T) { clip.Rect(image.Rect(0, 120, 100, 122)).Add(ops) paint.PaintOp{}.Add(ops) }, func(r result) { - r.expect(60, 60, colornames.White) - r.expect(60, 110, colornames.White) - r.expect(60, 120, colornames.White) - r.expect(60, 122, colornames.White) + r.expect(60, 60, transparent) + r.expect(60, 110, transparent) + r.expect(60, 120, transparent) + r.expect(60, 122, transparent) }) } diff --git a/gpu/internal/rendertest/transform_test.go b/gpu/internal/rendertest/transform_test.go index 286ab677..43364b86 100644 --- a/gpu/internal/rendertest/transform_test.go +++ b/gpu/internal/rendertest/transform_test.go @@ -18,10 +18,10 @@ func TestPaintOffset(t *testing.T) { op.Offset(f32.Pt(10, 20)).Add(o) paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 50, 50)).Op()) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(59, 30, colornames.Red) - r.expect(60, 30, colornames.White) - r.expect(10, 70, colornames.White) + r.expect(60, 30, transparent) + r.expect(10, 70, transparent) }) } @@ -33,8 +33,8 @@ func TestPaintRotate(t *testing.T) { }, func(r result) { r.expect(40, 40, colornames.Red) r.expect(50, 19, colornames.Red) - r.expect(59, 19, colornames.White) - r.expect(21, 21, colornames.White) + r.expect(59, 19, transparent) + r.expect(21, 21, transparent) }) } @@ -44,7 +44,7 @@ func TestPaintShear(t *testing.T) { op.Affine(a).Add(o) paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 40, 40)).Op()) }, func(r result) { - r.expect(10, 30, colornames.White) + r.expect(10, 30, transparent) }) } @@ -54,10 +54,10 @@ func TestClipPaintOffset(t *testing.T) { op.Offset(f32.Pt(20, 20)).Add(o) paint.FillShape(o, 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) + r.expect(0, 0, transparent) + r.expect(19, 19, transparent) r.expect(20, 20, colornames.Red) - r.expect(30, 30, colornames.White) + r.expect(30, 30, transparent) }) } @@ -67,11 +67,11 @@ func TestClipOffset(t *testing.T) { clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o) paint.FillShape(o, 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) + r.expect(0, 0, transparent) + r.expect(29, 29, transparent) r.expect(30, 30, colornames.Red) r.expect(49, 49, colornames.Red) - r.expect(50, 50, colornames.White) + r.expect(50, 50, transparent) }) } @@ -82,10 +82,10 @@ func TestClipScale(t *testing.T) { clip.RRect{Rect: f32.Rect(10, 10, 20, 20)}.Add(o) paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 1000, 1000)).Op()) }, func(r result) { - r.expect(19+10, 19+10, colornames.White) + r.expect(19+10, 19+10, transparent) r.expect(20+10, 20+10, colornames.Red) r.expect(39+10, 39+10, colornames.Red) - r.expect(40+10, 40+10, colornames.White) + r.expect(40+10, 40+10, transparent) }) } @@ -95,9 +95,9 @@ func TestClipRotate(t *testing.T) { clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o) paint.FillShape(o, red, clip.Rect(image.Rect(0, 40, 100, 100)).Op()) }, func(r result) { - r.expect(39, 39, colornames.White) + r.expect(39, 39, transparent) r.expect(41, 41, colornames.Red) - r.expect(50, 50, colornames.White) + r.expect(50, 50, transparent) }) } @@ -108,8 +108,8 @@ func TestOffsetTexture(t *testing.T) { scale(50.0/512, 50.0/512).Add(o) paint.PaintOp{}.Add(o) }, func(r result) { - r.expect(14, 20, colornames.White) - r.expect(66, 20, colornames.White) + r.expect(14, 20, transparent) + r.expect(66, 20, transparent) r.expect(16, 64, colornames.Green) r.expect(64, 16, colornames.Green) }) @@ -124,7 +124,7 @@ func TestOffsetScaleTexture(t *testing.T) { paint.PaintOp{}.Add(o) }, func(r result) { r.expect(114, 64, colornames.Blue) - r.expect(116, 64, colornames.White) + r.expect(116, 64, transparent) }) } @@ -152,7 +152,7 @@ func TestRotateClipTexture(t *testing.T) { scale(60.0/512, 60.0/512).Add(o) paint.PaintOp{}.Add(o) }, func(r result) { - r.expect(0, 0, colornames.White) + r.expect(0, 0, transparent) r.expect(37, 39, colornames.Green) r.expect(36, 39, colornames.Green) r.expect(35, 39, colornames.Green) @@ -174,7 +174,7 @@ func TestComplicatedTransform(t *testing.T) { scale(50.0/512, 50.0/512).Add(o) paint.PaintOp{}.Add(o) }, func(r result) { - r.expect(20, 5, colornames.White) + r.expect(20, 5, transparent) }) } @@ -192,9 +192,9 @@ func TestTransformOrder(t *testing.T) { paint.FillShape(o, 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) + r.expect(64-41, 64, transparent) r.expect(64-39, 64, colornames.Red) r.expect(64+39, 64, colornames.Red) - r.expect(64+41, 64, colornames.White) + r.expect(64+41, 64, transparent) }) } diff --git a/gpu/internal/rendertest/util_test.go b/gpu/internal/rendertest/util_test.go index 812963f0..6c5b9731 100644 --- a/gpu/internal/rendertest/util_test.go +++ b/gpu/internal/rendertest/util_test.go @@ -31,12 +31,13 @@ var ( ) var ( - red = f32color.RGBAToNRGBA(colornames.Red) - green = f32color.RGBAToNRGBA(colornames.Green) - blue = f32color.RGBAToNRGBA(colornames.Blue) - magenta = f32color.RGBAToNRGBA(colornames.Magenta) - black = f32color.RGBAToNRGBA(colornames.Black) - white = f32color.RGBAToNRGBA(colornames.White) + red = f32color.RGBAToNRGBA(colornames.Red) + green = f32color.RGBAToNRGBA(colornames.Green) + blue = f32color.RGBAToNRGBA(colornames.Blue) + magenta = f32color.RGBAToNRGBA(colornames.Magenta) + black = f32color.RGBAToNRGBA(colornames.Black) + white = f32color.RGBAToNRGBA(colornames.White) + transparent = color.RGBA{} ) func init() { @@ -163,21 +164,32 @@ func verifyRef(t *testing.T, img *image.RGBA, frame int) (ok bool) { t.Error("could not decode ref:", err) return } - ref, ok := r.(*image.RGBA) - if !ok { - t.Errorf("image is a %T, expected *image.RGBA", r) - return - } - if len(ref.Pix) != len(img.Pix) { - t.Error("not equal to ref (len)") + if img.Bounds() != r.Bounds() { + t.Errorf("reference image is %v, expected %v", r.Bounds(), img.Bounds()) return false } + var ref *image.RGBA + switch r := r.(type) { + case *image.RGBA: + ref = r + case *image.NRGBA: + ref = image.NewRGBA(r.Bounds()) + bnd := r.Bounds() + for x := bnd.Min.X; x < bnd.Max.X; x++ { + for y := bnd.Min.Y; y < bnd.Max.Y; y++ { + ref.SetRGBA(x, y, f32color.NRGBAToRGBA(r.NRGBAAt(x, y))) + } + } + default: + t.Fatalf("reference image is a %T, expected *image.NRGBA or *image.RGBA", r) + } bnd := img.Bounds() for x := bnd.Min.X; x < bnd.Max.X; x++ { for y := bnd.Min.Y; y < bnd.Max.Y; y++ { - c1, c2 := ref.RGBAAt(x, y), img.RGBAAt(x, y) - if !colorsClose(c1, c2) { - t.Error("not equal to ref at", x, y, " ", c1, c2) + exp := ref.RGBAAt(x, y) + got := img.RGBAAt(x, y) + if !colorsClose(exp, got) { + t.Error("not equal to ref at", x, y, " ", got, exp) return false } } @@ -230,6 +242,7 @@ func yiqEqApprox(c1, c2 color.RGBA, d2 float64) bool { } func (r result) expect(x, y int, col color.RGBA) { + r.t.Helper() if r.img == nil { return } @@ -244,9 +257,17 @@ type result struct { img *image.RGBA } -func saveImage(file string, img image.Image) error { +func saveImage(file string, img *image.RGBA) error { + // Only NRGBA images are losslessly encoded by png.Encode. + nrgba := image.NewNRGBA(img.Bounds()) + bnd := img.Bounds() + for x := bnd.Min.X; x < bnd.Max.X; x++ { + for y := bnd.Min.Y; y < bnd.Max.Y; y++ { + nrgba.SetNRGBA(x, y, f32color.RGBAToNRGBA(img.RGBAAt(x, y))) + } + } var buf bytes.Buffer - if err := png.Encode(&buf, img); err != nil { + if err := png.Encode(&buf, nrgba); err != nil { return err } return ioutil.WriteFile(file, buf.Bytes(), 0666)