Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / wr / webrender / res / gradient_shared.glsl
bloba3cc042ca6ef5d408d4b7da02d03e00a33e5bd12
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 #include gradient
7 // Size of the gradient pattern's rectangle, used to compute horizontal and vertical
8 // repetitions. Not to be confused with another kind of repetition of the pattern
9 // which happens along the gradient stops.
10 flat varying highp vec2 v_repeated_size;
12 varying highp vec2 v_pos;
14 #ifdef WR_FEATURE_ALPHA_PASS
15 flat varying highp vec2 v_tile_repeat;
16 #endif
18 #ifdef WR_VERTEX_SHADER
19 void write_gradient_vertex(
20     VertexInfo vi,
21     RectWithEndpoint local_rect,
22     RectWithEndpoint segment_rect,
23     ivec4 prim_user_data,
24     int brush_flags,
25     vec4 texel_rect,
26     int extend_mode,
27     vec2 stretch_size
28 ) {
29     if ((brush_flags & BRUSH_FLAG_SEGMENT_RELATIVE) != 0) {
30         v_pos = (vi.local_pos - segment_rect.p0) / rect_size(segment_rect);
31         v_pos = v_pos * (texel_rect.zw - texel_rect.xy) + texel_rect.xy;
32         v_pos = v_pos * rect_size(local_rect);
33     } else {
34         v_pos = vi.local_pos - local_rect.p0;
35     }
37     vec2 tile_repeat = rect_size(local_rect) / stretch_size;
38     v_repeated_size = stretch_size;
40     // Normalize UV to 0..1 scale.
41     v_pos /= v_repeated_size;
43     v_gradient_address.x = prim_user_data.x;
45     // Whether to repeat the gradient along the line instead of clamping.
46     v_gradient_repeat.x = float(extend_mode == EXTEND_MODE_REPEAT);
48 #ifdef WR_FEATURE_ALPHA_PASS
49     v_tile_repeat = tile_repeat;
50 #endif
52 #endif //WR_VERTEX_SHADER
54 #ifdef WR_FRAGMENT_SHADER
55 vec2 compute_repeated_pos() {
56 #if defined(WR_FEATURE_ALPHA_PASS) && !defined(SWGL_ANTIALIAS)
57     // Handle top and left inflated edges (see brush_image).
58     vec2 local_pos = max(v_pos, vec2(0.0));
60     // Apply potential horizontal and vertical repetitions.
61     vec2 pos = fract(local_pos);
63     // Handle bottom and right inflated edges (see brush_image).
64     if (local_pos.x >= v_tile_repeat.x) {
65         pos.x = 1.0;
66     }
67     if (local_pos.y >= v_tile_repeat.y) {
68         pos.y = 1.0;
69     }
70     return pos;
71 #else
72     // Apply potential horizontal and vertical repetitions.
73     return fract(v_pos);
74 #endif
77 #endif //WR_FRAGMENT_SHADER