| 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 #include "glsl/GrGLSLProgramDataManager.h" |
| 11 | 12 |
| 12 class GLConstColorProcessor : public GrGLFragmentProcessor { | 13 class GLConstColorProcessor : public GrGLFragmentProcessor { |
| 13 public: | 14 public: |
| 14 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {} | 15 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {} |
| 15 | 16 |
| 16 void emitCode(EmitArgs& args) override { | 17 void emitCode(EmitArgs& args) override { |
| 17 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); | 18 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); |
| 18 const char* colorUni; | 19 const char* colorUni; |
| 19 fColorUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 20 fColorUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 20 kVec4f_GrSLType, kMedium_GrSLPrecisi
on, "constantColor", | 21 kVec4f_GrSLType, kMedium_GrSLPrecisi
on, "constantColor", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 colorUni); | 33 colorUni); |
| 33 break; | 34 break; |
| 34 case GrConstColorProcessor::kModulateA_InputMode: | 35 case GrConstColorProcessor::kModulateA_InputMode: |
| 35 fsBuilder->codeAppendf("%s = %s.a * %s;", args.fOutputColor, arg
s.fInputColor, | 36 fsBuilder->codeAppendf("%s = %s.a * %s;", args.fOutputColor, arg
s.fInputColor, |
| 36 colorUni); | 37 colorUni); |
| 37 break; | 38 break; |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| 41 protected: | 42 protected: |
| 42 void onSetData(const GrGLProgramDataManager& pdm, const GrProcessor& process
or) override { | 43 void onSetData(const GrGLSLProgramDataManager& pdm, const GrProcessor& proce
ssor) override { |
| 43 GrColor color = processor.cast<GrConstColorProcessor>().color(); | 44 GrColor color = processor.cast<GrConstColorProcessor>().color(); |
| 44 // We use the "illegal" color value as an uninit sentinel. However, ut i
sn't inherently | 45 // We use the "illegal" color value as an uninit sentinel. However, ut i
sn't inherently |
| 45 // illegal to use this processor with unpremul colors. So we correctly h
andle the case | 46 // illegal to use this processor with unpremul colors. So we correctly h
andle the case |
| 46 // when the "illegal" color is used but we will always upload it. | 47 // when the "illegal" color is used but we will always upload it. |
| 47 if (GrColor_ILLEGAL == color || fPrevColor != color) { | 48 if (GrColor_ILLEGAL == color || fPrevColor != color) { |
| 48 static const GrGLfloat scale = 1.f / 255.f; | 49 static const float scale = 1.f / 255.f; |
| 49 GrGLfloat floatColor[4] = { | 50 float floatColor[4] = { |
| 50 GrColorUnpackR(color) * scale, | 51 GrColorUnpackR(color) * scale, |
| 51 GrColorUnpackG(color) * scale, | 52 GrColorUnpackG(color) * scale, |
| 52 GrColorUnpackB(color) * scale, | 53 GrColorUnpackB(color) * scale, |
| 53 GrColorUnpackA(color) * scale, | 54 GrColorUnpackA(color) * scale, |
| 54 }; | 55 }; |
| 55 pdm.set4fv(fColorUniform, 1, floatColor); | 56 pdm.set4fv(fColorUniform, 1, floatColor); |
| 56 fPrevColor = color; | 57 fPrevColor = color; |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 GrGLProgramDataManager::UniformHandle fColorUniform; | 62 GrGLSLProgramDataManager::UniformHandle fColorUniform; |
| 62 GrColor fPrevColor; | 63 GrColor fPrevColor; |
| 63 | 64 |
| 64 typedef GrGLFragmentProcessor INHERITED; | 65 typedef GrGLFragmentProcessor INHERITED; |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
| 68 | 69 |
| 69 void GrConstColorProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) c
onst { | 70 void GrConstColorProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) c
onst { |
| 70 if (kIgnore_InputMode == fMode) { | 71 if (kIgnore_InputMode == fMode) { |
| 71 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, | 72 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 color = 0; | 124 color = 0; |
| 124 break; | 125 break; |
| 125 case 2: | 126 case 2: |
| 126 color = d->fRandom->nextULessThan(0x100); | 127 color = d->fRandom->nextULessThan(0x100); |
| 127 color = color | (color << 8) | (color << 16) | (color << 24); | 128 color = color | (color << 8) | (color << 16) | (color << 24); |
| 128 break; | 129 break; |
| 129 } | 130 } |
| 130 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode
Cnt)); | 131 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode
Cnt)); |
| 131 return GrConstColorProcessor::Create(color, mode); | 132 return GrConstColorProcessor::Create(color, mode); |
| 132 } | 133 } |
| OLD | NEW |