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