92748af1a5
This drastically reduces the number of functions which we allow to be inlined. If this change does not hurt our performance, it will allow us to trivially remove hundreds of LOC. All current data leads us to believe that it may affect the Mali 400 but is highly unlikely to change results on any other device in the tree. More info: http://go/optimization-in-sksl-inliner Change-Id: Ia6b706742ce5407453e0e697b6c1f9201084c0e8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/384858 Auto-Submit: John Stiles <johnstiles@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
198 lines
7.8 KiB
GLSL
198 lines
7.8 KiB
GLSL
|
|
out vec4 sk_FragColor;
|
|
in vec4 src;
|
|
in vec4 dst;
|
|
float _blend_overlay_component(vec2 s, vec2 d) {
|
|
return 2.0 * d.x <= d.y ? (2.0 * s.x) * d.x : s.y * d.y - (2.0 * (d.y - d.x)) * (s.y - s.x);
|
|
}
|
|
vec4 blend_overlay(vec4 src, vec4 dst) {
|
|
vec4 result = vec4(_blend_overlay_component(src.xw, dst.xw), _blend_overlay_component(src.yw, dst.yw), _blend_overlay_component(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
|
result.xyz += dst.xyz * (1.0 - src.w) + src.xyz * (1.0 - dst.w);
|
|
return result;
|
|
}
|
|
vec4 blend_darken(vec4 src, vec4 dst) {
|
|
vec4 result = src + (1.0 - src.w) * dst;
|
|
result.xyz = min(result.xyz, (1.0 - dst.w) * src.xyz + dst.xyz);
|
|
return result;
|
|
}
|
|
vec4 blend_lighten(vec4 src, vec4 dst) {
|
|
vec4 result = src + (1.0 - src.w) * dst;
|
|
result.xyz = max(result.xyz, (1.0 - dst.w) * src.xyz + dst.xyz);
|
|
return result;
|
|
}
|
|
float _color_dodge_component(vec2 s, vec2 d) {
|
|
if (d.x == 0.0) {
|
|
return s.x * (1.0 - d.y);
|
|
} else {
|
|
float delta = s.y - s.x;
|
|
if (delta == 0.0) {
|
|
return (s.y * d.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
|
} else {
|
|
float _0_n = d.x * s.y;
|
|
delta = min(d.y, _0_n / delta);
|
|
return (delta * s.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
|
}
|
|
}
|
|
}
|
|
float _color_burn_component(vec2 s, vec2 d) {
|
|
if (d.y == d.x) {
|
|
return (s.y * d.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
|
} else if (s.x == 0.0) {
|
|
return d.x * (1.0 - s.y);
|
|
} else {
|
|
float _1_n = (d.y - d.x) * s.y;
|
|
float delta = max(0.0, d.y - _1_n / s.x);
|
|
return (delta * s.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
|
}
|
|
}
|
|
float _soft_light_component(vec2 s, vec2 d) {
|
|
if (2.0 * s.x <= s.y) {
|
|
float _2_n = (d.x * d.x) * (s.y - 2.0 * s.x);
|
|
return (_2_n / d.y + (1.0 - d.y) * s.x) + d.x * ((-s.y + 2.0 * s.x) + 1.0);
|
|
} else if (4.0 * d.x <= d.y) {
|
|
float DSqd = d.x * d.x;
|
|
float DCub = DSqd * d.x;
|
|
float DaSqd = d.y * d.y;
|
|
float DaCub = DaSqd * d.y;
|
|
float _3_n = ((DaSqd * (s.x - d.x * ((3.0 * s.y - 6.0 * s.x) - 1.0)) + ((12.0 * d.y) * DSqd) * (s.y - 2.0 * s.x)) - (16.0 * DCub) * (s.y - 2.0 * s.x)) - DaCub * s.x;
|
|
return _3_n / DaSqd;
|
|
} else {
|
|
return ((d.x * ((s.y - 2.0 * s.x) + 1.0) + s.x) - sqrt(d.y * d.x) * (s.y - 2.0 * s.x)) - d.y * s.x;
|
|
}
|
|
}
|
|
vec3 _blend_set_color_luminance(vec3 hueSatColor, float alpha, vec3 lumColor) {
|
|
float lum = dot(vec3(0.30000001192092896, 0.5899999737739563, 0.10999999940395355), lumColor);
|
|
vec3 result = (lum - dot(vec3(0.30000001192092896, 0.5899999737739563, 0.10999999940395355), hueSatColor)) + hueSatColor;
|
|
float minComp = min(min(result.x, result.y), result.z);
|
|
float maxComp = max(max(result.x, result.y), result.z);
|
|
if (minComp < 0.0 && lum != minComp) {
|
|
float _4_d = lum - minComp;
|
|
result = lum + (result - lum) * (lum / _4_d);
|
|
}
|
|
if (maxComp > alpha && maxComp != lum) {
|
|
vec3 _5_n = (result - lum) * (alpha - lum);
|
|
float _6_d = maxComp - lum;
|
|
return lum + _5_n / _6_d;
|
|
} else {
|
|
return result;
|
|
}
|
|
}
|
|
vec3 _blend_set_color_saturation_helper(vec3 minMidMax, float sat) {
|
|
if (minMidMax.x < minMidMax.z) {
|
|
float _7_n = sat * (minMidMax.y - minMidMax.x);
|
|
float _8_d = minMidMax.z - minMidMax.x;
|
|
return vec3(0.0, _7_n / _8_d, sat);
|
|
} else {
|
|
return vec3(0.0);
|
|
}
|
|
}
|
|
vec3 _blend_set_color_saturation(vec3 hueLumColor, vec3 satColor) {
|
|
float sat = max(max(satColor.x, satColor.y), satColor.z) - min(min(satColor.x, satColor.y), satColor.z);
|
|
if (hueLumColor.x <= hueLumColor.y) {
|
|
if (hueLumColor.y <= hueLumColor.z) {
|
|
return _blend_set_color_saturation_helper(hueLumColor, sat);
|
|
} else if (hueLumColor.x <= hueLumColor.z) {
|
|
return _blend_set_color_saturation_helper(hueLumColor.xzy, sat).xzy;
|
|
} else {
|
|
return _blend_set_color_saturation_helper(hueLumColor.zxy, sat).yzx;
|
|
}
|
|
} else if (hueLumColor.x <= hueLumColor.z) {
|
|
return _blend_set_color_saturation_helper(hueLumColor.yxz, sat).yxz;
|
|
} else if (hueLumColor.y <= hueLumColor.z) {
|
|
return _blend_set_color_saturation_helper(hueLumColor.yzx, sat).zxy;
|
|
} else {
|
|
return _blend_set_color_saturation_helper(hueLumColor.zyx, sat).zyx;
|
|
}
|
|
}
|
|
vec4 blend_hue(vec4 src, vec4 dst) {
|
|
float alpha = dst.w * src.w;
|
|
vec3 sda = src.xyz * dst.w;
|
|
vec3 dsa = dst.xyz * src.w;
|
|
return vec4((((_blend_set_color_luminance(_blend_set_color_saturation(sda, dsa), alpha, dsa) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha);
|
|
}
|
|
vec4 blend_saturation(vec4 src, vec4 dst) {
|
|
float alpha = dst.w * src.w;
|
|
vec3 sda = src.xyz * dst.w;
|
|
vec3 dsa = dst.xyz * src.w;
|
|
return vec4((((_blend_set_color_luminance(_blend_set_color_saturation(dsa, sda), alpha, dsa) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha);
|
|
}
|
|
vec4 blend_color(vec4 src, vec4 dst) {
|
|
float alpha = dst.w * src.w;
|
|
vec3 sda = src.xyz * dst.w;
|
|
vec3 dsa = dst.xyz * src.w;
|
|
return vec4((((_blend_set_color_luminance(sda, alpha, dsa) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha);
|
|
}
|
|
vec4 blend_luminosity(vec4 src, vec4 dst) {
|
|
float alpha = dst.w * src.w;
|
|
vec3 sda = src.xyz * dst.w;
|
|
vec3 dsa = dst.xyz * src.w;
|
|
return vec4((((_blend_set_color_luminance(dsa, alpha, sda) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha);
|
|
}
|
|
vec4 blend(int mode, vec4 src, vec4 dst) {
|
|
switch (mode) {
|
|
case 0:
|
|
return vec4(0.0);
|
|
case 1:
|
|
return src;
|
|
case 2:
|
|
return dst;
|
|
case 3:
|
|
return src + (1.0 - src.w) * dst;
|
|
case 4:
|
|
return (1.0 - dst.w) * src + dst;
|
|
case 5:
|
|
return src * dst.w;
|
|
case 6:
|
|
return dst * src.w;
|
|
case 7:
|
|
return (1.0 - dst.w) * src;
|
|
case 8:
|
|
return (1.0 - src.w) * dst;
|
|
case 9:
|
|
return dst.w * src + (1.0 - src.w) * dst;
|
|
case 10:
|
|
return (1.0 - dst.w) * src + src.w * dst;
|
|
case 11:
|
|
return (1.0 - dst.w) * src + (1.0 - src.w) * dst;
|
|
case 12:
|
|
return min(src + dst, 1.0);
|
|
case 13:
|
|
return src * dst;
|
|
case 14:
|
|
return src + (1.0 - src) * dst;
|
|
case 15:
|
|
return blend_overlay(src, dst);
|
|
case 16:
|
|
return blend_darken(src, dst);
|
|
case 17:
|
|
return blend_lighten(src, dst);
|
|
case 18:
|
|
return vec4(_color_dodge_component(src.xw, dst.xw), _color_dodge_component(src.yw, dst.yw), _color_dodge_component(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
|
case 19:
|
|
return vec4(_color_burn_component(src.xw, dst.xw), _color_burn_component(src.yw, dst.yw), _color_burn_component(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
|
case 20:
|
|
return blend_overlay(dst, src);
|
|
case 21:
|
|
return dst.w == 0.0 ? src : vec4(_soft_light_component(src.xw, dst.xw), _soft_light_component(src.yw, dst.yw), _soft_light_component(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
|
case 22:
|
|
return vec4((src.xyz + dst.xyz) - 2.0 * min(src.xyz * dst.w, dst.xyz * src.w), src.w + (1.0 - src.w) * dst.w);
|
|
case 23:
|
|
return vec4((dst.xyz + src.xyz) - (2.0 * dst.xyz) * src.xyz, src.w + (1.0 - src.w) * dst.w);
|
|
case 24:
|
|
return vec4(((1.0 - src.w) * dst.xyz + (1.0 - dst.w) * src.xyz) + src.xyz * dst.xyz, src.w + (1.0 - src.w) * dst.w);
|
|
case 25:
|
|
return blend_hue(src, dst);
|
|
case 26:
|
|
return blend_saturation(src, dst);
|
|
case 27:
|
|
return blend_color(src, dst);
|
|
case 28:
|
|
return blend_luminosity(src, dst);
|
|
default:
|
|
return vec4(0.0);
|
|
}
|
|
}
|
|
void main() {
|
|
sk_FragColor = blend(13, src, dst);
|
|
}
|