tor-browser

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

brush_yuv_image.glsl (5037B)


      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 VECS_PER_SPECIFIC_BRUSH 1
      6 
      7 #include shared,prim_shared,brush,yuv,image_source
      8 
      9 varying highp vec2 vUv_Y;
     10 flat varying highp vec4 vUvBounds_Y;
     11 
     12 varying highp vec2 vUv_U;
     13 flat varying highp vec4 vUvBounds_U;
     14 
     15 varying highp vec2 vUv_V;
     16 flat varying highp vec4 vUvBounds_V;
     17 
     18 flat varying YUV_PRECISION vec3 vYcbcrBias;
     19 flat varying YUV_PRECISION mat3 vRgbFromDebiasedYcbcr;
     20 
     21 // YUV format. Packed in to vector to work around bug 1630356.
     22 flat varying mediump ivec2 vFormat;
     23 
     24 #ifdef SWGL_DRAW_SPAN
     25 flat varying mediump int vRescaleFactor;
     26 #endif
     27 
     28 #ifdef WR_VERTEX_SHADER
     29 
     30 YuvPrimitive fetch_yuv_primitive(int address) {
     31     vec4 data = fetch_from_gpu_buffer_1f(address);
     32     // From YuvImageData.write_prim_gpu_blocks:
     33     int channel_bit_depth = int(data.x);
     34     int color_space = int(data.y);
     35     int yuv_format = int(data.z);
     36     return YuvPrimitive(channel_bit_depth, color_space, yuv_format);
     37 }
     38 
     39 void brush_vs(
     40     VertexInfo vi,
     41     int prim_address,
     42     RectWithEndpoint local_rect,
     43     RectWithEndpoint segment_rect,
     44     ivec4 prim_user_data,
     45     int specific_resource_address,
     46     mat4 transform,
     47     PictureTask pic_task,
     48     int brush_flags,
     49     vec4 unused
     50 ) {
     51     vec2 f = (vi.local_pos - local_rect.p0) / rect_size(local_rect);
     52 
     53     YuvPrimitive prim = fetch_yuv_primitive(prim_address);
     54 
     55 #ifdef SWGL_DRAW_SPAN
     56     // swgl_commitTextureLinearYUV needs to know the color space specifier and
     57     // also needs to know how many bits of scaling are required to normalize
     58     // HDR textures. Note that MSB HDR formats don't need renormalization.
     59     vRescaleFactor = 0;
     60     if (prim.channel_bit_depth > 8 && prim.yuv_format != YUV_FORMAT_P010) {
     61         vRescaleFactor = 16 - prim.channel_bit_depth;
     62     }
     63 #endif
     64 
     65     YuvColorMatrixInfo mat_info = get_rgb_from_ycbcr_info(prim);
     66     vYcbcrBias = mat_info.ycbcr_bias;
     67     vRgbFromDebiasedYcbcr = mat_info.rgb_from_debiased_ycbrc;
     68 
     69     vFormat.x = prim.yuv_format;
     70 
     71     // The additional test for 99 works around a gen6 shader compiler bug: 1708937
     72     if (vFormat.x == YUV_FORMAT_PLANAR || vFormat.x == 99) {
     73         ImageSource res_y = fetch_image_source(prim_user_data.x);
     74         ImageSource res_u = fetch_image_source(prim_user_data.y);
     75         ImageSource res_v = fetch_image_source(prim_user_data.z);
     76         write_uv_rect(res_y.uv_rect.p0, res_y.uv_rect.p1, f, TEX_SIZE_YUV(sColor0), vUv_Y, vUvBounds_Y);
     77         write_uv_rect(res_u.uv_rect.p0, res_u.uv_rect.p1, f, TEX_SIZE_YUV(sColor1), vUv_U, vUvBounds_U);
     78         write_uv_rect(res_v.uv_rect.p0, res_v.uv_rect.p1, f, TEX_SIZE_YUV(sColor2), vUv_V, vUvBounds_V);
     79     } else if (vFormat.x == YUV_FORMAT_NV12 || vFormat.x == YUV_FORMAT_P010) {
     80         ImageSource res_y = fetch_image_source(prim_user_data.x);
     81         ImageSource res_u = fetch_image_source(prim_user_data.y);
     82         write_uv_rect(res_y.uv_rect.p0, res_y.uv_rect.p1, f, TEX_SIZE_YUV(sColor0), vUv_Y, vUvBounds_Y);
     83         write_uv_rect(res_u.uv_rect.p0, res_u.uv_rect.p1, f, TEX_SIZE_YUV(sColor1), vUv_U, vUvBounds_U);
     84     } else if (vFormat.x == YUV_FORMAT_INTERLEAVED) {
     85         ImageSource res_y = fetch_image_source(prim_user_data.x);
     86         write_uv_rect(res_y.uv_rect.p0, res_y.uv_rect.p1, f, TEX_SIZE_YUV(sColor0), vUv_Y, vUvBounds_Y);
     87     }
     88 }
     89 #endif
     90 
     91 #ifdef WR_FRAGMENT_SHADER
     92 
     93 Fragment brush_fs() {
     94     vec4 color = sample_yuv(
     95         vFormat.x,
     96         vYcbcrBias,
     97         vRgbFromDebiasedYcbcr,
     98         vUv_Y,
     99         vUv_U,
    100         vUv_V,
    101         vUvBounds_Y,
    102         vUvBounds_U,
    103         vUvBounds_V
    104     );
    105 
    106 #ifdef WR_FEATURE_ALPHA_PASS
    107     color *= antialias_brush();
    108 #endif
    109 
    110     //color.r = float(100+vFormat) / 255.0;
    111     //color.g = vYcbcrBias.x;
    112     //color.b = vYcbcrBias.y;
    113     return Fragment(color);
    114 }
    115 
    116 #ifdef SWGL_DRAW_SPAN
    117 void swgl_drawSpanRGBA8() {
    118     if (vFormat.x == YUV_FORMAT_PLANAR) {
    119         swgl_commitTextureLinearYUV(sColor0, vUv_Y, vUvBounds_Y,
    120                                     sColor1, vUv_U, vUvBounds_U,
    121                                     sColor2, vUv_V, vUvBounds_V,
    122                                     vYcbcrBias,
    123                                     vRgbFromDebiasedYcbcr,
    124                                     vRescaleFactor);
    125     } else if (vFormat.x == YUV_FORMAT_NV12 || vFormat.x == YUV_FORMAT_P010) {
    126         swgl_commitTextureLinearYUV(sColor0, vUv_Y, vUvBounds_Y,
    127                                     sColor1, vUv_U, vUvBounds_U,
    128                                     vYcbcrBias,
    129                                     vRgbFromDebiasedYcbcr,
    130                                     vRescaleFactor);
    131     } else if (vFormat.x == YUV_FORMAT_INTERLEAVED) {
    132         swgl_commitTextureLinearYUV(sColor0, vUv_Y, vUvBounds_Y,
    133                                     vYcbcrBias,
    134                                     vRgbFromDebiasedYcbcr,
    135                                     vRescaleFactor);
    136     }
    137 }
    138 #endif
    139 
    140 #endif