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/GrConstColorProcessor.h" | 8 #include "effects/GrConstColorProcessor.h" |
9 #include "gl/GrGLFragmentProcessor.h" | 9 #include "gl/GrGLFragmentProcessor.h" |
10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
11 | 11 |
12 class GLConstColorProcessor : public GrGLFragmentProcessor { | 12 class GLConstColorProcessor : public GrGLFragmentProcessor { |
13 public: | 13 public: |
14 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {} | 14 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {} |
15 | 15 |
16 void emitCode(EmitArgs& args) override { | 16 void emitCode(EmitArgs& args) override { |
17 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); | 17 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); |
18 const char* colorUni; | 18 const char* colorUni; |
19 fColorUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 19 fColorUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
20 kVec4f_GrSLType, kMedium_GrSLPrecisi
on, "constantColor", | 20 kVec4f_GrSLType, kMedium_GrSLPrecisi
on, "constantColor", |
21 &colorUni); | 21 &colorUni); |
22 switch (args.fFp.cast<GrConstColorProcessor>().inputMode()) { | 22 GrConstColorProcessor::InputMode mode = args.fFp.cast<GrConstColorProces
sor>().inputMode(); |
| 23 if (!args.fInputColor) { |
| 24 mode = GrConstColorProcessor::kIgnore_InputMode; |
| 25 } |
| 26 switch (mode) { |
23 case GrConstColorProcessor::kIgnore_InputMode: | 27 case GrConstColorProcessor::kIgnore_InputMode: |
24 fsBuilder->codeAppendf("%s = %s;", args.fOutputColor, colorUni); | 28 fsBuilder->codeAppendf("%s = %s;", args.fOutputColor, colorUni); |
25 break; | 29 break; |
26 case GrConstColorProcessor::kModulateRGBA_InputMode: | 30 case GrConstColorProcessor::kModulateRGBA_InputMode: |
27 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, args.
fInputColor, | 31 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, args.
fInputColor, |
28 colorUni); | 32 colorUni); |
29 break; | 33 break; |
30 case GrConstColorProcessor::kModulateA_InputMode: | 34 case GrConstColorProcessor::kModulateA_InputMode: |
31 fsBuilder->codeAppendf("%s = %s.a * %s;", args.fOutputColor, arg
s.fInputColor, | 35 fsBuilder->codeAppendf("%s = %s.a * %s;", args.fOutputColor, arg
s.fInputColor, |
32 colorUni); | 36 colorUni); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 color = 0; | 123 color = 0; |
120 break; | 124 break; |
121 case 2: | 125 case 2: |
122 color = d->fRandom->nextULessThan(0x100); | 126 color = d->fRandom->nextULessThan(0x100); |
123 color = color | (color << 8) | (color << 16) | (color << 24); | 127 color = color | (color << 8) | (color << 16) | (color << 24); |
124 break; | 128 break; |
125 } | 129 } |
126 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode
Cnt)); | 130 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode
Cnt)); |
127 return GrConstColorProcessor::Create(color, mode); | 131 return GrConstColorProcessor::Create(color, mode); |
128 } | 132 } |
OLD | NEW |