| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "effects/GrExtractAlphaFragmentProcessor.h" | |
| 9 #include "gl/GrGLFragmentProcessor.h" | |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | |
| 11 | |
| 12 class GLExtractAlphaFragmentProcessor : public GrGLFragmentProcessor { | |
| 13 public: | |
| 14 GLExtractAlphaFragmentProcessor() {} | |
| 15 | |
| 16 void emitCode(EmitArgs& args) override { | |
| 17 if (args.fInputColor) { | |
| 18 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBui
lder(); | |
| 19 fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor); | |
| 20 this->emitChild(0, "alpha4", args.fOutputColor, args); | |
| 21 } else { | |
| 22 this->emitChild(0, nullptr, args.fOutputColor, args); | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 private: | |
| 27 typedef GrGLFragmentProcessor INHERITED; | |
| 28 }; | |
| 29 | |
| 30 GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() con
st { | |
| 31 return SkNEW(GLExtractAlphaFragmentProcessor); | |
| 32 } | |
| 33 | |
| 34 void GrExtractAlphaFragmentProcessor::onGetGLProcessorKey(const GrGLSLCaps&, | |
| 35 GrProcessorKeyBuilder*
) const { | |
| 36 } | |
| 37 | |
| 38 bool GrExtractAlphaFragmentProcessor::onIsEqual(const GrFragmentProcessor&) cons
t { return true; } | |
| 39 | |
| 40 void GrExtractAlphaFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput
* inout) const { | |
| 41 if (inout->validFlags() & kA_GrColorComponentFlag) { | |
| 42 GrColor color = GrColorPackA4(GrColorUnpackA(inout->color())); | |
| 43 inout->setToOther(kRGBA_GrColorComponentFlags, color, | |
| 44 GrInvariantOutput::kWill_ReadInput); | |
| 45 } else { | |
| 46 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | |
| 47 } | |
| 48 this->childProcessor(0).computeInvariantOutput(inout); | |
| 49 } | |
| 50 | |
| 51 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrExtractAlphaFragmentProcessor); | |
| 52 | |
| 53 const GrFragmentProcessor* GrExtractAlphaFragmentProcessor::TestCreate(GrProcess
orTestData* d) { | |
| 54 SkAutoTUnref<const GrFragmentProcessor> child(GrProcessorUnitTest::CreateChi
ldFP(d)); | |
| 55 return SkNEW_ARGS(GrExtractAlphaFragmentProcessor, (child)); | |
| 56 } | |
| OLD | NEW |