OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 #include "GrGLBlend.h" | |
8 #include "gl/builders/GrGLFragmentShaderBuilder.h" | |
9 | |
10 static bool append_porterduff_term(GrGLFragmentBuilder* fsBuilder, SkXfermode::C
oeff coeff, | |
11 const char* colorName, const char* srcColorNa
me, | |
12 const char* dstColorName, bool hasPrevious) { | |
13 if (SkXfermode::kZero_Coeff == coeff) { | |
14 return hasPrevious; | |
15 } else { | |
16 if (hasPrevious) { | |
17 fsBuilder->codeAppend(" + "); | |
18 } | |
19 fsBuilder->codeAppendf("%s", colorName); | |
20 switch (coeff) { | |
21 case SkXfermode::kOne_Coeff: | |
22 break; | |
23 case SkXfermode::kSC_Coeff: | |
24 fsBuilder->codeAppendf(" * %s", srcColorName); | |
25 break; | |
26 case SkXfermode::kISC_Coeff: | |
27 fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", srcColorName); | |
28 break; | |
29 case SkXfermode::kDC_Coeff: | |
30 fsBuilder->codeAppendf(" * %s", dstColorName); | |
31 break; | |
32 case SkXfermode::kIDC_Coeff: | |
33 fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", dstColorName); | |
34 break; | |
35 case SkXfermode::kSA_Coeff: | |
36 fsBuilder->codeAppendf(" * %s.a", srcColorName); | |
37 break; | |
38 case SkXfermode::kISA_Coeff: | |
39 fsBuilder->codeAppendf(" * (1.0 - %s.a)", srcColorName); | |
40 break; | |
41 case SkXfermode::kDA_Coeff: | |
42 fsBuilder->codeAppendf(" * %s.a", dstColorName); | |
43 break; | |
44 case SkXfermode::kIDA_Coeff: | |
45 fsBuilder->codeAppendf(" * (1.0 - %s.a)", dstColorName); | |
46 break; | |
47 default: | |
48 SkFAIL("Unsupported Blend Coeff"); | |
49 } | |
50 return true; | |
51 } | |
52 } | |
53 | |
54 void GrGLBlend::AppendPorterDuffBlend(GrGLFragmentBuilder* fsBuilder, const char
* srcColor, | |
55 const char* dstColor, const char* outColor
, | |
56 SkXfermode::Mode mode) { | |
57 | |
58 SkXfermode::Coeff srcCoeff, dstCoeff; | |
59 SkXfermode::ModeAsCoeff(mode, &srcCoeff, &dstCoeff); | |
60 | |
61 fsBuilder->codeAppendf("%s = ", outColor); | |
62 // append src blend | |
63 bool didAppend = append_porterduff_term(fsBuilder, srcCoeff, srcColor, srcCo
lor, dstColor, | |
64 false); | |
65 // append dst blend | |
66 if(!append_porterduff_term(fsBuilder, dstCoeff, dstColor, srcColor, dstColor
, didAppend)) { | |
67 fsBuilder->codeAppend("vec4(0, 0, 0, 0)"); | |
68 } | |
69 fsBuilder->codeAppend(";"); | |
70 } | |
OLD | NEW |