Lines Matching refs:fsBuilder
14 static void hard_light(GrGLSLFragmentBuilder* fsBuilder,
21 fsBuilder->codeAppendf("if (2.0 * %s.%c <= %s.a) {", src, component, src);
22 fsBuilder->codeAppendf("%s.%c = 2.0 * %s.%c * %s.%c;",
24 fsBuilder->codeAppend("} else {");
25 fsBuilder->codeAppendf("%s.%c = %s.a * %s.a - 2.0 * (%s.a - %s.%c) * (%s.a - %s.%c);",
28 fsBuilder->codeAppend("}");
30 fsBuilder->codeAppendf("%s.rgb += %s.rgb * (1.0 - %s.a) + %s.rgb * (1.0 - %s.a);",
35 static void color_dodge_component(GrGLSLFragmentBuilder* fsBuilder,
40 fsBuilder->codeAppendf("if (0.0 == %s.%c) {", dst, component);
41 fsBuilder->codeAppendf("%s.%c = %s.%c * (1.0 - %s.a);",
43 fsBuilder->codeAppend("} else {");
44 fsBuilder->codeAppendf("float d = %s.a - %s.%c;", src, src, component);
45 fsBuilder->codeAppend("if (0.0 == d) {");
46 fsBuilder->codeAppendf("%s.%c = %s.a * %s.a + %s.%c * (1.0 - %s.a) + %s.%c * (1.0 - %s.a);",
49 fsBuilder->codeAppend("} else {");
50 fsBuilder->codeAppendf("d = min(%s.a, %s.%c * %s.a / d);",
52 fsBuilder->codeAppendf("%s.%c = d * %s.a + %s.%c * (1.0 - %s.a) + %s.%c * (1.0 - %s.a);",
54 fsBuilder->codeAppend("}");
55 fsBuilder->codeAppend("}");
59 static void color_burn_component(GrGLSLFragmentBuilder* fsBuilder,
64 fsBuilder->codeAppendf("if (%s.a == %s.%c) {", dst, dst, component);
65 fsBuilder->codeAppendf("%s.%c = %s.a * %s.a + %s.%c * (1.0 - %s.a) + %s.%c * (1.0 - %s.a);",
68 fsBuilder->codeAppendf("} else if (0.0 == %s.%c) {", src, component);
69 fsBuilder->codeAppendf("%s.%c = %s.%c * (1.0 - %s.a);",
71 fsBuilder->codeAppend("} else {");
72 fsBuilder->codeAppendf("float d = max(0.0, %s.a - (%s.a - %s.%c) * %s.a / %s.%c);",
74 fsBuilder->codeAppendf("%s.%c = %s.a * d + %s.%c * (1.0 - %s.a) + %s.%c * (1.0 - %s.a);",
76 fsBuilder->codeAppend("}");
80 static void soft_light_component_pos_dst_alpha(GrGLSLFragmentBuilder* fsBuilder,
86 fsBuilder->codeAppendf("if (2.0 * %s.%c <= %s.a) {", src, component, src);
88 fsBuilder->codeAppendf("%s.%c = (%s.%c*%s.%c*(%s.a - 2.0*%s.%c)) / %s.a +"
94 fsBuilder->codeAppendf("} else if (4.0 * %s.%c <= %s.a) {",
96 fsBuilder->codeAppendf("float DSqd = %s.%c * %s.%c;",
98 fsBuilder->codeAppendf("float DCub = DSqd * %s.%c;", dst, component);
99 fsBuilder->codeAppendf("float DaSqd = %s.a * %s.a;", dst, dst);
100 fsBuilder->codeAppendf("float DaCub = DaSqd * %s.a;", dst);
102 fsBuilder->codeAppendf("%s.%c ="
109 fsBuilder->codeAppendf("} else {");
111 fsBuilder->codeAppendf("%s.%c = %s.%c*(%s.a - 2.0*%s.%c + 1.0) + %s.%c -"
115 fsBuilder->codeAppendf("}");
122 static void add_lum_function(GrGLSLFragmentBuilder* fsBuilder, SkString* setLumFunction) {
129 fsBuilder->emitFunction(kFloat_GrSLType,
157 fsBuilder->emitFunction(kVec3f_GrSLType,
167 static void add_sat_function(GrGLSLFragmentBuilder* fsBuilder, SkString* setSatFunction) {
174 fsBuilder->emitFunction(kFloat_GrSLType,
200 fsBuilder->emitFunction(kVec3f_GrSLType,
231 fsBuilder->emitFunction(kVec3f_GrSLType,
238 static void emit_advanced_xfermode_code(GrGLSLFragmentBuilder* fsBuilder, const char* srcColor,
245 fsBuilder->codeAppendf("%s.a = %s.a + (1.0 - %s.a) * %s.a;",
251 hard_light(fsBuilder, outputColor, dstColor, srcColor);
254 fsBuilder->codeAppendf("%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, "
261 fsBuilder->codeAppendf("%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, "
268 color_dodge_component(fsBuilder, outputColor, srcColor, dstColor, 'r');
269 color_dodge_component(fsBuilder, outputColor, srcColor, dstColor, 'g');
270 color_dodge_component(fsBuilder, outputColor, srcColor, dstColor, 'b');
273 color_burn_component(fsBuilder, outputColor, srcColor, dstColor, 'r');
274 color_burn_component(fsBuilder, outputColor, srcColor, dstColor, 'g');
275 color_burn_component(fsBuilder, outputColor, srcColor, dstColor, 'b');
278 hard_light(fsBuilder, outputColor, srcColor, dstColor);
281 fsBuilder->codeAppendf("if (0.0 == %s.a) {", dstColor);
282 fsBuilder->codeAppendf("%s.rgba = %s;", outputColor, srcColor);
283 fsBuilder->codeAppendf("} else {");
284 soft_light_component_pos_dst_alpha(fsBuilder, outputColor, srcColor, dstColor, 'r');
285 soft_light_component_pos_dst_alpha(fsBuilder, outputColor, srcColor, dstColor, 'g');
286 soft_light_component_pos_dst_alpha(fsBuilder, outputColor, srcColor, dstColor, 'b');
287 fsBuilder->codeAppendf("}");
290 fsBuilder->codeAppendf("%s.rgb = %s.rgb + %s.rgb -"
296 fsBuilder->codeAppendf("%s.rgb = %s.rgb + %s.rgb - "
301 fsBuilder->codeAppendf("%s.rgb = (1.0 - %s.a) * %s.rgb + "
310 add_sat_function(fsBuilder, &setSat);
311 add_lum_function(fsBuilder, &setLum);
312 fsBuilder->codeAppendf("vec4 dstSrcAlpha = %s * %s.a;",
314 fsBuilder->codeAppendf("%s.rgb = %s(%s(%s.rgb * %s.a, dstSrcAlpha.rgb),"
318 fsBuilder->codeAppendf("%s.rgb += (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rgb;",
325 add_sat_function(fsBuilder, &setSat);
326 add_lum_function(fsBuilder, &setLum);
327 fsBuilder->codeAppendf("vec4 dstSrcAlpha = %s * %s.a;",
329 fsBuilder->codeAppendf("%s.rgb = %s(%s(dstSrcAlpha.rgb, %s.rgb * %s.a),"
333 fsBuilder->codeAppendf("%s.rgb += (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rgb;",
340 add_lum_function(fsBuilder, &setLum);
341 fsBuilder->codeAppendf("vec4 srcDstAlpha = %s * %s.a;",
343 fsBuilder->codeAppendf("%s.rgb = %s(srcDstAlpha.rgb, srcDstAlpha.a, %s.rgb * %s.a);",
345 fsBuilder->codeAppendf("%s.rgb += (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rgb;",
352 add_lum_function(fsBuilder, &setLum);
353 fsBuilder->codeAppendf("vec4 srcDstAlpha = %s * %s.a;",
355 fsBuilder->codeAppendf("%s.rgb = %s(%s.rgb * %s.a, srcDstAlpha.a, srcDstAlpha.rgb);",
357 fsBuilder->codeAppendf("%s.rgb += (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rgb;",
371 static bool append_porterduff_term(GrGLSLFragmentBuilder* fsBuilder, SkXfermode::Coeff coeff,
378 fsBuilder->codeAppend(" + ");
380 fsBuilder->codeAppendf("%s", colorName);
385 fsBuilder->codeAppendf(" * %s", srcColorName);
388 fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", srcColorName);
391 fsBuilder->codeAppendf(" * %s", dstColorName);
394 fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", dstColorName);
397 fsBuilder->codeAppendf(" * %s.a", srcColorName);
400 fsBuilder->codeAppendf(" * (1.0 - %s.a)", srcColorName);
403 fsBuilder->codeAppendf(" * %s.a", dstColorName);
406 fsBuilder->codeAppendf(" * (1.0 - %s.a)", dstColorName);
417 void GrGLSLBlend::AppendMode(GrGLSLFragmentBuilder* fsBuilder, const char* srcColor,
423 fsBuilder->codeAppendf("%s = ", outColor);
425 bool didAppend = append_porterduff_term(fsBuilder, srcCoeff, srcColor, srcColor, dstColor,
428 if(!append_porterduff_term(fsBuilder, dstCoeff, dstColor, srcColor, dstColor, didAppend)) {
429 fsBuilder->codeAppend("vec4(0, 0, 0, 0)");
431 fsBuilder->codeAppend(";");
433 emit_advanced_xfermode_code(fsBuilder, srcColor, dstColor, outColor, mode);
437 void GrGLSLBlend::AppendRegionOp(GrGLSLFragmentBuilder* fsBuilder, const char* srcColor,
472 fsBuilder->codeAppendf("%s = ", outColor);
474 bool didAppend = append_porterduff_term(fsBuilder, srcCoeff, srcColor, srcColor, dstColor,
477 if(!append_porterduff_term(fsBuilder, dstCoeff, dstColor, srcColor, dstColor, didAppend)) {
478 fsBuilder->codeAppend("vec4(0, 0, 0, 0)");
480 fsBuilder->codeAppend(";");