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 shared,rect,render_task,gpu_cache,gpu_buffer,gradient
7 varying highp vec2 v_pos;
9 flat varying mediump vec2 v_scale_dir;
11 // Start offset. Packed in to a vector to work around bug 1630356.
12 flat varying highp vec2 v_start_offset;
14 #ifdef WR_VERTEX_SHADER
16 #define EXTEND_MODE_REPEAT 1
18 PER_INSTANCE in vec4 aTaskRect;
19 PER_INSTANCE in vec2 aStartPoint;
20 PER_INSTANCE in vec2 aEndPoint;
21 PER_INSTANCE in vec2 aScale;
22 PER_INSTANCE in int aExtendMode;
23 PER_INSTANCE in int aGradientStopsAddress;
26 vec2 pos = mix(aTaskRect.xy, aTaskRect.zw, aPosition.xy);
27 gl_Position = uTransform * vec4(pos, 0.0, 1.0);
29 v_pos = aPosition.xy * aScale;
31 vec2 dir = aEndPoint - aStartPoint;
33 // Normalize UV and offsets to 0..1 scale.
34 v_scale_dir = dir / dot(dir, dir);
35 v_start_offset.x = dot(aStartPoint, v_scale_dir);
37 v_scale_dir *= (aTaskRect.zw - aTaskRect.xy);
39 v_gradient_repeat.x = float(aExtendMode == EXTEND_MODE_REPEAT);
40 v_gradient_address.x = aGradientStopsAddress;
45 #ifdef WR_FRAGMENT_SHADER
48 // Project position onto a direction vector to compute offset.
49 float offset = dot(v_pos, v_scale_dir) - v_start_offset.x;
51 oFragColor = sample_gradient(offset);
56 void swgl_drawSpanRGBA8() {
57 int address = swgl_validateGradient(sGpuBufferF, get_gpu_buffer_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
62 swgl_commitLinearGradientRGBA8(sGpuBufferF, address, GRADIENT_ENTRIES, false, v_gradient_repeat.x != 0.0,
63 v_pos, v_scale_dir, v_start_offset.x);