tor-browser

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

ps_split_composite.glsl (3653B)


      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 #define WR_FEATURE_TEXTURE_2D
      6 
      7 #include shared,prim_shared,image_source
      8 
      9 // interpolated UV coordinates to sample.
     10 varying highp vec2 vUv;
     11 
     12 // Flag to allow perspective interpolation of UV.
     13 // Packed in to a vector to work around bug 1630356.
     14 flat varying mediump vec2 vPerspective;
     15 
     16 flat varying highp vec4 vUvSampleBounds;
     17 
     18 #ifdef WR_VERTEX_SHADER
     19 struct SplitGeometry {
     20     vec2 local[4];
     21 };
     22 
     23 SplitGeometry fetch_split_geometry(int address) {
     24     vec4[2] data = fetch_from_gpu_buffer_2f(address);
     25 
     26     SplitGeometry geo;
     27     geo.local = vec2[4](
     28         data[0].xy,
     29         data[0].zw,
     30         data[1].xy,
     31         data[1].zw
     32     );
     33 
     34     return geo;
     35 }
     36 
     37 vec2 bilerp(vec2 a, vec2 b, vec2 c, vec2 d, float s, float t) {
     38     vec2 x = mix(a, b, t);
     39     vec2 y = mix(c, d, t);
     40     return mix(x, y, s);
     41 }
     42 
     43 struct SplitCompositeInstance {
     44     int prim_header_index;
     45     int polygons_address;
     46     float z;
     47     int render_task_index;
     48 };
     49 
     50 SplitCompositeInstance fetch_composite_instance() {
     51     SplitCompositeInstance ci;
     52 
     53     ci.prim_header_index = aData.x;
     54     ci.polygons_address = aData.y;
     55     ci.z = float(aData.z);
     56     ci.render_task_index = aData.w;
     57 
     58     return ci;
     59 }
     60 
     61 void main(void) {
     62     SplitCompositeInstance ci = fetch_composite_instance();
     63     SplitGeometry geometry = fetch_split_geometry(ci.polygons_address);
     64     PrimitiveHeader ph = fetch_prim_header(ci.prim_header_index);
     65     PictureTask dest_task = fetch_picture_task(ci.render_task_index);
     66     Transform transform = fetch_transform(ph.transform_id);
     67     ImageSource res = fetch_image_source(ph.user_data.x);
     68     ClipArea clip_area = fetch_clip_area(ph.user_data.w);
     69 
     70     vec2 dest_origin = dest_task.task_rect.p0 -
     71                        dest_task.content_origin;
     72 
     73     vec2 local_pos = bilerp(geometry.local[0], geometry.local[1],
     74                             geometry.local[3], geometry.local[2],
     75                             aPosition.y, aPosition.x);
     76     vec4 world_pos = transform.m * vec4(local_pos, 0.0, 1.0);
     77 
     78     vec4 final_pos = vec4(
     79         dest_origin * world_pos.w + world_pos.xy * dest_task.device_pixel_scale,
     80         world_pos.w * ci.z,
     81         world_pos.w
     82     );
     83 
     84     write_clip(
     85         world_pos,
     86         clip_area,
     87         dest_task
     88     );
     89 
     90     gl_Position = uTransform * final_pos;
     91 
     92     vec2 texture_size = vec2(TEX_SIZE(sColor0));
     93     vec2 uv0 = res.uv_rect.p0;
     94     vec2 uv1 = res.uv_rect.p1;
     95 
     96     vec2 min_uv = min(uv0, uv1);
     97     vec2 max_uv = max(uv0, uv1);
     98 
     99     vUvSampleBounds = vec4(
    100         min_uv + vec2(0.5),
    101         max_uv - vec2(0.5)
    102     ) / texture_size.xyxy;
    103 
    104     vec2 f = (local_pos - ph.local_rect.p0) / rect_size(ph.local_rect);
    105     f = get_image_quad_uv(ph.user_data.x, f);
    106     vec2 uv = mix(uv0, uv1, f);
    107     float perspective_interpolate = float(ph.user_data.y);
    108 
    109     vUv = uv / texture_size * mix(gl_Position.w, 1.0, perspective_interpolate);
    110     vPerspective.x = perspective_interpolate;
    111 }
    112 #endif
    113 
    114 #ifdef WR_FRAGMENT_SHADER
    115 void main(void) {
    116     float alpha = do_clip();
    117     float perspective_divisor = mix(gl_FragCoord.w, 1.0, vPerspective.x);
    118     vec2 uv = clamp(vUv * perspective_divisor, vUvSampleBounds.xy, vUvSampleBounds.zw);
    119     write_output(alpha * texture(sColor0, uv));
    120 }
    121 
    122 #ifdef SWGL_DRAW_SPAN
    123 void swgl_drawSpanRGBA8() {
    124     float perspective_divisor = mix(swgl_forceScalar(gl_FragCoord.w), 1.0, vPerspective.x);
    125     vec2 uv = vUv * perspective_divisor;
    126 
    127     swgl_commitTextureRGBA8(sColor0, uv, vUvSampleBounds);
    128 }
    129 #endif
    130 
    131 #endif