blob: 0e78d10d76b07e3a6dfd5439c976843c15d86873 [file] [log] [blame]
static constexpr char SKSL_MINIFIED_sksl_graphite_frag[] =
"const int $kTileModeClamp=0;const int $kTileModeRepeat=1;const int $kTileModeMirror"
"=2;const int $kTileModeDecal=3;const int $kFilterModeNearest=0;const int $kFilterModeLinear"
"=1;const int $kTFTypeSRGB=1;const int $kTFTypePQ=2;const int $kTFTypeHLG=3;"
"const int $kTFTypeHLGinv=4;const int $kColorSpaceXformFlagUnpremul=1;const int"
" $kColorSpaceXformFlagLinearize=2;const int $kColorSpaceXformFlagGamutTransform"
"=4;const int $kColorSpaceXformFlagEncode=8;const int $kColorSpaceXformFlagPremul"
"=16;$pure half4 sk_error(){return half4(1.,0.,1.,1.);}$pure half4 sk_passthrough"
"(half4 color){return color;}$pure half4 sk_solid_shader(float4 colorParam){"
"return half4(colorParam);}$pure half $apply_xfer_fn(int kind,half x,half[7]"
"cs){half G=cs[0];half A=cs[1];half B=cs[2];half C=cs[3];half D=cs[4];half E"
"=cs[5];half F=cs[6];half s=sign(x);x=abs(x);switch(kind){case 1:x=x<D?C*x+F"
":pow(A*x+B,G)+E;break;case 2:x=pow(max(A+B*pow(x,C),0.)/(D+E*pow(x,C)),F);break"
";case 3:x=x*A<=1.?pow(x*A,B):exp((x-E)*C)+D;x*=F+1.;break;case 4:x/=F+1.;x="
"x<=1.?A*pow(x,B):C*log(x-D)+E;break;}return s*x;}$pure half4 sk_color_space_transform"
"(half4 color,int flags,int srcKind,int dstKind,half[7]srcCoeffs,half[7]dstCoeffs"
",half3x3 gamutTransform){if(bool(flags&$kColorSpaceXformFlagUnpremul)){color"
"=unpremul(color);}if(bool(flags&$kColorSpaceXformFlagLinearize)){color.x=$apply_xfer_fn"
"(srcKind,color.x,srcCoeffs);color.y=$apply_xfer_fn(srcKind,color.y,srcCoeffs"
");color.z=$apply_xfer_fn(srcKind,color.z,srcCoeffs);}if(bool(flags&$kColorSpaceXformFlagGamutTransform"
")){color.xyz=gamutTransform*color.xyz;}if(bool(flags&$kColorSpaceXformFlagEncode"
")){color.x=$apply_xfer_fn(dstKind,color.x,dstCoeffs);color.y=$apply_xfer_fn"
"(dstKind,color.y,dstCoeffs);color.z=$apply_xfer_fn(dstKind,color.z,dstCoeffs"
");}if(bool(flags&$kColorSpaceXformFlagPremul)){color.xyz*=color.w;}return color"
";}$pure float $tile(int tileMode,float f,float low,float high){switch(tileMode"
"){case 0:return clamp(f,low,high);case 1:{float length=high-low;return mod("
"f-low,length)+low;}case 2:{float length=high-low;float length2=2.*length;float"
" tmp=mod(f-low,length2);return mix(tmp,length2-tmp,step(length,tmp))+low;}default"
":return f;}}$pure half4 $sample_image(float2 pos,float2 imgSize,float4 subset"
",int tileModeX,int tileModeY,int filterMode,sampler2D s){if(tileModeX==$kTileModeDecal"
"&&filterMode==$kFilterModeNearest){float snappedX=floor(pos.x)+.5;if(snappedX"
"<subset.x||snappedX>subset.z){return half4(0.);}}if(tileModeY==$kTileModeDecal"
"&&filterMode==$kFilterModeNearest){float snappedY=floor(pos.y)+.5;if(snappedY"
"<subset.y||snappedY>subset.w){return half4(0.);}}pos.x=$tile(tileModeX,pos."
"x,subset.x,subset.z);pos.y=$tile(tileModeY,pos.y,subset.y,subset.w);float4 insetClamp"
";if(filterMode==$kFilterModeNearest){insetClamp=float4(floor(subset.xy)+.5,"
"ceil(subset.zw)-.5);}else{insetClamp=float4(subset.xy+.5,subset.zw-.5);}float2"
" clampedPos=clamp(pos,insetClamp.xy,insetClamp.zw);half4 color=sample(s,clampedPos"
"/imgSize);if(filterMode==$kFilterModeLinear){half2 error=half2(pos-clampedPos"
");half2 absError=abs(error);bool sampleExtraX=tileModeX==$kTileModeRepeat;bool"
" sampleExtraY=tileModeY==$kTileModeRepeat;if(sampleExtraX||sampleExtraY){float"
" extraCoordX;float extraCoordY;half4 extraColorX;half4 extraColorY;if(sampleExtraX"
"){extraCoordX=error.x>0.?insetClamp.x:insetClamp.z;extraColorX=sample(s,float2"
"(extraCoordX,clampedPos.y)/imgSize);}if(sampleExtraY){extraCoordY=error.y>0."
"?insetClamp.y:insetClamp.w;extraColorY=sample(s,float2(clampedPos.x,extraCoordY"
")/imgSize);}if(sampleExtraX&&sampleExtraY){half4 extraColorXY=sample(s,float2"
"(extraCoordX,extraCoordY)/imgSize);color=mix(mix(color,extraColorX,absError"
".x),mix(extraColorY,extraColorXY,absError.x),absError.y);}else if(sampleExtraX"
"){color=mix(color,extraColorX,absError.x);}else if(sampleExtraY){color=mix("
"color,extraColorY,absError.y);}}if(tileModeX==$kTileModeDecal){color*=max(1."
"-absError.x,0.);}if(tileModeY==$kTileModeDecal){color*=max(1.-absError.y,0."
");}}return color;}$pure half4 $cubic_filter_image(float2 pos,float2 imgSize"
",float4 subset,int tileModeX,int tileModeY,float4x4 coeffs,sampler2D s){float2"
" f=fract(pos-.5);pos-=1.5;pos=floor(pos)+.5;float4 wx=coeffs*float4(1.,f.x,"
"f.x*f.x,(f.x*f.x)*f.x);float4 wy=coeffs*float4(1.,f.y,f.y*f.y,(f.y*f.y)*f.y"
");float4 color=float4(0.);for(int y=0;y<4;++y){float4 rowColor=float4(0.);for"
"(int x=0;x<4;++x){rowColor+=wx[x]*float4($sample_image(pos+float2(float(x),"
"float(y)),imgSize,subset,tileModeX,tileModeY,$kFilterModeNearest,s));}color"
"+=wy[y]*rowColor;}return half4(color);}$pure half4 sk_image_shader(float2 coords"
",float2 imgSize,float4 subset,int tileModeX,int tileModeY,int filterMode,int"
" useCubic,float4x4 cubicCoeffs,int csXformFlags,int csXformSrcKind,int csXformDstKind"
",half[7]csXformSrcCoeffs,half[7]csXformDstCoeffs,half3x3 csXformGamutTransform"
",sampler2D s){half4 sampleColor=useCubic!=0?$cubic_filter_image(coords,imgSize"
",subset,tileModeX,tileModeY,cubicCoeffs,s):$sample_image(coords,imgSize,subset"
",tileModeX,tileModeY,filterMode,s);return sk_color_space_transform(sampleColor"
",csXformFlags,csXformSrcKind,csXformDstKind,csXformSrcCoeffs,csXformDstCoeffs"
",csXformGamutTransform);}$pure float2 $tile_grad(int tileMode,float2 t){switch"
"(tileMode){case 0:t.x=clamp(t.x,0.,1.);break;case 1:t.x=fract(t.x);break;case"
" 2:{float t_1=t.x-1.;t.x=(t_1-2.*floor(t_1*.5))-1.;if(sk_Caps.mustDoOpBetweenFloorAndAbs"
"){t.x=clamp(t.x,-1.,1.);}t.x=abs(t.x);break;}case 3:if(t.x<0.||t.x>1.){return"
" float2(0.,-1.);}break;}return t;}$pure half4 $colorize_grad_4(float4[4]colorsParam"
",float[4]offsetsParam,float2 t){if(t.y<0.){return half4(0.);}else if(t.x<=offsetsParam"
"[0]){return half4(colorsParam[0]);}else if(t.x<offsetsParam[1]){return half4"
"(mix(colorsParam[0],colorsParam[1],(t.x-offsetsParam[0])/(offsetsParam[1]-offsetsParam"
"[0])));}else if(t.x<offsetsParam[2]){return half4(mix(colorsParam[1],colorsParam"
"[2],(t.x-offsetsParam[1])/(offsetsParam[2]-offsetsParam[1])));}else if(t.x<"
"offsetsParam[3]){return half4(mix(colorsParam[2],colorsParam[3],(t.x-offsetsParam"
"[2])/(offsetsParam[3]-offsetsParam[2])));}else{return half4(colorsParam[3])"
";}}$pure half4 $colorize_grad_8(float4[8]colorsParam,float[8]offsetsParam,float2"
" t){if(t.y<0.){return half4(0.);}else if(t.x<offsetsParam[4]){if(t.x<offsetsParam"
"[2]){if(t.x<=offsetsParam[0]){return half4(colorsParam[0]);}else if(t.x<offsetsParam"
"[1]){return half4(mix(colorsParam[0],colorsParam[1],(t.x-offsetsParam[0])/("
"offsetsParam[1]-offsetsParam[0])));}else{return half4(mix(colorsParam[1],colorsParam"
"[2],(t.x-offsetsParam[1])/(offsetsParam[2]-offsetsParam[1])));}}else{if(t.x"
"<offsetsParam[3]){return half4(mix(colorsParam[2],colorsParam[3],(t.x-offsetsParam"
"[2])/(offsetsParam[3]-offsetsParam[2])));}else{return half4(mix(colorsParam"
"[3],colorsParam[4],(t.x-offsetsParam[3])/(offsetsParam[4]-offsetsParam[3]))"
");}}}else{if(t.x<offsetsParam[6]){if(t.x<offsetsParam[5]){return half4(mix("
"colorsParam[4],colorsParam[5],(t.x-offsetsParam[4])/(offsetsParam[5]-offsetsParam"
"[4])));}else{return half4(mix(colorsParam[5],colorsParam[6],(t.x-offsetsParam"
"[5])/(offsetsParam[6]-offsetsParam[5])));}}else{if(t.x<offsetsParam[7]){return"
" half4(mix(colorsParam[6],colorsParam[7],(t.x-offsetsParam[6])/(offsetsParam"
"[7]-offsetsParam[6])));}else{return half4(colorsParam[7]);}}}}$pure float2 $linear_grad_layout"
"(float2 point0Param,float2 point1Param,float2 pos){pos-=point0Param;float2 delta"
"=point1Param-point0Param;float t=dot(pos,delta)/dot(delta,delta);return float2"
"(t,1.);}$pure float2 $radial_grad_layout(float2 centerParam,float radiusParam"
",float2 pos){float t=distance(pos,centerParam)/radiusParam;return float2(t,"
"1.);}$pure float2 $sweep_grad_layout(float2 centerParam,float biasParam,float"
" scaleParam,float2 pos){pos-=centerParam;float angle=sk_Caps.atan2ImplementedAsAtanYOverX"
"?2.*atan(-pos.y,length(pos)-pos.x):atan(-pos.y,-pos.x);float t=((angle*.159154937"
"+.5)+biasParam)*scaleParam;return float2(t,1.);}$pure float3x3 $map_to_unit_x"
"(float2 p0,float2 p1){return float3x3(0.,-1.,0.,1.,0.,0.,0.,0.,1.)*inverse("
"float3x3(p1.y-p0.y,p0.x-p1.x,0.,p1.x-p0.x,p1.y-p0.y,0.,p0.x,p0.y,1.));}$pure"
" float2 $conical_grad_layout(float2 point0Param,float2 point1Param,float radius0Param"
",float radius1Param,float2 pos){const float SK_ScalarNearlyZero=.000244140625"
";float dCenter=distance(point0Param,point1Param);float dRadius=radius1Param"
"-radius0Param;bool radial=dCenter<SK_ScalarNearlyZero;bool strip=abs(dRadius"
")<SK_ScalarNearlyZero;if(radial){if(strip){return float2(0.,-1.);}float scale"
"=1./dRadius;float scaleSign=sign(dRadius);float bias=radius0Param/dRadius;float2"
" pt=(pos-point0Param)*scale;float t=length(pt)*scaleSign-bias;return float2"
"(t,1.);}else if(strip){float3x3 transform=$map_to_unit_x(point0Param,point1Param"
");float r=radius0Param/dCenter;float r_2=r*r;float2 pt=(transform*float3(pos"
",1.)).xy;float t=r_2-pt.y*pt.y;if(t<0.){return float2(0.,-1.);}t=pt.x+sqrt("
"t);return float2(t,1.);}else{float f=radius0Param/(radius0Param-radius1Param"
");bool isSwapped=abs(f-1.)<SK_ScalarNearlyZero;if(isSwapped){float2 tmpPt=point0Param"
";point0Param=point1Param;point1Param=tmpPt;f=0.;}float2 Cf=point0Param*(1.-"
"f)+point1Param*f;float3x3 transform=$map_to_unit_x(Cf,point1Param);float scaleX"
"=abs(1.-f);float scaleY=scaleX;float r1=abs(radius1Param-radius0Param)/dCenter"
";bool isFocalOnCircle=abs(r1-1.)<SK_ScalarNearlyZero;if(isFocalOnCircle){scaleX"
"*=.5;scaleY*=.5;}else{scaleX*=r1/(r1*r1-1.);scaleY/=sqrt(abs(r1*r1-1.));}transform"
"=float3x3(scaleX,0.,0.,0.,scaleY,0.,0.,0.,1.)*transform;float2 pt=(transform"
"*float3(pos,1.)).xy;float invR1=1./r1;float dRadiusSign=sign(1.-f);bool isWellBehaved"
"=!isFocalOnCircle&&r1>1.;float x_t=-1.;if(isFocalOnCircle){x_t=dot(pt,pt)/pt"
".x;}else if(isWellBehaved){x_t=length(pt)-pt.x*invR1;}else{float temp=pt.x*"
"pt.x-pt.y*pt.y;if(temp>=0.){if(isSwapped||dRadiusSign<0.){x_t=-sqrt(temp)-pt"
".x*invR1;}else{x_t=sqrt(temp)-pt.x*invR1;}}}if(!isWellBehaved&&x_t<0.){return"
" float2(0.,-1.);}float t=f+dRadiusSign*x_t;if(isSwapped){t=1.-t;}return float2"
"(t,1.);}}$pure half4 sk_linear_grad_4_shader(float2 coords,float4[4]colorsParam"
",float[4]offsetsParam,float2 point0Param,float2 point1Param,int tileMode){float2"
" t=$linear_grad_layout(point0Param,point1Param,coords);t=$tile_grad(tileMode"
",t);return $colorize_grad_4(colorsParam,offsetsParam,t);}$pure half4 sk_linear_grad_8_shader"
"(float2 coords,float4[8]colorsParam,float[8]offsetsParam,float2 point0Param"
",float2 point1Param,int tileMode){float2 t=$linear_grad_layout(point0Param,"
"point1Param,coords);t=$tile_grad(tileMode,t);return $colorize_grad_8(colorsParam"
",offsetsParam,t);}$pure half4 sk_radial_grad_4_shader(float2 coords,float4["
"4]colorsParam,float[4]offsetsParam,float2 centerParam,float radiusParam,int"
" tileMode){float2 t=$radial_grad_layout(centerParam,radiusParam,coords);t=$tile_grad"
"(tileMode,t);return $colorize_grad_4(colorsParam,offsetsParam,t);}$pure half4"
" sk_radial_grad_8_shader(float2 coords,float4[8]colorsParam,float[8]offsetsParam"
",float2 centerParam,float radiusParam,int tileMode){float2 t=$radial_grad_layout"
"(centerParam,radiusParam,coords);t=$tile_grad(tileMode,t);return $colorize_grad_8"
"(colorsParam,offsetsParam,t);}$pure half4 sk_sweep_grad_4_shader(float2 coords"
",float4[4]colorsParam,float[4]offsetsParam,float2 centerParam,float biasParam"
",float scaleParam,int tileMode){float2 t=$sweep_grad_layout(centerParam,biasParam"
",scaleParam,coords);t=$tile_grad(tileMode,t);return $colorize_grad_4(colorsParam"
",offsetsParam,t);}$pure half4 sk_sweep_grad_8_shader(float2 coords,float4[8"
"]colorsParam,float[8]offsetsParam,float2 centerParam,float biasParam,float scaleParam"
",int tileMode){float2 t=$sweep_grad_layout(centerParam,biasParam,scaleParam"
",coords);t=$tile_grad(tileMode,t);return $colorize_grad_8(colorsParam,offsetsParam"
",t);}$pure half4 sk_conical_grad_4_shader(float2 coords,float4[4]colorsParam"
",float[4]offsetsParam,float2 point0Param,float2 point1Param,float radius0Param"
",float radius1Param,int tileMode){float2 t=$conical_grad_layout(point0Param"
",point1Param,radius0Param,radius1Param,coords);t=$tile_grad(tileMode,t);return"
" $colorize_grad_4(colorsParam,offsetsParam,t);}$pure half4 sk_conical_grad_8_shader"
"(float2 coords,float4[8]colorsParam,float[8]offsetsParam,float2 point0Param"
",float2 point1Param,float radius0Param,float radius1Param,int tileMode){float2"
" t=$conical_grad_layout(point0Param,point1Param,radius0Param,radius1Param,coords"
");t=$tile_grad(tileMode,t);return $colorize_grad_8(colorsParam,offsetsParam"
",t);}$pure half4 sk_matrix_colorfilter(half4 colorIn,float4x4 m,float4 v,int"
" inHSLA){if(bool(inHSLA)){colorIn=$rgb_to_hsl(colorIn.xyz,colorIn.w);}else{"
"colorIn=unpremul(colorIn);}half4 colorOut=half4(m*float4(colorIn)+v);if(bool"
"(inHSLA)){colorOut=$hsl_to_rgb(colorOut.xyz,colorOut.w);}else{colorOut=saturate"
"(colorOut);colorOut.xyz*=colorOut.w;}return colorOut;}$pure half4 sk_blend("
"int blendMode,half4 src,half4 dst){const int kClear=0;const int kSrc=1;const"
" int kDst=2;const int kSrcOver=3;const int kDstOver=4;const int kSrcIn=5;const"
" int kDstIn=6;const int kSrcOut=7;const int kDstOut=8;const int kSrcATop=9;"
"const int kDstATop=10;const int kXor=11;const int kPlus=12;const int kModulate"
"=13;const int kScreen=14;const int kOverlay=15;const int kDarken=16;const int"
" kLighten=17;const int kColorDodge=18;const int kColorBurn=19;const int kHardLight"
"=20;const int kSoftLight=21;const int kDifference=22;const int kExclusion=23"
";const int kMultiply=24;const int kHue=25;const int kSaturation=26;const int"
" kColor=27;const int kLuminosity=28;switch(blendMode){case 0:{return blend_clear"
"(src,dst);}case 1:{return blend_src(src,dst);}case 2:{return blend_dst(src,"
"dst);}case 3:{return blend_porter_duff(half4(1.,0.,0.,-1.),src,dst);}case 4"
":{return blend_porter_duff(half4(0.,1.,-1.,0.),src,dst);}case 5:{return blend_porter_duff"
"(half4(0.,0.,1.,0.),src,dst);}case 6:{return blend_porter_duff(half4(0.,0.,"
"0.,1.),src,dst);}case 7:{return blend_porter_duff(half4(0.,0.,-1.,0.),src,dst"
");}case 8:{return blend_porter_duff(half4(0.,0.,0.,-1.),src,dst);}case 9:{return"
" blend_porter_duff(half4(0.,0.,1.,-1.),src,dst);}case 10:{return blend_porter_duff"
"(half4(0.,0.,-1.,1.),src,dst);}case 11:{return blend_porter_duff(half4(0.,0."
",-1.,-1.),src,dst);}case 12:{return blend_porter_duff(half4(1.,1.,0.,0.),src"
",dst);}case 13:{return blend_modulate(src,dst);}case 14:{return blend_screen"
"(src,dst);}case 15:{return blend_overlay(0.,src,dst);}case 16:{return blend_darken"
"(1.,src,dst);}case 17:{return blend_darken(-1.,src,dst);}case 18:{return blend_color_dodge"
"(src,dst);}case 19:{return blend_color_burn(src,dst);}case 20:{return blend_overlay"
"(1.,src,dst);}case 21:{return blend_soft_light(src,dst);}case 22:{return blend_difference"
"(src,dst);}case 23:{return blend_exclusion(src,dst);}case 24:{return blend_multiply"
"(src,dst);}case 25:{return blend_hslc(half2(0.,1.),src,dst);}case 26:{return"
" blend_hslc(half2(1.),src,dst);}case 27:{return blend_hslc(half2(0.),src,dst"
");}case 28:{return blend_hslc(half2(1.,0.),src,dst);}default:return half4(0."
");}}$pure half4 sk_blend_shader(int blendMode,half4 dst,half4 src){return sk_blend"
"(blendMode,src,dst);}$pure half4 porter_duff_blend_shader(half4 blendOp,half4"
" dst,half4 src){return blend_porter_duff(blendOp,src,dst);}$pure half4 sk_blend_colorfilter"
"(half4 dstColor,int blendMode,float4 srcColor){return sk_blend(blendMode,half4"
"(srcColor),dstColor);}$pure half4 sk_table_colorfilter(half4 inColor,sampler2D"
" s){half4 coords=(unpremul(inColor)*255.)/256.+.001953125;half4 color=half4"
"(sample(s,float2(half2(coords.x,.375))).x,sample(s,float2(half2(coords.y,.625"
"))).x,sample(s,float2(half2(coords.z,.875))).x,1.);return color*sample(s,float2"
"(half2(coords.w,.125))).x;}$pure half4 sk_gaussian_colorfilter(half4 inColor"
"){half factor=1.-inColor.w;factor=exp((-factor*factor)*4.)-.018;return half4"
"(factor);}";