tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cs_radial_gradient.glsl (2421B)


      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/. */
      4 
      5 #include shared,rect,render_task,gpu_buffer,gradient
      6 
      7 varying highp vec2 v_pos;
      8 
      9 // Start radius. Packed in to a vector to work around bug 1630356.
     10 flat varying highp vec2 v_start_radius;
     11 
     12 #ifdef WR_VERTEX_SHADER
     13 
     14 #define EXTEND_MODE_REPEAT 1
     15 
     16 PER_INSTANCE in vec4 aTaskRect;
     17 PER_INSTANCE in vec2 aCenter;
     18 PER_INSTANCE in vec2 aScale;
     19 PER_INSTANCE in float aStartRadius;
     20 PER_INSTANCE in float aEndRadius;
     21 PER_INSTANCE in float aXYRatio;
     22 PER_INSTANCE in int aExtendMode;
     23 PER_INSTANCE in int aGradientStopsAddress;
     24 
     25 void main(void) {
     26     // Store 1/rd where rd = end_radius - start_radius
     27     // If rd = 0, we can't get its reciprocal. Instead, just use a zero scale.
     28     float rd = aEndRadius - aStartRadius;
     29     float radius_scale = rd != 0.0 ? 1.0 / rd : 0.0;
     30 
     31     vec2 pos = mix(aTaskRect.xy, aTaskRect.zw, aPosition.xy);
     32     gl_Position = uTransform * vec4(pos, 0.0, 1.0);
     33 
     34     v_start_radius.x = aStartRadius * radius_scale;
     35 
     36     // Transform all coordinates by the y scale so the
     37     // fragment shader can work with circles
     38 
     39     // v_pos is in a coordinate space relative to the task rect
     40     // (so it is independent of the task origin).
     41     v_pos = ((aTaskRect.zw - aTaskRect.xy) * aPosition.xy * aScale - aCenter) * radius_scale;
     42     v_pos.y *= aXYRatio;
     43 
     44     v_gradient_repeat.x = float(aExtendMode == EXTEND_MODE_REPEAT);
     45     v_gradient_address.x = aGradientStopsAddress;
     46 }
     47 #endif
     48 
     49 
     50 #ifdef WR_FRAGMENT_SHADER
     51 
     52 void main(void) {
     53     // Solve for t in length(pd) = v_start_radius + t * rd
     54     float offset = length(v_pos) - v_start_radius.x;
     55 
     56     oFragColor = sample_gradient(offset);
     57 }
     58 
     59 #ifdef SWGL_DRAW_SPAN
     60 void swgl_drawSpanRGBA8() {
     61     int address = swgl_validateGradient(sGpuBufferF, get_gpu_buffer_uv(v_gradient_address.x),
     62                                         int(GRADIENT_ENTRIES + 2.0));
     63     if (address < 0) {
     64         return;
     65     }
     66 #ifdef WR_FEATURE_DITHERING
     67     swgl_commitDitheredRadialGradientRGBA8(sGpuBufferF, address, GRADIENT_ENTRIES, v_gradient_repeat.x != 0.0,
     68                                    v_pos, v_start_radius.x);
     69 #else
     70     swgl_commitRadialGradientRGBA8(sGpuBufferF, address, GRADIENT_ENTRIES, v_gradient_repeat.x != 0.0, v_pos, v_start_radius.x);
     71 #endif
     72 }
     73 #endif
     74 
     75 #endif