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 "glsl/GrGLSLFragmentProcessor.h" |
10 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
11 #include "glsl/GrGLSLProgramBuilder.h" | 11 #include "glsl/GrGLSLProgramBuilder.h" |
12 #include "glsl/GrGLSLProgramDataManager.h" | 12 #include "glsl/GrGLSLProgramDataManager.h" |
13 | 13 |
14 class GLConstColorProcessor : public GrGLFragmentProcessor { | 14 class GLConstColorProcessor : public GrGLSLFragmentProcessor { |
15 public: | 15 public: |
16 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {} | 16 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {} |
17 | 17 |
18 void emitCode(EmitArgs& args) override { | 18 void emitCode(EmitArgs& args) override { |
19 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild
er(); | 19 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild
er(); |
20 const char* colorUni; | 20 const char* colorUni; |
21 fColorUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, | 21 fColorUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, |
22 kVec4f_GrSLType, kMedium_GrSLPrecisi
on, "constantColor", | 22 kVec4f_GrSLType, kMedium_GrSLPrecisi
on, "constantColor", |
23 &colorUni); | 23 &colorUni); |
24 GrConstColorProcessor::InputMode mode = args.fFp.cast<GrConstColorProces
sor>().inputMode(); | 24 GrConstColorProcessor::InputMode mode = args.fFp.cast<GrConstColorProces
sor>().inputMode(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 }; | 56 }; |
57 pdm.set4fv(fColorUniform, 1, floatColor); | 57 pdm.set4fv(fColorUniform, 1, floatColor); |
58 fPrevColor = color; | 58 fPrevColor = color; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 GrGLSLProgramDataManager::UniformHandle fColorUniform; | 63 GrGLSLProgramDataManager::UniformHandle fColorUniform; |
64 GrColor fPrevColor; | 64 GrColor fPrevColor; |
65 | 65 |
66 typedef GrGLFragmentProcessor INHERITED; | 66 typedef GrGLSLFragmentProcessor INHERITED; |
67 }; | 67 }; |
68 | 68 |
69 /////////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////////// |
70 | 70 |
71 void GrConstColorProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) c
onst { | 71 void GrConstColorProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) c
onst { |
72 if (kIgnore_InputMode == fMode) { | 72 if (kIgnore_InputMode == fMode) { |
73 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, | 73 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, |
74 GrInvariantOutput::kWillNot_ReadInput); | 74 GrInvariantOutput::kWillNot_ReadInput); |
75 } else { | 75 } else { |
76 GrColor r = GrColorUnpackR(fColor); | 76 GrColor r = GrColorUnpackR(fColor); |
(...skipping 12 matching lines...) Expand all Loading... |
89 inout->mulAlphaByKnownFourComponents(fColor); | 89 inout->mulAlphaByKnownFourComponents(fColor); |
90 } | 90 } |
91 } | 91 } |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 void GrConstColorProcessor::onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKe
yBuilder* b) const { | 95 void GrConstColorProcessor::onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKe
yBuilder* b) const { |
96 b->add32(fMode); | 96 b->add32(fMode); |
97 } | 97 } |
98 | 98 |
99 GrGLFragmentProcessor* GrConstColorProcessor::onCreateGLInstance() const { | 99 GrGLSLFragmentProcessor* GrConstColorProcessor::onCreateGLInstance() const { |
100 return new GLConstColorProcessor; | 100 return new GLConstColorProcessor; |
101 } | 101 } |
102 | 102 |
103 bool GrConstColorProcessor::onIsEqual(const GrFragmentProcessor& other) const { | 103 bool GrConstColorProcessor::onIsEqual(const GrFragmentProcessor& other) const { |
104 const GrConstColorProcessor& that = other.cast<GrConstColorProcessor>(); | 104 const GrConstColorProcessor& that = other.cast<GrConstColorProcessor>(); |
105 return fMode == that.fMode && fColor == that.fColor; | 105 return fMode == that.fMode && fColor == that.fColor; |
106 } | 106 } |
107 | 107 |
108 /////////////////////////////////////////////////////////////////////////////// | 108 /////////////////////////////////////////////////////////////////////////////// |
109 | 109 |
(...skipping 15 matching lines...) Expand all Loading... |
125 color = 0; | 125 color = 0; |
126 break; | 126 break; |
127 case 2: | 127 case 2: |
128 color = d->fRandom->nextULessThan(0x100); | 128 color = d->fRandom->nextULessThan(0x100); |
129 color = color | (color << 8) | (color << 16) | (color << 24); | 129 color = color | (color << 8) | (color << 16) | (color << 24); |
130 break; | 130 break; |
131 } | 131 } |
132 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode
Cnt)); | 132 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode
Cnt)); |
133 return GrConstColorProcessor::Create(color, mode); | 133 return GrConstColorProcessor::Create(color, mode); |
134 } | 134 } |
OLD | NEW |