Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / wr / webrender / res / ps_split_composite.glsl
blobc07eca137127b00a040e1adcf0a1750c7fd9f110
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #define WR_FEATURE_TEXTURE_2D
7 #include shared,prim_shared
9 // interpolated UV coordinates to sample.
10 varying highp vec2 vUv;
12 // Flag to allow perspective interpolation of UV.
13 // Packed in to a vector to work around bug 1630356.
14 flat varying mediump vec2 vPerspective;
16 flat varying highp vec4 vUvSampleBounds;
18 #ifdef WR_VERTEX_SHADER
19 struct SplitGeometry {
20     vec2 local[4];
23 SplitGeometry fetch_split_geometry(int address) {
24     ivec2 uv = get_gpu_cache_uv(address);
26     vec4 data0 = TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0));
27     vec4 data1 = TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0));
29     SplitGeometry geo;
30     geo.local = vec2[4](
31         data0.xy,
32         data0.zw,
33         data1.xy,
34         data1.zw
35     );
37     return geo;
40 vec2 bilerp(vec2 a, vec2 b, vec2 c, vec2 d, float s, float t) {
41     vec2 x = mix(a, b, t);
42     vec2 y = mix(c, d, t);
43     return mix(x, y, s);
46 struct SplitCompositeInstance {
47     int prim_header_index;
48     int polygons_address;
49     float z;
50     int render_task_index;
53 SplitCompositeInstance fetch_composite_instance() {
54     SplitCompositeInstance ci;
56     ci.prim_header_index = aData.x;
57     ci.polygons_address = aData.y;
58     ci.z = float(aData.z);
59     ci.render_task_index = aData.w;
61     return ci;
64 void main(void) {
65     SplitCompositeInstance ci = fetch_composite_instance();
66     SplitGeometry geometry = fetch_split_geometry(ci.polygons_address);
67     PrimitiveHeader ph = fetch_prim_header(ci.prim_header_index);
68     PictureTask dest_task = fetch_picture_task(ci.render_task_index);
69     Transform transform = fetch_transform(ph.transform_id);
70     ImageSource res = fetch_image_source(ph.user_data.x);
71     ClipArea clip_area = fetch_clip_area(ph.user_data.w);
73     vec2 dest_origin = dest_task.task_rect.p0 -
74                        dest_task.content_origin;
76     vec2 local_pos = bilerp(geometry.local[0], geometry.local[1],
77                             geometry.local[3], geometry.local[2],
78                             aPosition.y, aPosition.x);
79     vec4 world_pos = transform.m * vec4(local_pos, 0.0, 1.0);
81     vec4 final_pos = vec4(
82         dest_origin * world_pos.w + world_pos.xy * dest_task.device_pixel_scale,
83         world_pos.w * ci.z,
84         world_pos.w
85     );
87     write_clip(
88         world_pos,
89         clip_area,
90         dest_task
91     );
93     gl_Position = uTransform * final_pos;
95     vec2 texture_size = vec2(TEX_SIZE(sColor0));
96     vec2 uv0 = res.uv_rect.p0;
97     vec2 uv1 = res.uv_rect.p1;
99     vec2 min_uv = min(uv0, uv1);
100     vec2 max_uv = max(uv0, uv1);
102     vUvSampleBounds = vec4(
103         min_uv + vec2(0.5),
104         max_uv - vec2(0.5)
105     ) / texture_size.xyxy;
107     vec2 f = (local_pos - ph.local_rect.p0) / rect_size(ph.local_rect);
108     f = get_image_quad_uv(ph.user_data.x, f);
109     vec2 uv = mix(uv0, uv1, f);
110     float perspective_interpolate = float(ph.user_data.y);
112     vUv = uv / texture_size * mix(gl_Position.w, 1.0, perspective_interpolate);
113     vPerspective.x = perspective_interpolate;
115 #endif
117 #ifdef WR_FRAGMENT_SHADER
118 void main(void) {
119     float alpha = do_clip();
120     float perspective_divisor = mix(gl_FragCoord.w, 1.0, vPerspective.x);
121     vec2 uv = clamp(vUv * perspective_divisor, vUvSampleBounds.xy, vUvSampleBounds.zw);
122     write_output(alpha * texture(sColor0, uv));
125 #ifdef SWGL_DRAW_SPAN
126 void swgl_drawSpanRGBA8() {
127     float perspective_divisor = mix(swgl_forceScalar(gl_FragCoord.w), 1.0, vPerspective.x);
128     vec2 uv = vUv * perspective_divisor;
130     swgl_commitTextureRGBA8(sColor0, uv, vUvSampleBounds);
132 #endif
134 #endif