OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "effects/GrXfermodeFragmentProcessor.h" | 8 #include "effects/GrXfermodeFragmentProcessor.h" |
9 | 9 |
10 #include "GrFragmentProcessor.h" | 10 #include "GrFragmentProcessor.h" |
11 #include "effects/GrConstColorProcessor.h" | 11 #include "effects/GrConstColorProcessor.h" |
12 #include "gl/GrGLFragmentProcessor.h" | 12 #include "gl/GrGLFragmentProcessor.h" |
13 #include "gl/GrGLSLBlend.h" | 13 #include "gl/GrGLSLBlend.h" |
14 #include "gl/builders/GrGLProgramBuilder.h" | 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 15 #include "glsl/GrGLSLProgramBuilder.h" |
15 #include "SkGrPriv.h" | 16 #include "SkGrPriv.h" |
16 | 17 |
17 class ComposeTwoFragmentProcessor : public GrFragmentProcessor { | 18 class ComposeTwoFragmentProcessor : public GrFragmentProcessor { |
18 public: | 19 public: |
19 ComposeTwoFragmentProcessor(const GrFragmentProcessor* src, const GrFragment
Processor* dst, | 20 ComposeTwoFragmentProcessor(const GrFragmentProcessor* src, const GrFragment
Processor* dst, |
20 SkXfermode::Mode mode) | 21 SkXfermode::Mode mode) |
21 : fMode(mode) { | 22 : fMode(mode) { |
22 this->initClassID<ComposeTwoFragmentProcessor>(); | 23 this->initClassID<ComposeTwoFragmentProcessor>(); |
23 SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(src); | 24 SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(src); |
24 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(dst); | 25 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(dst); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 82 } |
82 | 83 |
83 GrGLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLInstance() const{ | 84 GrGLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLInstance() const{ |
84 return new GLComposeTwoFragmentProcessor(*this); | 85 return new GLComposeTwoFragmentProcessor(*this); |
85 } | 86 } |
86 | 87 |
87 ///////////////////////////////////////////////////////////////////// | 88 ///////////////////////////////////////////////////////////////////// |
88 | 89 |
89 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { | 90 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { |
90 | 91 |
91 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 92 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
92 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc
essor>(); | 93 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc
essor>(); |
93 | 94 |
94 const char* inputColor = nullptr; | 95 const char* inputColor = nullptr; |
95 if (args.fInputColor) { | 96 if (args.fInputColor) { |
96 inputColor = "inputColor"; | 97 inputColor = "inputColor"; |
97 fsBuilder->codeAppendf("vec4 inputColor = vec4(%s.rgb, 1.0);", args.fInp
utColor); | 98 fsBuilder->codeAppendf("vec4 inputColor = vec4(%s.rgb, 1.0);", args.fInp
utColor); |
98 } | 99 } |
99 | 100 |
100 // declare outputColor and emit the code for each of the two children | 101 // declare outputColor and emit the code for each of the two children |
101 SkString srcColor("src"); | 102 SkString srcColor("src"); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 typedef GrFragmentProcessor INHERITED; | 212 typedef GrFragmentProcessor INHERITED; |
212 }; | 213 }; |
213 | 214 |
214 ////////////////////////////////////////////////////////////////////////////// | 215 ////////////////////////////////////////////////////////////////////////////// |
215 | 216 |
216 class GLComposeOneFragmentProcessor : public GrGLFragmentProcessor { | 217 class GLComposeOneFragmentProcessor : public GrGLFragmentProcessor { |
217 public: | 218 public: |
218 GLComposeOneFragmentProcessor(const GrProcessor& processor) {} | 219 GLComposeOneFragmentProcessor(const GrProcessor& processor) {} |
219 | 220 |
220 void emitCode(EmitArgs& args) override { | 221 void emitCode(EmitArgs& args) override { |
221 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); | 222 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild
er(); |
222 SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mod
e(); | 223 SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mod
e(); |
223 ComposeOneFragmentProcessor::Child child = | 224 ComposeOneFragmentProcessor::Child child = |
224 args.fFp.cast<ComposeOneFragmentProcessor>().child(); | 225 args.fFp.cast<ComposeOneFragmentProcessor>().child(); |
225 SkString childColor("child"); | 226 SkString childColor("child"); |
226 this->emitChild(0, nullptr, &childColor, args); | 227 this->emitChild(0, nullptr, &childColor, args); |
227 | 228 |
228 const char* inputColor = args.fInputColor; | 229 const char* inputColor = args.fInputColor; |
229 // We don't try to optimize for this case at all | 230 // We don't try to optimize for this case at all |
230 if (!inputColor) { | 231 if (!inputColor) { |
231 fsBuilder->codeAppendf("const vec4 ones = vec4(1);"); | 232 fsBuilder->codeAppendf("const vec4 ones = vec4(1);"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 case SkXfermode::kClear_Mode: | 290 case SkXfermode::kClear_Mode: |
290 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 291 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, |
291 GrConstColorProcessor::kIgnore_
InputMode); | 292 GrConstColorProcessor::kIgnore_
InputMode); |
292 case SkXfermode::kDst_Mode: | 293 case SkXfermode::kDst_Mode: |
293 return nullptr; | 294 return nullptr; |
294 default: | 295 default: |
295 return new ComposeOneFragmentProcessor(src, mode, | 296 return new ComposeOneFragmentProcessor(src, mode, |
296 ComposeOneFragmentProcessor::
kSrc_Child); | 297 ComposeOneFragmentProcessor::
kSrc_Child); |
297 } | 298 } |
298 } | 299 } |
OLD | NEW |