test(vulkan): cover clipped, clamped, square and rotated hint draws
1 file · +53 -0
M internal/adapters/vulkan/position_hint_test.go +53 -0
| @@ -107,3 +107,56 @@ func TestPositionHintRoundedOrient(t *testing.T) { | |||
| 107 | 107 | require.Equal(t, roundRect(image.Rect(int(d.pc.rect[0]), int(d.pc.rect[1]), int(d.pc.rect[2]), int(d.pc.rect[3]))), d.round) | |
| 108 | 108 | } | |
| 109 | 109 | } | |
| 110 | + | ||
| 111 | + | func TestHintRoundDraws(t *testing.T) { | |
| 112 | + | bounds := image.Rect(0, 0, 100, 100) | |
| 113 | + | for _, tc := range []struct { | |
| 114 | + | name string | |
| 115 | + | rect image.Rectangle | |
| 116 | + | radius int | |
| 117 | + | wantDraws int | |
| 118 | + | wantRadius float32 | |
| 119 | + | }{ | |
| 120 | + | {"inside", image.Rect(10, 10, 50, 40), 6, 1, 6}, | |
| 121 | + | {"clipped fully off output", image.Rect(200, 200, 240, 230), 6, 0, 0}, | |
| 122 | + | {"clipped by bounds", image.Rect(90, 90, 130, 130), 6, 1, 6}, | |
| 123 | + | {"tiny pill clamps the radius", image.Rect(10, 10, 16, 14), 100, 1, 2}, | |
| 124 | + | {"zero radius is a plain fill", image.Rect(10, 10, 50, 40), 0, 1, 0}, | |
| 125 | + | {"negative radius is a plain fill", image.Rect(10, 10, 50, 40), -3, 1, 0}, | |
| 126 | + | } { | |
| 127 | + | t.Run(tc.name, func(t *testing.T) { | |
| 128 | + | w := sceneWalk{r: &Renderer{width: 100, height: 100}, alpha: 1, bounds: bounds} | |
| 129 | + | w.hintRound(tc.rect, tc.radius, [3]uint8{1, 2, 3}) | |
| 130 | + | require.Len(t, w.draws, tc.wantDraws) | |
| 131 | + | for _, d := range w.draws { | |
| 132 | + | if tc.wantRadius == 0 { | |
| 133 | + | require.Zero(t, d.pc.misc[1]&flagRounded) | |
| 134 | + | continue | |
| 135 | + | } | |
| 136 | + | require.NotZero(t, d.pc.misc[1]&flagRounded) | |
| 137 | + | require.Equal(t, roundRect(tc.rect), d.round, "the clip is the requested rect") | |
| 138 | + | require.Equal(t, tc.wantRadius, math.Float32frombits(d.radii[0])) | |
| 139 | + | } | |
| 140 | + | }) | |
| 141 | + | } | |
| 142 | + | } | |
| 143 | + | ||
| 144 | + | func TestPositionHintRoundedRotatedOrient(t *testing.T) { | |
| 145 | + | for transform := ports.BufferTransform(1); transform < 8; transform++ { | |
| 146 | + | r := &Renderer{width: 640, height: 480} | |
| 147 | + | sw, sh := r.sceneSize(transform) | |
| 148 | + | s := ports.Scene{OutputWidth: sw, OutputHeight: sh, Scale: 1, Transform: transform, PositionHint: hintGrid(2, 2)} | |
| 149 | + | ds := r.draws(s, nil, newDamage(&target{}, s, image.Rect(0, 0, sw, sh))) | |
| 150 | + | require.Len(t, ds, 1+4) | |
| 151 | + | sceneRects := make([]image.Rectangle, len(ds)) | |
| 152 | + | for i, d := range ds { | |
| 153 | + | sceneRects[i] = image.Rect(int(d.pc.rect[0]), int(d.pc.rect[1]), int(d.pc.rect[2]), int(d.pc.rect[3])) | |
| 154 | + | } | |
| 155 | + | r.orient(ds, transform) | |
| 156 | + | for i, d := range ds { | |
| 157 | + | want := transform.RectToBuffer(sceneRects[i], sw, sh) | |
| 158 | + | require.Equal(t, roundRect(want), d.round, "transform %d draw %d", transform, i) | |
| 159 | + | require.NotZero(t, d.pc.misc[1]&flagRounded) | |
| 160 | + | } | |
| 161 | + | } | |
| 162 | + | } | |
| @@ -107,3 +107,56 @@ func TestPositionHintRoundedOrient(t *testing.T) { | |||||
| 107 | require.Equal(t, roundRect(image.Rect(int(d.pc.rect[0]), int(d.pc.rect[1]), int(d.pc.rect[2]), int(d.pc.rect[3]))), d.round) | 107 | require.Equal(t, roundRect(image.Rect(int(d.pc.rect[0]), int(d.pc.rect[1]), int(d.pc.rect[2]), int(d.pc.rect[3]))), d.round) | ||
| 108 | } | 108 | } | ||
| 109 | } | 109 | } | ||
| 110 | + | ||||
| 111 | + | func TestHintRoundDraws(t *testing.T) { | |||
| 112 | + | bounds := image.Rect(0, 0, 100, 100) | |||
| 113 | + | for _, tc := range []struct { | |||
| 114 | + | name string | |||
| 115 | + | rect image.Rectangle | |||
| 116 | + | radius int | |||
| 117 | + | wantDraws int | |||
| 118 | + | wantRadius float32 | |||
| 119 | + | }{ | |||
| 120 | + | {"inside", image.Rect(10, 10, 50, 40), 6, 1, 6}, | |||
| 121 | + | {"clipped fully off output", image.Rect(200, 200, 240, 230), 6, 0, 0}, | |||
| 122 | + | {"clipped by bounds", image.Rect(90, 90, 130, 130), 6, 1, 6}, | |||
| 123 | + | {"tiny pill clamps the radius", image.Rect(10, 10, 16, 14), 100, 1, 2}, | |||
| 124 | + | {"zero radius is a plain fill", image.Rect(10, 10, 50, 40), 0, 1, 0}, | |||
| 125 | + | {"negative radius is a plain fill", image.Rect(10, 10, 50, 40), -3, 1, 0}, | |||
| 126 | + | } { | |||
| 127 | + | t.Run(tc.name, func(t *testing.T) { | |||
| 128 | + | w := sceneWalk{r: &Renderer{width: 100, height: 100}, alpha: 1, bounds: bounds} | |||
| 129 | + | w.hintRound(tc.rect, tc.radius, [3]uint8{1, 2, 3}) | |||
| 130 | + | require.Len(t, w.draws, tc.wantDraws) | |||
| 131 | + | for _, d := range w.draws { | |||
| 132 | + | if tc.wantRadius == 0 { | |||
| 133 | + | require.Zero(t, d.pc.misc[1]&flagRounded) | |||
| 134 | + | continue | |||
| 135 | + | } | |||
| 136 | + | require.NotZero(t, d.pc.misc[1]&flagRounded) | |||
| 137 | + | require.Equal(t, roundRect(tc.rect), d.round, "the clip is the requested rect") | |||
| 138 | + | require.Equal(t, tc.wantRadius, math.Float32frombits(d.radii[0])) | |||
| 139 | + | } | |||
| 140 | + | }) | |||
| 141 | + | } | |||
| 142 | + | } | |||
| 143 | + | ||||
| 144 | + | func TestPositionHintRoundedRotatedOrient(t *testing.T) { | |||
| 145 | + | for transform := ports.BufferTransform(1); transform < 8; transform++ { | |||
| 146 | + | r := &Renderer{width: 640, height: 480} | |||
| 147 | + | sw, sh := r.sceneSize(transform) | |||
| 148 | + | s := ports.Scene{OutputWidth: sw, OutputHeight: sh, Scale: 1, Transform: transform, PositionHint: hintGrid(2, 2)} | |||
| 149 | + | ds := r.draws(s, nil, newDamage(&target{}, s, image.Rect(0, 0, sw, sh))) | |||
| 150 | + | require.Len(t, ds, 1+4) | |||
| 151 | + | sceneRects := make([]image.Rectangle, len(ds)) | |||
| 152 | + | for i, d := range ds { | |||
| 153 | + | sceneRects[i] = image.Rect(int(d.pc.rect[0]), int(d.pc.rect[1]), int(d.pc.rect[2]), int(d.pc.rect[3])) | |||
| 154 | + | } | |||
| 155 | + | r.orient(ds, transform) | |||
| 156 | + | for i, d := range ds { | |||
| 157 | + | want := transform.RectToBuffer(sceneRects[i], sw, sh) | |||
| 158 | + | require.Equal(t, roundRect(want), d.round, "transform %d draw %d", transform, i) | |||
| 159 | + | require.NotZero(t, d.pc.misc[1]&flagRounded) | |||
| 160 | + | } | |||
| 161 | + | } | |||
| 162 | + | } | |||