Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / wr / webrender / res / ps_quad_textured.glsl
blob2382623cdb9a1139f948a5c323aab66d79c123a3
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 /// This shader renders solid colors or simple images in a color or alpha target.
7 #include ps_quad
9 #ifndef SWGL_ANTIALIAS
10 varying highp vec2 vLocalPos;
11 #endif
13 #ifdef WR_VERTEX_SHADER
14 void main(void) {
15     PrimitiveInfo info = ps_quad_main();
17 #ifndef SWGL_ANTIALIAS
18     RectWithEndpoint xf_bounds = RectWithEndpoint(
19         max(info.local_prim_rect.p0, info.local_clip_rect.p0),
20         min(info.local_prim_rect.p1, info.local_clip_rect.p1)
21     );
22     vTransformBounds = vec4(xf_bounds.p0, xf_bounds.p1);
24     vLocalPos = info.local_pos;
26     if (info.edge_flags == 0) {
27         v_flags.x = 0;
28     } else {
29         v_flags.x = 1;
30     }
31 #endif
33     if ((info.quad_flags & QF_SAMPLE_AS_MASK) != 0) {
34         v_flags.z = 1;
35     } else {
36         v_flags.z = 0;
37     }
39 #endif
41 #ifdef WR_FRAGMENT_SHADER
42 void main(void) {
43     vec4 color = v_color;
45 #ifndef SWGL_ANTIALIAS
46     if (v_flags.x != 0) {
47         float alpha = init_transform_fs(vLocalPos);
48         color *= alpha;
49     }
50 #endif
52     if (v_flags.y != 0) {
53         vec2 uv = clamp(v_uv, v_uv_sample_bounds.xy, v_uv_sample_bounds.zw);
54         vec4 texel = TEX_SAMPLE(sColor0, uv);
55         if (v_flags.z != 0) {
56             texel = texel.rrrr;
57         }
58         color *= texel;
59     }
61     oFragColor = color;
64 #if defined(SWGL_DRAW_SPAN)
65 void swgl_drawSpanRGBA8() {
66     if (v_flags.y != 0) {
67         if (v_flags.z != 0) {
68             // Fall back to fragment shader as we don't specialize for mask yet. Perhaps
69             // we can use an existing swgl commit or add a new one though?
70         } else {
71             swgl_commitTextureLinearColorRGBA8(sColor0, v_uv, v_uv_sample_bounds, v_color);
72         }
73     } else {
74         swgl_commitSolidRGBA8(v_color);
75     }
77 #endif
79 #endif