tor-browser

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

cs_conic_gradient.glsl (2238B)


      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 #define PI                  3.141592653589793
      8 
      9 varying highp vec2 v_pos;
     10 
     11 flat varying highp vec2 v_center;
     12 
     13 // x: start offset, y: offset scale, z: angle
     14 // Packed in to a vector to work around bug 1630356.
     15 flat varying highp vec3 v_start_offset_offset_scale_angle_vec;
     16 #define v_start_offset v_start_offset_offset_scale_angle_vec.x
     17 #define v_offset_scale v_start_offset_offset_scale_angle_vec.y
     18 #define v_angle v_start_offset_offset_scale_angle_vec.z
     19 
     20 #ifdef WR_VERTEX_SHADER
     21 
     22 #define EXTEND_MODE_REPEAT 1
     23 
     24 PER_INSTANCE in vec4 aTaskRect;
     25 PER_INSTANCE in vec2 aCenter;
     26 PER_INSTANCE in vec2 aScale;
     27 PER_INSTANCE in float aStartOffset;
     28 PER_INSTANCE in float aEndOffset;
     29 PER_INSTANCE in float aAngle;
     30 PER_INSTANCE in int aExtendMode;
     31 PER_INSTANCE in int aGradientStopsAddress;
     32 
     33 void main(void) {
     34     // Store 1/d where d = end_offset - start_offset
     35     // If d = 0, we can't get its reciprocal. Instead, just use a zero scale.
     36     float d = aEndOffset - aStartOffset;
     37     v_offset_scale = d != 0.0 ? 1.0 / d : 0.0;
     38 
     39     vec2 pos = mix(aTaskRect.xy, aTaskRect.zw, aPosition.xy);
     40     gl_Position = uTransform * vec4(pos, 0.0, 1.0);
     41 
     42     v_angle = PI / 2.0 - aAngle;
     43     v_start_offset = aStartOffset * v_offset_scale;
     44 
     45     // v_pos and v_center are in a coordinate space relative to the task rect
     46     // (so they are independent of the task origin).
     47     v_center = aCenter * v_offset_scale;
     48     v_pos = (aTaskRect.zw - aTaskRect.xy) * aPosition.xy * v_offset_scale * aScale;
     49 
     50     v_gradient_repeat.x = float(aExtendMode == EXTEND_MODE_REPEAT);
     51     v_gradient_address.x = aGradientStopsAddress;
     52 }
     53 #endif
     54 
     55 
     56 #ifdef WR_FRAGMENT_SHADER
     57 
     58 void main(void) {
     59     // Use inverse trig to find the angle offset from the relative position.
     60     vec2 current_dir = v_pos - v_center;
     61     float current_angle = atan(current_dir.y, current_dir.x) + v_angle;
     62     float offset = fract(current_angle / (2.0 * PI)) * v_offset_scale - v_start_offset;
     63 
     64     oFragColor = sample_gradient(offset);
     65 }
     66 
     67 #endif