Bug 1708540 - Handle and test various NaN situations with gradients. r=gfx-reviewers,bradwerth

Differential Revision: https://phabricator.services.mozilla.com/D114366
This commit is contained in:
Nicolas Silva 2021-05-05 21:28:34 +00:00
Родитель fc544d4e99
Коммит 141d788226
5 изменённых файлов: 295 добавлений и 1 удалений

Просмотреть файл

@ -132,7 +132,9 @@ impl GradientBuilder {
let first = *stops.first().unwrap();
let last = *stops.last().unwrap();
assert!(first.offset <= last.offset);
// Express the assertion so that if one of the offsets is NaN, we don't panic
// and instead take the branch that handles degenerate gradients.
assert!(!(first.offset > last.offset));
let stops_delta = last.offset - first.offset;

Просмотреть файл

@ -0,0 +1,41 @@
---
root:
items:
- type: conic-gradient
bounds: 50 50 200 NaN
center: 100 100
angle: 0.0
stops: [0.0, red, 0.25, green, 0.5, blue, 0.75, black]
- type: conic-gradient
bounds: 50 50 200 200
center: NaN 100
angle: 0.0
stops: [0.0, red, 0.25, green, 0.5, blue, 0.75, black]
- type: conic-gradient
bounds: 50 50 200 200
center: 100 100
angle: NaN
stops: [0.0, red, 0.25, green, 0.5, blue, 0.75, black]
- type: conic-gradient
bounds: 50 50 200 200
center: 100 100
angle: 0.0
stops: [0.0, red, NaN, green, 0.5, blue, 0.75, black]
- type: conic-gradient
bounds: 50 50 200 200
tile-size: NaN 200
center: 100 100
angle: 0.0
stops: [0.0, red, 0.25, green, 0.5, blue, 0.75, black]
- type: conic-gradient
bounds: 50 50 200 200
clip-rect: NaN 0 100 100
center: 100 100
angle: 0.0
stops: [0.0, red, 0.25, green, 0.5, blue, 0.75, black]
- type: conic-gradient
bounds: NaN NaN NaN NaN
clip-rect: NaN NaN NaN NaN
center: NaN NaN
angle: NaN
stops: [NaN, red, NaN, green, NaN, blue, NaN, black]

Просмотреть файл

@ -0,0 +1,213 @@
---
root:
items:
# Small-ish gradients
- type: gradient
bounds: 50 50 NaN 200
start: 0 100
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 200 200
start: 0 100
end: NaN 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 200 200
start: 0 NaN
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 200 200
start: 0 100
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
NaN, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 200 200
start: 0 100
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, NaN, black]
- type: gradient
bounds: 50 50 200 200
clip-rect: 50 50 150 NaN
start: 0 100
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 200 200
tile-size: NaN 200
start: 0 100
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
# Large-ish gradients
- type: gradient
bounds: 50 50 NaN 500
start: 0 100
end: 500 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 500 500
start: 0 100
end: NaN 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 500 500
start: 0 NaN
end: 500 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 500 500
start: 0 100
end: 500 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
NaN, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 500 500
start: 0 100
end: 500 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, NaN, black]
- type: gradient
bounds: 50 50 500 500
clip-rect: 50 50 150 NaN
start: 0 100
end: 500 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 500 500
tile-size: NaN 500
start: 0 100
end: 500 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
# Very large gradients
- type: gradient
bounds: 50 50 10000 10000
start: 0 100
end: NaN 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 10000 10000
start: 0 NaN
end: 10000 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.5, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 10000 10000
start: 0 100
end: 10000 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
NaN, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 10000 10000
start: 0 100
end: 10000 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, NaN, black]
- type: gradient
bounds: 50 50 10000 10000
clip-rect: 50 50 150 NaN
start: 0 100
end: 10000 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 10000 10000
tile-size: NaN 10000
start: 0 100
end: 10000 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
# Not axis-aligned
- type: gradient
bounds: 50 50 200 200
tile-size: NaN 200
start: 0 0
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: NaN 50 200 200
tile-size: 100 100
start: 0 0
end: 200 100
stops: [0.0, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, 0.75, blue,
0.75, black, 1.0, black]
- type: gradient
bounds: 50 50 200 200
start: 0.0 0
end: 200 100
stops: [NaN, red, 0.25, red,
0.25, green, 0.5, green,
0.0, blue, NaN, blue,
0.75, black, 1.0, black]
# Post-apocalyptic gradient
- type: gradient
bounds: NaN NaN NaN NaN
tile-size: NaN NaN
start: NaN NaN
end: NaN NaN
stops: [NaN, red, NaN, red,
NaN, green, NaN, green,
NaN, blue, NaN, blue,
NaN, black, NaN, black]

Просмотреть файл

@ -0,0 +1,35 @@
---
root:
items:
- type: radial-gradient
bounds: 50 50 NaN 300
center: 150 150
radius: 200 200
stops: [0, red, 1, blue]
- type: radial-gradient
bounds: 50 50 300 300
center: 150 NaN
radius: 200 200
stops: [0, red, 1, blue]
- type: radial-gradient
bounds: 50 50 300 300
center: 150 150
radius: NaN 200
stops: [0, red, 1, blue]
- type: radial-gradient
bounds: 50 50 300 300
center: 150 150
radius: 200 200
stops: [0, red, NaN, blue]
- type: radial-gradient
bounds: 50 50 300 300
tile-size: 50 NaN
center: 150 150
radius: 200 200
stops: [0, red, 1, blue]
- type: radial-gradient
bounds: 50 50 300 300
clip-rect: 50 10 NaN 300
center: 150 150
radius: 200 200
stops: [0, red, 1, blue]

Просмотреть файл

@ -121,3 +121,6 @@ fuzzy(1,7000) == radial-large.yaml radial-large-ref.png
# crash tests
== linear-far-endpoints.yaml linear-far-endpoints.yaml
== linear-nan.yaml linear-nan.yaml
== radial-nan.yaml radial-nan.yaml
== conic-nan.yaml conic-nan.yaml