Index: src/gpu/GrFragmentProcessor.cpp |
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp |
index bad7ebe0360cd046262d39b4fa639aeecb874445..fdba610356c2dd74a0c786027809a29b0255f7a0 100644 |
--- a/src/gpu/GrFragmentProcessor.cpp |
+++ b/src/gpu/GrFragmentProcessor.cpp |
@@ -143,6 +143,46 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha( |
SkXfermode::kDstIn_Mode); |
} |
+sk_sp<GrFragmentProcessor> GrFragmentProcessor::PremulInput(sk_sp<GrFragmentProcessor> fp) { |
+ |
+ class PremulInputFragmentProcessor : public GrFragmentProcessor { |
+ public: |
+ PremulInputFragmentProcessor() { |
+ this->initClassID<PremulInputFragmentProcessor>(); |
+ } |
+ |
+ const char* name() const override { return "PremultiplyInput"; } |
+ |
+ private: |
+ GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
+ class GLFP : public GrGLSLFragmentProcessor { |
+ public: |
+ void emitCode(EmitArgs& args) override { |
+ GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
+ |
+ fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor); |
+ fragBuilder->codeAppendf("%s.rgb *= %s.a;", |
+ args.fOutputColor, args.fInputColor); |
+ } |
+ }; |
+ return new GLFP; |
+ } |
+ |
+ void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override {} |
+ |
+ bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
+ |
+ void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
+ inout->premulFourChannelColor(); |
+ } |
+ }; |
+ if (!fp) { |
+ return nullptr; |
+ } |
+ sk_sp<GrFragmentProcessor> fpPipeline[] = { sk_make_sp<PremulInputFragmentProcessor>(), fp}; |
+ return GrFragmentProcessor::RunInSeries(fpPipeline, 2); |
+} |
+ |
sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputUnpremulColor( |
sk_sp<GrFragmentProcessor> fp) { |