From 87ba62e67c9ed0c453754a5341255829075c8e22 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Tue, 22 Sep 2015 06:41:59 -0700 Subject: [PATCH] Replace GrExtractAlphaFragmentProcessor with DstIn compose processor Review URL: https://codereview.chromium.org/1347943003 --- gm/dcshader.cpp | 4 +- gyp/gpu.gypi | 2 - include/gpu/GrFragmentProcessor.h | 10 ++++ .../effects/GrExtractAlphaFragmentProcessor.h | 47 ---------------- src/core/SkBitmapProcShader.cpp | 3 +- src/core/SkLightingShader.cpp | 3 +- src/effects/SkPerlinNoiseShader.cpp | 5 +- src/effects/gradients/SkLinearGradient.cpp | 3 +- src/effects/gradients/SkRadialGradient.cpp | 3 +- src/effects/gradients/SkSweepGradient.cpp | 3 +- .../gradients/SkTwoPointConicalGradient.cpp | 3 +- src/gpu/GrProcessor.cpp | 7 +++ .../GrExtractAlphaFragmentProcessor.cpp | 56 ------------------- 13 files changed, 27 insertions(+), 122 deletions(-) delete mode 100644 include/gpu/effects/GrExtractAlphaFragmentProcessor.h delete mode 100644 src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp diff --git a/gm/dcshader.cpp b/gm/dcshader.cpp index 56265f16c9..051430ea88 100644 --- a/gm/dcshader.cpp +++ b/gm/dcshader.cpp @@ -10,7 +10,7 @@ #if SK_SUPPORT_GPU #include "GrFragmentProcessor.h" #include "GrCoordTransform.h" -#include "effects/GrExtractAlphaFragmentProcessor.h" +#include "effects/GrXfermodeFragmentProcessor.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "Resources.h" @@ -104,7 +104,7 @@ const GrFragmentProcessor* DCShader::asFragmentProcessor( SkFilterQuality, GrProcessorDataManager* procDataManager) const { SkAutoTUnref inner(new DCFP(procDataManager, fDeviceMatrix)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } class DCShaderGM : public GM { diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index c9761943b9..7840abcf19 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -46,7 +46,6 @@ '<(skia_include_path)/gpu/effects/GrConstColorProcessor.h', '<(skia_include_path)/gpu/effects/GrCoverageSetOpXP.h', '<(skia_include_path)/gpu/effects/GrCustomXfermode.h', - '<(skia_include_path)/gpu/effects/GrExtractAlphaFragmentProcessor.h', '<(skia_include_path)/gpu/effects/GrPorterDuffXferProcessor.h', '<(skia_include_path)/gpu/effects/GrXfermodeFragmentProcessor.h', @@ -243,7 +242,6 @@ '<(skia_src_path)/gpu/effects/GrConfigConversionEffect.cpp', '<(skia_src_path)/gpu/effects/GrConfigConversionEffect.h', '<(skia_src_path)/gpu/effects/GrConstColorProcessor.cpp', - '<(skia_src_path)/gpu/effects/GrExtractAlphaFragmentProcessor.cpp', '<(skia_src_path)/gpu/effects/GrCoverageSetOpXP.cpp', '<(skia_src_path)/gpu/effects/GrCustomXfermode.cpp', '<(skia_src_path)/gpu/effects/GrBezierEffect.cpp', diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h index a5e0d98c4d..4b0e1e12d0 100644 --- a/include/gpu/GrFragmentProcessor.h +++ b/include/gpu/GrFragmentProcessor.h @@ -23,6 +23,16 @@ class GrProcessorKeyBuilder; */ class GrFragmentProcessor : public GrProcessor { public: + /** + * In many instances (e.g. SkShader::asFragmentProcessor() implementations) it is desirable to + * only consider the input color's alpha. However, there is a competing desire to have reusable + * GrFragmentProcessor subclasses that can be used in other scenarios where the entire input + * color is considered. This function exists to filter the input color and pass it to a FP. It + * does so by returning a parent FP that multiplies the passed in FPs output by the parent's + * input alpha. The passed in FP will not receive an input color. + */ + static const GrFragmentProcessor* MulOuputByInputAlpha(const GrFragmentProcessor*); + GrFragmentProcessor() : INHERITED() , fUsesLocalCoords(false) diff --git a/include/gpu/effects/GrExtractAlphaFragmentProcessor.h b/include/gpu/effects/GrExtractAlphaFragmentProcessor.h deleted file mode 100644 index 29ff097d9d..0000000000 --- a/include/gpu/effects/GrExtractAlphaFragmentProcessor.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrExtractAlphaFragmentProcessor_DEFINED -#define GrExtractAlphaFragmentProcessor_DEFINED - -#include "GrFragmentProcessor.h" - -/** This processor extracts the incoming color's alpha, ignores r, g, and b, and feeds - the replicated alpha to it's inner processor. */ -class GrExtractAlphaFragmentProcessor : public GrFragmentProcessor { -public: - static GrFragmentProcessor* Create(const GrFragmentProcessor* processor) { - if (!processor) { - return nullptr; - } - return new GrExtractAlphaFragmentProcessor(processor); - } - - ~GrExtractAlphaFragmentProcessor() override {} - - const char* name() const override { return "Extract Alpha"; } - -private: - GrExtractAlphaFragmentProcessor(const GrFragmentProcessor* processor) { - this->initClassID(); - this->registerChildProcessor(processor); - } - - GrGLFragmentProcessor* onCreateGLInstance() const override; - - void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; - - bool onIsEqual(const GrFragmentProcessor&) const override; - - void onComputeInvariantOutput(GrInvariantOutput* inout) const override; - - GR_DECLARE_FRAGMENT_PROCESSOR_TEST; - - typedef GrFragmentProcessor INHERITED; -}; - -#endif diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index 125f480f72..8a5e03cfc3 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -16,7 +16,6 @@ #if SK_SUPPORT_GPU #include "effects/GrBicubicEffect.h" -#include "effects/GrExtractAlphaFragmentProcessor.h" #include "effects/GrSimpleTextureEffect.h" #endif @@ -411,7 +410,7 @@ const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* co if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { return SkRef(inner.get()); } - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } #endif diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp index 2907dba7d5..b23acfdf7d 100644 --- a/src/core/SkLightingShader.cpp +++ b/src/core/SkLightingShader.cpp @@ -131,7 +131,6 @@ private: #include "GrCoordTransform.h" #include "GrFragmentProcessor.h" #include "GrTextureAccess.h" -#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "SkGr.h" @@ -401,7 +400,7 @@ const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( SkAutoTUnref inner ( new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffParams, normParams, fLights, fInvNormRotation)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } #endif diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index a530753d88..842c32ca34 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -20,7 +20,6 @@ #include "GrInvariantOutput.h" #include "SkGr.h" #include "effects/GrConstColorProcessor.h" -#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #endif @@ -935,7 +934,7 @@ const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( SkAutoTUnref inner( GrConstColorProcessor::Create(0x80404040, GrConstColorProcessor::kModulateRGBA_InputMode)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } // Emit zero. return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore_InputMode); @@ -963,7 +962,7 @@ const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( paintingData, permutationsTexture, noiseTexture, m)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } delete paintingData; return nullptr; diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index e36a569562..21d368caab 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -439,7 +439,6 @@ void SkLinearGradient::LinearGradientContext::shadeSpan16(int x, int y, #if SK_SUPPORT_GPU -#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "SkGr.h" @@ -562,7 +561,7 @@ const GrFragmentProcessor* SkLinearGradient::asFragmentProcessor( SkAutoTUnref inner( GrLinearGradient::Create(context, procDataManager, *this, matrix, fTileMode)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp index 13b45101cf..bf46f70f6a 100644 --- a/src/effects/gradients/SkRadialGradient.cpp +++ b/src/effects/gradients/SkRadialGradient.cpp @@ -415,7 +415,6 @@ void SkRadialGradient::RadialGradientContext::shadeSpan(int x, int y, #if SK_SUPPORT_GPU #include "SkGr.h" -#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" class GrGLRadialGradient : public GrGLGradientEffect { @@ -534,7 +533,7 @@ const GrFragmentProcessor* SkRadialGradient::asFragmentProcessor( matrix.postConcat(fPtsToUnit); SkAutoTUnref inner( GrRadialGradient::Create(context, procDataManager, *this, matrix, fTileMode)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } #endif diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 40b0f8288b..207308a97f 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -167,7 +167,6 @@ void SkSweepGradient::SweepGradientContext::shadeSpan16(int x, int y, uint16_t* #if SK_SUPPORT_GPU #include "SkGr.h" -#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" class GrGLSweepGradient : public GrGLGradientEffect { @@ -292,7 +291,7 @@ const GrFragmentProcessor* SkSweepGradient::asFragmentProcessor( SkAutoTUnref inner( GrSweepGradient::Create(context, procDataManager, *this, matrix)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } #endif diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index daec1e6388..f6462b31ae 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -359,7 +359,6 @@ void SkTwoPointConicalGradient::flatten(SkWriteBuffer& buffer) const { #if SK_SUPPORT_GPU #include "SkGr.h" -#include "effects/GrExtractAlphaFragmentProcessor.h" const GrFragmentProcessor* SkTwoPointConicalGradient::asFragmentProcessor( GrContext* context, @@ -372,7 +371,7 @@ const GrFragmentProcessor* SkTwoPointConicalGradient::asFragmentProcessor( SkAutoTUnref inner( Gr2PtConicalGradientEffect::Create(context, procDataManager, *this, fTileMode, localMatrix)); - return GrExtractAlphaFragmentProcessor::Create(inner); + return GrFragmentProcessor::MulOuputByInputAlpha(inner); } #endif diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp index 782b82ba5c..496e8ee218 100644 --- a/src/gpu/GrProcessor.cpp +++ b/src/gpu/GrProcessor.cpp @@ -241,6 +241,13 @@ bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con return true; } +#include "effects/GrXfermodeFragmentProcessor.h" + +const GrFragmentProcessor* GrFragmentProcessor::MulOuputByInputAlpha( + const GrFragmentProcessor* fp) { + return GrXfermodeFragmentProcessor::CreateFromDstProcessor(fp, SkXfermode::kDstIn_Mode); +} + /////////////////////////////////////////////////////////////////////////////////////////////////// // Initial static variable from GrXPFactory diff --git a/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp b/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp deleted file mode 100644 index 93a394eb78..0000000000 --- a/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 { - if (args.fInputColor) { - GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); - fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor); - this->emitChild(0, "alpha4", args.fOutputColor, args); - } else { - this->emitChild(0, nullptr, args.fOutputColor, args); - } - } - -private: - typedef GrGLFragmentProcessor INHERITED; -}; - -GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() const { - return new 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); -} - -GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrExtractAlphaFragmentProcessor); - -const GrFragmentProcessor* GrExtractAlphaFragmentProcessor::TestCreate(GrProcessorTestData* d) { - SkAutoTUnref child(GrProcessorUnitTest::CreateChildFP(d)); - return new GrExtractAlphaFragmentProcessor(child); -}