blob: 5ff0fbef8991472e1978b8cf47eb35ff2013dbc1 [file] [log] [blame]
Ethan Nicholasc18bb512020-07-28 14:46:53 -04001// defines built-in functions supported by SkSL when running on a GPU
2
3$genType radians($genType degrees);
4$genType sin($genType angle);
5$genType cos($genType angle);
6$genType tan($genType angle);
7$genType asin($genType x);
8$genType acos($genType x);
9$genType atan($genType y, $genType x);
10$genType atan($genType y_over_x);
11$genType sinh($genType x);
12$genType cosh($genType x);
13$genType tanh($genType x);
14$genType asinh($genType x);
15$genType acosh($genType x);
16$genType atanh($genType x);
17$genType pow($genType x, $genType y);
18$genType exp($genType x);
19$genType log($genType x);
20$genType exp2($genType x);
21$genType log2($genType x);
22$genType sqrt($genType x);
23$genHType radians($genHType degrees);
24$genHType sin($genHType angle);
25$genHType cos($genHType angle);
26$genHType tan($genHType angle);
27$genHType asin($genHType x);
28$genHType acos($genHType x);
29$genHType atan($genHType y, $genHType x);
30$genHType atan($genHType y_over_x);
31$genHType sinh($genHType x);
32$genHType cosh($genHType x);
33$genHType tanh($genHType x);
34$genHType asinh($genHType x);
35$genHType acosh($genHType x);
36$genHType atanh($genHType x);
37$genHType pow($genHType x, $genHType y);
38$genHType exp($genHType x);
39$genHType log($genHType x);
40$genHType exp2($genHType x);
41$genHType log2($genHType x);
42$genHType sqrt($genHType x);
43$genType inversesqrt($genType x);
44$genType abs($genType x);
45$genHType abs($genHType x);
46$genIType abs($genIType x);
47$genType sign($genType x);
48$genHType sign($genHType x);
49$genIType sign($genIType x);
50$genType floor($genType x);
51$genHType floor($genHType x);
52$genType trunc($genType x);
53$genHType trunc($genHType x);
54$genType round($genType x);
55$genHType round($genHType x);
56$genType roundEven($genType x);
57$genHType roundEven($genHType x);
58$genType ceil($genType x);
59$genHType ceil($genHType x);
60$genType fract($genType x);
61$genHType fract($genHType x);
62$genType mod($genType x, float y);
63$genType mod($genType x, $genType y);
64$genHType mod($genHType x, half y);
65$genHType mod($genHType x, $genHType y);
66$genType modf($genType x, out $genType i);
67$genHType modf($genHType x, out $genHType i);
68$genType min($genType x, $genType y);
69$genType min($genType x, float y);
70$genHType min($genHType x, $genHType y);
71$genHType min($genHType x, half y);
72$genIType min($genIType x, $genIType y);
73$genIType min($genIType x, int y);
74$genType max($genType x, $genType y);
75$genType max($genType x, float y);
76$genHType max($genHType x, $genHType y);
77$genHType max($genHType x, half y);
78$genIType max($genIType x, $genIType y);
79$genIType max($genIType x, int y);
80$genType clamp($genType x, $genType minVal, $genType maxVal);
81$genType clamp($genType x, float minVal, float maxVal);
82$genHType clamp($genHType x, $genHType minVal, $genHType maxVal);
83$genHType clamp($genHType x, half minVal, half maxVal);
84$genIType clamp($genIType x, $genIType minVal, $genIType maxVal);
85$genIType clamp($genIType x, int minVal, int maxVal);
86$genType saturate($genType x);
87$genHType saturate($genHType x);
88$genType mix($genType x, $genType y, $genType a);
89$genType mix($genType x, $genType y, float a);
90$genHType mix($genHType x, $genHType y, $genHType a);
91$genHType mix($genHType x, $genHType y, half a);
92$genType mix($genType x, $genType y, $genBType a);
93$genHType mix($genHType x, $genHType y, $genBType a);
94$genIType mix($genIType x, $genIType y, $genBType a);
95$genBType mix($genBType x, $genBType y, $genBType a);
96$genType step($genType edge, $genType x);
97$genType step(float edge, $genType x);
98$genHType step($genHType edge, $genHType x);
99$genHType step(half edge, $genHType x);
100$genType smoothstep($genType edge0, $genType edge1, $genType x);
101$genType smoothstep(float edge0, float edge1, $genType x);
102$genHType smoothstep($genHType edge0, $genHType edge1, $genHType x);
103$genHType smoothstep(half edge0, half edge1, $genHType x);
104$genBType isnan($genType x);
105$genBType isinf($genType x);
106$genIType floatBitsToInt($genType value);
107$genType intBitsTofloat($genIType value);
108$genType uintBitsTofloat($genUType value);
109$genType fma($genType a, $genType b, $genType c);
110$genHType fma($genHType a, $genHType b, $genHType c);
111sk_has_side_effects $genType frexp($genType x, out $genIType exp);
112$genType ldexp($genType x, in $genIType exp);
113uint packUnorm2x16(float2 v);
114uint packSnorm2x16(float2 v);
115uint packUnorm4x8(float4 v);
116uint packSnorm4x8(float4 v);
117float2 unpackUnorm2x16(uint p);
118float2 unpackSnorm2x16(uint p);
119float4 unpackUnorm4x8(uint p);
120float4 unpackSnorm4x8(uint p);
121uint packHalf2x16(float2 v);
122float2 unpackHalf2x16(uint v);
123float length($genType x);
124half length($genHType x);
125float distance($genType p0, $genType p1);
126half distance($genHType p0, $genHType p1);
127float dot($genType x, $genType y);
128half dot($genHType x, $genHType y);
129float3 cross(float3 x, float3 y);
130half3 cross(half3 x, half3 y);
131$genType normalize($genType x);
132$genHType normalize($genHType x);
133float4 ftransform();
134$genType faceforward($genType N, $genType I, $genType Nref);
135$genHType faceforward($genHType N, $genHType I, $genHType Nref);
136$genType reflect($genType I, $genType N);
137$genHType reflect($genHType I, $genHType N);
138$genType refract($genType I, $genType N, float eta);
139$genHType refract($genHType I, $genHType N, float eta);
140$mat matrixCompMult($mat x, $mat y);
141float2x2 outerProduct(float2 c, float2 r);
142float3x3 outerProduct(float3 c, float3 r);
143float4x3 outerProduct(float4 c, float4 r);
144float2x3 outerProduct(float3 c, float2 r);
145float3x2 outerProduct(float2 c, float3 r);
146float2x4 outerProduct(float4 c, float2 r);
147float4x2 outerProduct(float2 c, float4 r);
148float3x4 outerProduct(float4 c, float3 r);
149float4x3 outerProduct(float3 c, float4 r);
150half2x2 outerProduct(half2 c, half2 r);
151half3x3 outerProduct(half3 c, half3 r);
152half4x3 outerProduct(half4 c, half4 r);
153half2x3 outerProduct(half3 c, half2 r);
154half3x2 outerProduct(half2 c, half3 r);
155half2x4 outerProduct(half4 c, half2 r);
156half4x2 outerProduct(half2 c, half4 r);
157half3x4 outerProduct(half4 c, half3 r);
158half4x3 outerProduct(half3 c, half4 r);
159float2x2 transpose(float2x2 m);
160float3x3 transpose(float3x3 m);
161float4x4 transpose(float4x4 m);
162float2x3 transpose(float3x2 m);
163float3x2 transpose(float2x3 m);
164float2x4 transpose(float4x2 m);
165float4x2 transpose(float2x4 m);
166float3x4 transpose(float4x3 m);
167float4x3 transpose(float3x4 m);
168half2x2 transpose(half2x2 m);
169half3x3 transpose(half3x3 m);
170half4x4 transpose(half4x4 m);
171half2x3 transpose(half3x2 m);
172half3x2 transpose(half2x3 m);
173half2x4 transpose(half4x2 m);
174half4x2 transpose(half2x4 m);
175half3x4 transpose(half4x3 m);
176half4x3 transpose(half3x4 m);
177float determinant(float2x2 m);
178float determinant(float3x3 m);
179float determinant(float4x4 m);
180half determinant(half2x2 m);
181half determinant(half3x3 m);
182half determinant(half4x4 m);
183float2x2 inverse(float2x2 m);
184float3x3 inverse(float3x3 m);
185float4x4 inverse(float4x4 m);
186half2x2 inverse(half2x2 m);
187half3x3 inverse(half3x3 m);
188half4x4 inverse(half4x4 m);
189$bvec lessThan($vec x, $vec y);
190$bvec lessThan($hvec x, $hvec y);
191$bvec lessThan($ivec x, $ivec y);
192$bvec lessThan($svec x, $svec y);
193$bvec lessThan($usvec x, $usvec y);
194$bvec lessThan($uvec x, $uvec y);
195$bvec lessThanEqual($vec x, $vec y);
196$bvec lessThanEqual($hvec x, $hvec y);
197$bvec lessThanEqual($ivec x, $ivec y);
198$bvec lessThanEqual($uvec x, $uvec y);
199$bvec lessThanEqual($svec x, $svec y);
200$bvec lessThanEqual($usvec x, $usvec y);
201$bvec greaterThan($vec x, $vec y);
202$bvec greaterThan($hvec x, $hvec y);
203$bvec greaterThan($ivec x, $ivec y);
204$bvec greaterThan($uvec x, $uvec y);
205$bvec greaterThan($svec x, $svec y);
206$bvec greaterThan($usvec x, $usvec y);
207$bvec greaterThanEqual($vec x, $vec y);
208$bvec greaterThanEqual($hvec x, $hvec y);
209$bvec greaterThanEqual($ivec x, $ivec y);
210$bvec greaterThanEqual($uvec x, $uvec y);
211$bvec greaterThanEqual($svec x, $svec y);
212$bvec greaterThanEqual($usvec x, $usvec y);
213$bvec equal($vec x, $vec y);
214$bvec equal($hvec x, $hvec y);
215$bvec equal($ivec x, $ivec y);
216$bvec equal($uvec x, $uvec y);
217$bvec equal($svec x, $svec y);
218$bvec equal($usvec x, $usvec y);
219$bvec equal($bvec x, $bvec y);
220$bvec notEqual($vec x, $vec y);
221$bvec notEqual($hvec x, $hvec y);
222$bvec notEqual($ivec x, $ivec y);
223$bvec notEqual($uvec x, $uvec y);
224$bvec notEqual($svec x, $svec y);
225$bvec notEqual($usvec x, $usvec y);
226$bvec notEqual($bvec x, $bvec y);
227bool any($bvec x);
228bool all($bvec x);
229$bvec not($bvec x);
230
231$genIType bitCount($genIType value);
232$genIType bitCount($genUType value);
233$genIType findLSB($genIType value);
234$genIType findLSB($genUType value);
235$genIType findMSB($genIType value);
236$genIType findMSB($genUType value);
237
238sampler2D makeSampler2D(texture2D texture, sampler sampler);
239int2 textureSize($gsampler2DRect sampler);
240
241half4 sample($gsampler1D sampler, float P);
242half4 sample($gsampler1D sampler, float P, float bias);
243half4 sample($gsampler2D sampler, float2 P);
244// The above currently only expand to handle the float/fixed case. So we also declare this integer
245// version of sample().
246int4 sample(isampler2D sampler, float2 P);
247half4 sample(samplerExternalOES sampler, float2 P, float bias);
248half4 sample(samplerExternalOES sampler, float2 P);
249
250half4 sample($gsampler2DRect sampler, float2 P);
251half4 sample($gsampler2DRect sampler, float3 P);
252
253// Currently we do not support the generic types of loading subpassInput so we have some explicit
254// versions that we currently use
Greg Danielcf1a4f52020-09-08 15:25:23 -0400255half4 subpassLoad(subpassInput subpass);
256half4 subpassLoad(subpassInputMS subpass, int sample);
Ethan Nicholasc18bb512020-07-28 14:46:53 -0400257
258half4 sample($gsampler1D sampler, float2 P);
259half4 sample($gsampler1D sampler, float2 P, float bias);
260half4 sample($gsampler2D sampler, float3 P);
261half4 sample($gsampler2D sampler, float3 P, float bias);
262
263float4 imageLoad(image2D image, int2 P);
264int4 imageLoad(iimage2D image, int2 P);
265$genType dFdx($genType p);
266$genType dFdy($genType p);
267$genHType dFdx($genHType p);
268$genHType dFdy($genHType p);
269$genType fwidth($genType p);
270$genHType fwidth($genHType p);
271float interpolateAtSample(float interpolant, int sample);
272float2 interpolateAtSample(float2 interpolant, int sample);
273float3 interpolateAtSample(float3 interpolant, int sample);
274float4 interpolateAtSample(float4 interpolant, int sample);
275float interpolateAtOffset(float interpolant, float2 offset);
276float2 interpolateAtOffset(float2 interpolant, float2 offset);
277float3 interpolateAtOffset(float3 interpolant, float2 offset);
278float4 interpolateAtOffset(float4 interpolant, float2 offset);
279
280// Definitions of functions implementing all of the SkBlendMode blends.
281
282half4 blend_clear(half4 src, half4 dst) { return half4(0); }
283
284half4 blend_src(half4 src, half4 dst) { return src; }
285
286half4 blend_dst(half4 src, half4 dst) { return dst; }
287
288half4 blend_src_over(half4 src, half4 dst) { return src + (1 - src.a)*dst; }
289
290half4 blend_dst_over(half4 src, half4 dst) { return (1 - dst.a)*src + dst; }
291
292half4 blend_src_in(half4 src, half4 dst) {
293 @if (sk_Caps.inBlendModesFailRandomlyForAllZeroVec) {
294 if (src == half4(0)) {
295 return half4(0);
296 }
297 }
298 return src*dst.a;
299}
300
301half4 blend_dst_in(half4 src, half4 dst) { return blend_src_in(dst, src); }
302
303half4 blend_src_out(half4 src, half4 dst) { return (1 - dst.a)*src; }
304
305half4 blend_dst_out(half4 src, half4 dst) { return (1 - src.a)*dst; }
306
307half4 blend_src_atop(half4 src, half4 dst) { return dst.a*src + (1 - src.a)*dst; }
308
309half4 blend_dst_atop(half4 src, half4 dst) { return (1 - dst.a) * src + src.a*dst; }
310
311half4 blend_xor(half4 src, half4 dst) { return (1 - dst.a)*src + (1 - src.a)*dst; }
312
313half4 blend_plus(half4 src, half4 dst) { return min(src + dst, 1); }
314
315half4 blend_modulate(half4 src, half4 dst) { return src*dst; }
316
317half4 blend_screen(half4 src, half4 dst) { return src + (1 - src)*dst; }
318
319half _blend_overlay_component(half sc, half sa, half dc, half da) {
320 if (2*dc <= da) {
321 return 2*sc*dc;
322 }
323 return sa*da - 2*(da - dc)*(sa - sc);
324}
325
326half4 blend_overlay(half4 src, half4 dst) {
327 half4 result = half4(_blend_overlay_component(src.r, src.a, dst.r, dst.a),
328 _blend_overlay_component(src.g, src.a, dst.g, dst.a),
329 _blend_overlay_component(src.b, src.a, dst.b, dst.a),
330 src.a + (1 - src.a)*dst.a);
331 result.rgb += dst.rgb*(1 - src.a) + src.rgb*(1 - dst.a);
332 return result;
333}
334
335half4 blend_darken(half4 src, half4 dst) {
336 half4 result = blend_src_over(src, dst);
337 result.rgb = min(result.rgb, (1 - dst.a)*src.rgb + dst.rgb);
338 return result;
339}
340
341half4 blend_lighten(half4 src, half4 dst) {
342 half4 result = blend_src_over(src, dst);
343 result.rgb = max(result.rgb, (1 - dst.a)*src.rgb + dst.rgb);
344 return result;
345}
346
347half _guarded_divide(half n, half d) {
348 @if (sk_Caps.mustGuardDivisionEvenAfterExplicitZeroCheck) {
349 return n/(d + 0.00000001);
350 } else {
351 return n/d;
352 }
353}
354
355half _color_dodge_component(half sc, half sa, half dc, half da) {
356 if (dc == 0) {
357 return sc*(1 - da);
358 } else {
359 half d = sa - sc;
360 if (d == 0) {
361 return sa*da + sc*(1 - da) + dc*(1 - sa);
362 }
363 d = min(da, _guarded_divide(dc*sa, d));
364 return d*sa + sc*(1 - da) + dc*(1 - sa);
365 }
366}
367
368half4 blend_color_dodge(half4 src, half4 dst) {
369 return half4(_color_dodge_component(src.r, src.a, dst.r, dst.a),
370 _color_dodge_component(src.g, src.a, dst.g, dst.a),
371 _color_dodge_component(src.b, src.a, dst.b, dst.a),
372 src.a + (1 - src.a)*dst.a);
373}
374
375half _color_burn_component(half sc, half sa, half dc, half da) {
376 if (da == dc) {
377 return sa*da + sc*(1 - da) + dc*(1 - sa);
378 } else if (sc == 0) {
379 return dc*(1 - sa);
380 }
381 half d = max(0, da - _guarded_divide((da - dc)*sa, sc));
382 return d*sa + sc*(1 - da) + dc*(1 - sa);
383}
384
385half4 blend_color_burn(half4 src, half4 dst) {
386 return half4(_color_burn_component(src.r, src.a, dst.r, dst.a),
387 _color_burn_component(src.g, src.a, dst.g, dst.a),
388 _color_burn_component(src.b, src.a, dst.b, dst.a),
389 src.a + (1 - src.a)*dst.a);
390}
391
392half4 blend_hard_light(half4 src, half4 dst) { return blend_overlay(dst, src); }
393
394half _soft_light_component(half sc, half sa, half dc, half da) {
395 if (2*sc <= sa) {
396 return _guarded_divide(dc*dc*(sa - 2*sc), da) + (1 - da)*sc + dc*(-sa + 2*sc + 1);
397 } else if (4.0 * dc <= da) {
398 half DSqd = dc*dc;
399 half DCub = DSqd*dc;
400 half DaSqd = da*da;
401 half DaCub = DaSqd*da;
402 return _guarded_divide(DaSqd*(sc - dc*(3*sa - 6*sc - 1)) + 12*da*DSqd*(sa - 2*sc)
403 - 16*DCub * (sa - 2*sc) - DaCub*sc, DaSqd);
404 }
405 return dc*(sa - 2*sc + 1) + sc - sqrt(da*dc)*(sa - 2*sc) - da*sc;
406}
407
408half4 blend_soft_light(half4 src, half4 dst) {
409 if (dst.a == 0) {
410 return src;
411 }
412 return half4(_soft_light_component(src.r, src.a, dst.r, dst.a),
413 _soft_light_component(src.g, src.a, dst.g, dst.a),
414 _soft_light_component(src.b, src.a, dst.b, dst.a),
415 src.a + (1 - src.a)*dst.a);
416}
417
418half4 blend_difference(half4 src, half4 dst) {
419 return half4(src.rgb + dst.rgb - 2*min(src.rgb*dst.a, dst.rgb*src.a),
420 src.a + (1 - src.a)*dst.a);
421}
422
423half4 blend_exclusion(half4 src, half4 dst) {
424 return half4(dst.rgb + src.rgb - 2*dst.rgb*src.rgb, src.a + (1 - src.a)*dst.a);
425}
426
427half4 blend_multiply(half4 src, half4 dst) {
428 return half4((1 - src.a)*dst.rgb + (1 - dst.a)*src.rgb + src.rgb*dst.rgb,
429 src.a + (1 - src.a)*dst.a);
430}
431
432half _blend_color_luminance(half3 color) { return dot(half3(0.3, 0.59, 0.11), color); }
433
434half3 _blend_set_color_luminance(half3 hueSatColor, half alpha, half3 lumColor) {
435 half lum = _blend_color_luminance(lumColor);
436 half3 result = lum - _blend_color_luminance(hueSatColor) + hueSatColor;
437 half minComp = min(min(result.r, result.g), result.b);
438 half maxComp = max(max(result.r, result.g), result.b);
439 if (minComp < 0 && lum != minComp) {
440 result = lum + (result - lum) * lum/(lum - minComp);
441 }
442 if (maxComp > alpha && maxComp != lum) {
443 return lum + ((result - lum) * (alpha - lum))/(maxComp - lum);
444 }
445 return result;
446}
447
448half _blend_color_saturation(half3 color) {
449 return max(max(color.r, color.g), color.b) - min(min(color.r, color.g), color.b);
450}
451
452half3 _blend_set_color_saturation_helper(half3 minMidMax, half sat) {
453 if (minMidMax.r < minMidMax.b) {
454 return half3(0, sat*(minMidMax.g - minMidMax.r)/(minMidMax.b - minMidMax.r), sat);
455 }
456 return half3(0);
457}
458
459half3 _blend_set_color_saturation(half3 hueLumColor, half3 satColor) {
460 half sat = _blend_color_saturation(satColor);
461 if (hueLumColor.r <= hueLumColor.g) {
462 if (hueLumColor.g <= hueLumColor.b) {
463 hueLumColor.rgb = _blend_set_color_saturation_helper(hueLumColor.rgb, sat);
464 } else if (hueLumColor.r <= hueLumColor.b) {
465 hueLumColor.rbg = _blend_set_color_saturation_helper(hueLumColor.rbg, sat);
466 } else {
467 hueLumColor.brg = _blend_set_color_saturation_helper(hueLumColor.brg, sat);
468 }
469 } else if (hueLumColor.r <= hueLumColor.b) {
470 hueLumColor.grb = _blend_set_color_saturation_helper(hueLumColor.grb, sat);
471 } else if (hueLumColor.g <= hueLumColor.b) {
472 hueLumColor.gbr = _blend_set_color_saturation_helper(hueLumColor.gbr, sat);
473 } else {
474 hueLumColor.bgr = _blend_set_color_saturation_helper(hueLumColor.bgr, sat);
475 }
476 return hueLumColor;
477}
478
479half4 blend_hue(half4 src, half4 dst) {
480 half alpha = dst.a*src.a;
481 half3 sda = src.rgb*dst.a;
482 half3 dsa = dst.rgb*src.a;
483 return half4(_blend_set_color_luminance(_blend_set_color_saturation(sda, dsa), alpha, dsa) +
484 dst.rgb - dsa + src.rgb - sda,
485 src.a + dst.a - alpha);
486}
487
488half4 blend_saturation(half4 src, half4 dst) {
489 half alpha = dst.a*src.a;
490 half3 sda = src.rgb*dst.a;
491 half3 dsa = dst.rgb*src.a;
492 return half4(_blend_set_color_luminance(_blend_set_color_saturation(dsa, sda), alpha, dsa) +
493 dst.rgb - dsa + src.rgb - sda,
494 src.a + dst.a - alpha);
495}
496
497half4 blend_color(half4 src, half4 dst) {
498 half alpha = dst.a*src.a;
499 half3 sda = src.rgb*dst.a;
500 half3 dsa = dst.rgb*src.a;
501 return half4(_blend_set_color_luminance(sda, alpha, dsa) + dst.rgb - dsa + src.rgb - sda,
502 src.a + dst.a - alpha);
503}
504
505half4 blend_luminosity(half4 src, half4 dst) {
506 half alpha = dst.a*src.a;
507 half3 sda = src.rgb*dst.a;
508 half3 dsa = dst.rgb*src.a;
509 return half4(_blend_set_color_luminance(dsa, alpha, sda) + dst.rgb - dsa + src.rgb - sda,
510 src.a + dst.a - alpha);
511
512}
513
514enum class SkBlendMode {
515 kClear = 0,
516 kSrc = 1,
517 kDst = 2,
518 kSrcOver = 3,
519 kDstOver = 4,
520 kSrcIn = 5,
521 kDstIn = 6,
522 kSrcOut = 7,
523 kDstOut = 8,
524 kSrcATop = 9,
525 kDstATop = 10,
526 kXor = 11,
527 kPlus = 12,
528 kModulate = 13,
529 kScreen = 14,
530 kOverlay = 15,
531 kDarken = 16,
532 kLighten = 17,
533 kColorDodge = 18,
534 kColorBurn = 19,
535 kHardLight = 20,
536 kSoftLight = 21,
537 kDifference = 22,
538 kExclusion = 23,
539 kMultiply = 24,
540 kHue = 25,
541 kSaturation = 26,
542 kColor = 27,
543 kLuminosity = 28
544};
545
546half4 blend(SkBlendMode mode, half4 src, half4 dst) {
547 switch (mode) {
548 case SkBlendMode::kClear: return blend_clear(src, dst);
549 case SkBlendMode::kSrc: return blend_src(src, dst);
550 case SkBlendMode::kDst: return blend_dst(src, dst);
551 case SkBlendMode::kSrcOver: return blend_src_over(src, dst);
552 case SkBlendMode::kDstOver: return blend_dst_over(src, dst);
553 case SkBlendMode::kSrcIn: return blend_src_in(src, dst);
554 case SkBlendMode::kDstIn: return blend_dst_in(src, dst);
555 case SkBlendMode::kSrcOut: return blend_src_out(src, dst);
556 case SkBlendMode::kDstOut: return blend_dst_out(src, dst);
557 case SkBlendMode::kSrcATop: return blend_src_atop(src, dst);
558 case SkBlendMode::kDstATop: return blend_dst_atop(src, dst);
559 case SkBlendMode::kXor: return blend_xor(src, dst);
560 case SkBlendMode::kPlus: return blend_plus(src, dst);
561 case SkBlendMode::kModulate: return blend_modulate(src, dst);
562 case SkBlendMode::kScreen: return blend_screen(src, dst);
563 case SkBlendMode::kOverlay: return blend_overlay(src, dst);
564 case SkBlendMode::kDarken: return blend_darken(src, dst);
565 case SkBlendMode::kLighten: return blend_lighten(src, dst);
566 case SkBlendMode::kColorDodge: return blend_color_dodge(src, dst);
567 case SkBlendMode::kColorBurn: return blend_color_burn(src, dst);
568 case SkBlendMode::kHardLight: return blend_hard_light(src, dst);
569 case SkBlendMode::kSoftLight: return blend_soft_light(src, dst);
570 case SkBlendMode::kDifference: return blend_difference(src, dst);
571 case SkBlendMode::kExclusion: return blend_exclusion(src, dst);
572 case SkBlendMode::kMultiply: return blend_multiply(src, dst);
573 case SkBlendMode::kHue: return blend_hue(src, dst);
574 case SkBlendMode::kSaturation: return blend_saturation(src, dst);
575 case SkBlendMode::kColor: return blend_color(src, dst);
576 case SkBlendMode::kLuminosity: return blend_luminosity(src, dst);
577 }
578 return half4(0); // Avoids "'blend' can exit without returning a value."
579}
580
581// The max() guards against division by zero when the incoming color is transparent black
582half4 unpremul(half4 color) { return half4(color.rgb / max(color.a, 0.0001), color.a); }
583float4 unpremul_float(float4 color) { return float4(color.rgb / max(color.a, 0.0001), color.a); }
584
585float2 proj(float3 p) { return p.xy / p.z; }