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/GrExtractAlphaFragmentProcessor.h" | 8 #include "effects/GrExtractAlphaFragmentProcessor.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 GLExtractAlphaFragmentProcessor : public GrGLFragmentProcessor { | 12 class GLExtractAlphaFragmentProcessor : public GrGLFragmentProcessor { |
13 public: | 13 public: |
14 GLExtractAlphaFragmentProcessor() {} | 14 GLExtractAlphaFragmentProcessor() {} |
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 fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor); | 18 fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor); |
19 SkString output; | 19 this->emitChild(0, "alpha4", args.fOutputColor, args); |
20 this->emitChild(0, "alpha4", &output, args); | |
21 fsBuilder->codeAppendf("%s = %s;", args.fOutputColor, output.c_str()); | |
22 } | 20 } |
23 | 21 |
24 private: | 22 private: |
25 typedef GrGLFragmentProcessor INHERITED; | 23 typedef GrGLFragmentProcessor INHERITED; |
26 }; | 24 }; |
27 | 25 |
28 GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() con
st { | 26 GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() con
st { |
29 return SkNEW(GLExtractAlphaFragmentProcessor); | 27 return SkNEW(GLExtractAlphaFragmentProcessor); |
30 } | 28 } |
31 | 29 |
32 void GrExtractAlphaFragmentProcessor::onGetGLProcessorKey(const GrGLSLCaps&, | 30 void GrExtractAlphaFragmentProcessor::onGetGLProcessorKey(const GrGLSLCaps&, |
33 GrProcessorKeyBuilder*
) const { | 31 GrProcessorKeyBuilder*
) const { |
34 } | 32 } |
35 | 33 |
36 bool GrExtractAlphaFragmentProcessor::onIsEqual(const GrFragmentProcessor&) cons
t { return true; } | 34 bool GrExtractAlphaFragmentProcessor::onIsEqual(const GrFragmentProcessor&) cons
t { return true; } |
37 | 35 |
38 void GrExtractAlphaFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput
* inout) const { | 36 void GrExtractAlphaFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput
* inout) const { |
39 if (inout->validFlags() & kA_GrColorComponentFlag) { | 37 if (inout->validFlags() & kA_GrColorComponentFlag) { |
40 GrColor color = GrColorPackA4(GrColorUnpackA(inout->color())); | 38 GrColor color = GrColorPackA4(GrColorUnpackA(inout->color())); |
41 inout->setToOther(kRGBA_GrColorComponentFlags, color, | 39 inout->setToOther(kRGBA_GrColorComponentFlags, color, |
42 GrInvariantOutput::kWill_ReadInput); | 40 GrInvariantOutput::kWill_ReadInput); |
43 } else { | 41 } else { |
44 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 42 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
45 } | 43 } |
46 this->childProcessor(0).computeInvariantOutput(inout); | 44 this->childProcessor(0).computeInvariantOutput(inout); |
47 } | 45 } |
OLD | NEW |