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 #define VECS_PER_SPECIFIC_BRUSH 1
7 #include shared,prim_shared,brush,yuv
9 varying highp vec2 vUv_Y;
10 flat varying highp vec4 vUvBounds_Y;
12 varying highp vec2 vUv_U;
13 flat varying highp vec4 vUvBounds_U;
15 varying highp vec2 vUv_V;
16 flat varying highp vec4 vUvBounds_V;
18 flat varying YUV_PRECISION vec3 vYcbcrBias;
19 flat varying YUV_PRECISION mat3 vRgbFromDebiasedYcbcr;
21 // YUV format. Packed in to vector to work around bug 1630356.
22 flat varying mediump ivec2 vFormat;
25 flat varying mediump int vRescaleFactor;
28 #ifdef WR_VERTEX_SHADER
30 YuvPrimitive fetch_yuv_primitive(int address) {
31 vec4 data = fetch_from_gpu_cache_1(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);
42 RectWithEndpoint local_rect,
43 RectWithEndpoint segment_rect,
45 int specific_resource_address,
51 vec2 f = (vi.local_pos - local_rect.p0) / rect_size(local_rect);
53 YuvPrimitive prim = fetch_yuv_primitive(prim_address);
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.
60 if (prim.channel_bit_depth > 8 && prim.yuv_format != YUV_FORMAT_P010) {
61 vRescaleFactor = 16 - prim.channel_bit_depth;
65 YuvColorMatrixInfo mat_info = get_rgb_from_ycbcr_info(prim);
66 vYcbcrBias = mat_info.ycbcr_bias;
67 vRgbFromDebiasedYcbcr = mat_info.rgb_from_debiased_ycbrc;
69 vFormat.x = prim.yuv_format;
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);
91 #ifdef WR_FRAGMENT_SHADER
94 vec4 color = sample_yuv(
97 vRgbFromDebiasedYcbcr,
106 #ifdef WR_FEATURE_ALPHA_PASS
107 color *= antialias_brush();
110 //color.r = float(100+vFormat) / 255.0;
111 //color.g = vYcbcrBias.x;
112 //color.b = vYcbcrBias.y;
113 return Fragment(color);
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,
123 vRgbFromDebiasedYcbcr,
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,
129 vRgbFromDebiasedYcbcr,
131 } else if (vFormat.x == YUV_FORMAT_INTERLEAVED) {
132 swgl_commitTextureLinearYUV(sColor0, vUv_Y, vUvBounds_Y,
134 vRgbFromDebiasedYcbcr,