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 VECS_PER_SPECIFIC_BRUSH 2
7 #include shared,prim_shared,brush,gpu_buffer,gradient_shared
9 // Start offset. Packed in to vector to work around bug 1630356.
10 flat varying mediump vec2 v_start_offset;
12 flat varying mediump vec2 v_scale_dir;
14 #ifdef WR_VERTEX_SHADER
22 Gradient fetch_gradient(int address) {
23 vec4 data[2] = fetch_from_gpu_cache_2(address);
34 RectWithEndpoint local_rect,
35 RectWithEndpoint segment_rect,
37 int specific_resource_address,
43 Gradient gradient = fetch_gradient(prim_address);
45 write_gradient_vertex(
56 vec2 start_point = gradient.start_end_point.xy;
57 vec2 end_point = gradient.start_end_point.zw;
58 vec2 dir = end_point - start_point;
60 // Normalize UV and offsets to 0..1 scale.
61 v_scale_dir = dir / dot(dir, dir);
62 v_start_offset.x = dot(start_point, v_scale_dir);
63 v_scale_dir *= v_repeated_size;
67 #ifdef WR_FRAGMENT_SHADER
68 float get_gradient_offset(vec2 pos) {
69 // Project position onto a direction vector to compute offset.
70 return dot(pos, v_scale_dir) - v_start_offset.x;
74 vec4 color = sample_gradient(get_gradient_offset(compute_repeated_pos()));
76 #ifdef WR_FEATURE_ALPHA_PASS
77 color *= antialias_brush();
80 return Fragment(color);
84 void swgl_drawSpanRGBA8() {
85 int address = swgl_validateGradient(sGpuBufferF, get_gpu_buffer_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
90 swgl_commitLinearGradientRGBA8(sGpuBufferF, address, GRADIENT_ENTRIES, true, v_gradient_repeat.x != 0.0,
91 v_pos, v_scale_dir, v_start_offset.x);