Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/gpu/gl/GrGLBlend.cpp

Issue 1254833003: Added GrGLBlend.h|cpp with helper function AppendPorterDuffBlend() in preparation for SkComposeShad… (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: More nits by Greg Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLBlend.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 SkAssertResult(append_porterduff_term(fsBuilder, dstCoeff, dstColor, srcColo r, dstColor,
67 didAppend));
68 fsBuilder->codeAppend(";");
69 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLBlend.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698