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/. */
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;
18 #ifdef WR_VERTEX_SHADER
19 void write_gradient_vertex(
21 RectWithEndpoint local_rect,
22 RectWithEndpoint segment_rect,
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);
34 v_pos = vi.local_pos - local_rect.p0;
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;
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) {
67 if (local_pos.y >= v_tile_repeat.y) {
72 // Apply potential horizontal and vertical repetitions.
77 #endif //WR_FRAGMENT_SHADER