Skip to content

Commit 9ba91c3

Browse files
author
bors-servo
authored
Auto merge of #1771 - glennw:angle-grad-radius, r=kvark
Add clip mask sampling to the angle gradient shader. Fixes #1770. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1771) <!-- Reviewable:end -->
2 parents 8670275 + c18336b commit 9ba91c3

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

webrender/res/ps_angle_gradient.glsl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void main(void) {
4343

4444
// Whether to repeat the gradient instead of clamping.
4545
vGradientRepeat = float(int(gradient.extend_mode.x) != EXTEND_MODE_CLAMP);
46+
47+
write_clip(vi.screen_pos, prim.clip_area);
4648
}
4749
#endif
4850

@@ -57,8 +59,21 @@ void main(void) {
5759

5860
float offset = dot(pos - vStartPoint, vScaledDir);
5961

60-
oFragColor = sample_gradient(vGradientAddress,
62+
vec4 color = sample_gradient(vGradientAddress,
6163
offset,
6264
vGradientRepeat);
65+
66+
// Un-premultiply the color from sampling the gradient.
67+
if (color.a > 0.0) {
68+
color.rgb /= color.a;
69+
70+
// Apply the clip mask
71+
color.a = min(color.a, do_clip());
72+
73+
// Pre-multiply the result.
74+
color.rgb *= color.a;
75+
}
76+
77+
oFragColor = color;
6378
}
6479
#endif

wrench/reftests/gradient/reftest.list

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ fuzzy(1,17) == tiling-radial-4.yaml tiling-radial-4-ref.yaml
5858
== radial-zero-size-3.yaml radial-zero-size-ref.yaml
5959

6060
== linear-aligned-border-radius.yaml linear-aligned-border-radius.png
61+
== repeat-border-radius.yaml repeat-border-radius.png
62+
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
root:
3+
items:
4+
- type: clip
5+
bounds: [20, 20, 100, 100]
6+
complex:
7+
- rect: [20, 20, 100, 100]
8+
radius: 32
9+
items:
10+
- type: gradient
11+
bounds: 20 20 100 100
12+
start: 50 0
13+
end: 50 100
14+
stops: [0.0, red, 1.0, yellow]
15+
repeat: true
16+
17+
- type: rect
18+
bounds: [130, 10, 120, 120]
19+
color: blue
20+
21+
- type: clip
22+
bounds: [140, 20, 100, 100]
23+
complex:
24+
- rect: [140, 20, 100, 100]
25+
radius: 32
26+
items:
27+
- type: gradient
28+
bounds: 140 20 100 100
29+
start: 50 0
30+
end: 50 100
31+
stops: [0.2, red, 1.0, yellow]
32+
33+
- type: rect
34+
bounds: [260, 10, 120, 120]
35+
color: black
36+
37+
- type: clip
38+
bounds: [270, 20, 100, 100]
39+
complex:
40+
- rect: [270, 20, 100, 100]
41+
radius: 32
42+
items:
43+
- type: gradient
44+
bounds: 270 20 100 100
45+
start: 50 0
46+
end: 51 100
47+
stops: [0.0, red, 1.0, yellow]

0 commit comments

Comments
 (0)