diff options
author | Brian Osman <brianosman@google.com> | 2017-03-22 14:37:50 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-22 19:16:30 +0000 |
commit | ce425510a07632f14b7b779ec3864f719cb4326b (patch) | |
tree | 9d0c42b3aa282f4a7610c91108854fd94f6a33cb /src/gpu/GrFragmentProcessor.cpp | |
parent | dda14b9b7ac13dba9214f484fc6270b3ccf4b68b (diff) |
Add Swizzle FP, and remove swizzle logic from GrConfigConversionEffect
Trying to decompose read/writePixels into some reusable chunks.
BUG=skia:5853
Change-Id: If08b004b008e8ca7d464d9dc47068e487bae850a
Reviewed-on: https://skia-review.googlesource.com/10015
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/gpu/GrFragmentProcessor.cpp')
-rw-r--r-- | src/gpu/GrFragmentProcessor.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp index 27d0bcdf31..0d1bfadcc5 100644 --- a/src/gpu/GrFragmentProcessor.cpp +++ b/src/gpu/GrFragmentProcessor.cpp @@ -207,6 +207,63 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::UnpremulOutput(sk_sp<GrFragmentP return GrFragmentProcessor::RunInSeries(fpPipeline, 2); } +sk_sp<GrFragmentProcessor> GrFragmentProcessor::SwizzleOutput(sk_sp<GrFragmentProcessor> fp, + const GrSwizzle& swizzle) { + class SwizzleFragmentProcessor : public GrFragmentProcessor { + public: + SwizzleFragmentProcessor(const GrSwizzle& swizzle) + : INHERITED(kAll_OptimizationFlags) + , fSwizzle(swizzle) { + this->initClassID<SwizzleFragmentProcessor>(); + } + + const char* name() const override { return "Swizzle"; } + const GrSwizzle& swizzle() const { return fSwizzle; } + + private: + GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { + class GLFP : public GrGLSLFragmentProcessor { + public: + void emitCode(EmitArgs& args) override { + const SwizzleFragmentProcessor& sfp = args.fFp.cast<SwizzleFragmentProcessor>(); + const GrSwizzle& swizzle = sfp.swizzle(); + GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; + + fragBuilder->codeAppendf("%s = %s.%s;", + args.fOutputColor, args.fInputColor, swizzle.c_str()); + } + }; + return new GLFP; + } + + void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { + b->add32(fSwizzle.asKey()); + } + + bool onIsEqual(const GrFragmentProcessor& other) const override { + const SwizzleFragmentProcessor& sfp = other.cast<SwizzleFragmentProcessor>(); + return fSwizzle == sfp.fSwizzle; + } + + GrColor4f constantOutputForConstantInput(GrColor4f input) const override { + return fSwizzle.applyTo(input); + } + + GrSwizzle fSwizzle; + + typedef GrFragmentProcessor INHERITED; + }; + + if (!fp) { + return nullptr; + } + if (GrSwizzle::RGBA() == swizzle) { + return fp; + } + sk_sp<GrFragmentProcessor> fpPipeline[] = { fp, sk_make_sp<SwizzleFragmentProcessor>(swizzle) }; + return GrFragmentProcessor::RunInSeries(fpPipeline, 2); +} + sk_sp<GrFragmentProcessor> GrFragmentProcessor::MakeInputPremulAndMulByOutput( sk_sp<GrFragmentProcessor> fp) { |