Index: src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp |
diff --git a/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp b/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3414df2b135bb548d93223858bf18db197873af9 |
--- /dev/null |
+++ b/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp |
@@ -0,0 +1,47 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "effects/GrExtractAlphaFragmentProcessor.h" |
+#include "gl/GrGLFragmentProcessor.h" |
+#include "gl/builders/GrGLProgramBuilder.h" |
+ |
+class GLExtractAlphaFragmentProcessor : public GrGLFragmentProcessor { |
+public: |
+ GLExtractAlphaFragmentProcessor() {} |
+ |
+ void emitCode(EmitArgs& args) override { |
+ GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
+ fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor); |
+ SkString output; |
+ this->emitChild(0, "alpha4", &output, args); |
+ fsBuilder->codeAppendf("%s = %s;", args.fOutputColor, output.c_str()); |
+ } |
+ |
+private: |
+ typedef GrGLFragmentProcessor INHERITED; |
+}; |
+ |
+GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() const { |
+ return SkNEW(GLExtractAlphaFragmentProcessor); |
+} |
+ |
+void GrExtractAlphaFragmentProcessor::onGetGLProcessorKey(const GrGLSLCaps&, |
+ GrProcessorKeyBuilder*) const { |
+} |
+ |
+bool GrExtractAlphaFragmentProcessor::onIsEqual(const GrFragmentProcessor&) const { return true; } |
+ |
+void GrExtractAlphaFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
+ if (inout->validFlags() & kA_GrColorComponentFlag) { |
+ GrColor color = GrColorPackA4(GrColorUnpackA(inout->color())); |
+ inout->setToOther(kRGBA_GrColorComponentFlags, color, |
+ GrInvariantOutput::kWill_ReadInput); |
+ } else { |
+ inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
+ } |
+ this->childProcessor(0).computeInvariantOutput(inout); |
+} |