|
3 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this
|
4 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
5 | 5 |
|
6 |
| -flat varying vec4 vClipRect; |
7 |
| -flat varying vec4 vClipRadius; |
8 |
| -flat varying vec4 vClipMaskUvRect; |
9 |
| -flat varying vec4 vClipMaskLocalRect; |
10 |
| - |
11 | 6 | #ifdef WR_VERTEX_SHADER
|
12 |
| -void write_clip(ClipData clip) { |
13 |
| - vClipRect = vec4(clip.rect.rect.xy, clip.rect.rect.xy + clip.rect.rect.zw); |
14 |
| - vClipRadius = vec4(clip.top_left.outer_inner_radius.x, |
15 |
| - clip.top_right.outer_inner_radius.x, |
16 |
| - clip.bottom_right.outer_inner_radius.x, |
17 |
| - clip.bottom_left.outer_inner_radius.x); |
18 |
| - //TODO: interpolate the final mask UV |
19 |
| - vec2 texture_size = textureSize(sMask, 0); |
20 |
| - vClipMaskUvRect = clip.mask_data.uv_rect / texture_size.xyxy; |
21 |
| - vClipMaskLocalRect = clip.mask_data.local_rect; //TODO: transform |
22 |
| -} |
23 |
| -#endif |
24 | 7 |
|
25 |
| -#ifdef WR_FRAGMENT_SHADER |
26 |
| -float do_clip(vec2 pos) { |
27 |
| - vec2 ref_tl = vClipRect.xy + vec2( vClipRadius.x, vClipRadius.x); |
28 |
| - vec2 ref_tr = vClipRect.zy + vec2(-vClipRadius.y, vClipRadius.y); |
29 |
| - vec2 ref_br = vClipRect.zw + vec2(-vClipRadius.z, -vClipRadius.z); |
30 |
| - vec2 ref_bl = vClipRect.xw + vec2( vClipRadius.w, -vClipRadius.w); |
| 8 | +struct CacheClipInstance { |
| 9 | + int render_task_index; |
| 10 | + int layer_index; |
| 11 | + int data_index; |
| 12 | +}; |
31 | 13 |
|
32 |
| - float d_tl = distance(pos, ref_tl); |
33 |
| - float d_tr = distance(pos, ref_tr); |
34 |
| - float d_br = distance(pos, ref_br); |
35 |
| - float d_bl = distance(pos, ref_bl); |
| 14 | +CacheClipInstance fetch_clip_item(int index) { |
| 15 | + CacheClipInstance cci; |
36 | 16 |
|
37 |
| - float pixels_per_fragment = length(fwidth(pos.xy)); |
38 |
| - float nudge = 0.5 * pixels_per_fragment; |
39 |
| - vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge; |
| 17 | + int offset = index * 1; |
40 | 18 |
|
41 |
| - bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y, |
42 |
| - pos.x > ref_tr.x && pos.y < ref_tr.y, |
43 |
| - pos.x > ref_br.x && pos.y > ref_br.y, |
44 |
| - pos.x < ref_bl.x && pos.y > ref_bl.y); |
| 19 | + ivec4 data0 = int_data[offset + 0]; |
45 | 20 |
|
46 |
| - float distance_from_border = dot(vec4(is_out), |
47 |
| - max(vec4(0.0, 0.0, 0.0, 0.0), distances)); |
| 21 | + cci.render_task_index = data0.x; |
| 22 | + cci.layer_index = data0.y; |
| 23 | + cci.data_index = data0.z; |
| 24 | + |
| 25 | + return cci; |
| 26 | +} |
48 | 27 |
|
49 |
| - // Move the distance back into pixels. |
50 |
| - distance_from_border /= pixels_per_fragment; |
51 |
| - // Apply a more gradual fade out to transparent. |
52 |
| - //distance_from_border -= 0.5; |
| 28 | +// The transformed vertex function that always covers the whole whole clip area, |
| 29 | +// which is the intersection of all clip instances of a given primitive |
| 30 | +TransformVertexInfo write_clip_tile_vertex(vec4 local_clip_rect, |
| 31 | + Layer layer, |
| 32 | + ClipArea area) { |
| 33 | + vec2 lp0_base = local_clip_rect.xy; |
| 34 | + vec2 lp1_base = local_clip_rect.xy + local_clip_rect.zw; |
53 | 35 |
|
54 |
| - float border_alpha = 1.0 - smoothstep(0.0, 1.0, distance_from_border); |
| 36 | + vec2 lp0 = clamp_rect(lp0_base, layer.local_clip_rect); |
| 37 | + vec2 lp1 = clamp_rect(lp1_base, layer.local_clip_rect); |
| 38 | + vec4 clipped_local_rect = vec4(lp0, lp1 - lp0); |
55 | 39 |
|
56 |
| - bool repeat_mask = false; //TODO |
57 |
| - vec2 vMaskUv = (pos - vClipMaskLocalRect.xy) / vClipMaskLocalRect.zw; |
58 |
| - vec2 clamped_mask_uv = repeat_mask ? fract(vMaskUv) : |
59 |
| - clamp(vMaskUv, vec2(0.0, 0.0), vec2(1.0, 1.0)); |
60 |
| - vec2 source_uv = clamped_mask_uv * vClipMaskUvRect.zw + vClipMaskUvRect.xy; |
61 |
| - float mask_alpha = texture(sMask, source_uv).r; //careful: texture has type A8 |
| 40 | + vec2 final_pos = mix(area.task_bounds.xy, area.task_bounds.zw, aPosition.xy); |
62 | 41 |
|
63 |
| - return border_alpha * mask_alpha; |
| 42 | + // compute the point position in side the layer, in CSS space |
| 43 | + vec2 clamped_pos = final_pos + area.screen_origin_target_index.xy - area.task_bounds.xy; |
| 44 | + vec4 layer_pos = get_layer_pos(clamped_pos / uDevicePixelRatio, layer); |
| 45 | + |
| 46 | + gl_Position = uTransform * vec4(final_pos, 0.0, 1); |
| 47 | + |
| 48 | + return TransformVertexInfo(layer_pos.xyw, clamped_pos, clipped_local_rect); |
64 | 49 | }
|
65 |
| -#endif |
| 50 | + |
| 51 | +#endif //WR_VERTEX_SHADER |
0 commit comments