diff options
author | bsalomon <bsalomon@google.com> | 2015-09-15 15:33:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-15 15:33:27 -0700 |
commit | ae4738f677c70f4ec7687422e1510ee3d80d810e (patch) | |
tree | 81c2e343e61a5102a74fbb67246101d1006c0738 /src/effects | |
parent | cd7f03597475ea423aa819bdae03996b26874dd5 (diff) |
Create fragment processor for performing input color blend with child processor
The new FP is used to implement SkXM::Mode color filters and SkXM::Mode image filters. Also, these now support all advanced SkXM::Mode xfermodes.
Review URL: https://codereview.chromium.org/1334293003
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkArithmeticMode.cpp | 10 | ||||
-rw-r--r-- | src/effects/SkArithmeticMode_gpu.cpp | 38 | ||||
-rw-r--r-- | src/effects/SkArithmeticMode_gpu.h | 12 | ||||
-rw-r--r-- | src/effects/SkColorCubeFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkColorFilters.cpp | 315 | ||||
-rw-r--r-- | src/effects/SkColorMatrixFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkLumaColorFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkTableColorFilter.cpp | 8 | ||||
-rw-r--r-- | src/effects/SkXfermodeImageFilter.cpp | 14 |
9 files changed, 65 insertions, 338 deletions
diff --git a/src/effects/SkArithmeticMode.cpp b/src/effects/SkArithmeticMode.cpp index 7db6b47d66..35ac8a84ba 100644 --- a/src/effects/SkArithmeticMode.cpp +++ b/src/effects/SkArithmeticMode.cpp @@ -31,8 +31,8 @@ public: SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkArithmeticMode_scalar) #if SK_SUPPORT_GPU - bool asFragmentProcessor(GrFragmentProcessor**, GrProcessorDataManager*, - GrTexture* background) const override; + bool asFragmentProcessor(const GrFragmentProcessor**, GrProcessorDataManager*, + const GrFragmentProcessor* dst) const override; bool asXPFactory(GrXPFactory**) const override; #endif @@ -235,9 +235,9 @@ SkXfermode* SkArithmeticMode::Create(SkScalar k1, SkScalar k2, ////////////////////////////////////////////////////////////////////////////// #if SK_SUPPORT_GPU -bool SkArithmeticMode_scalar::asFragmentProcessor(GrFragmentProcessor** fp, +bool SkArithmeticMode_scalar::asFragmentProcessor(const GrFragmentProcessor** fp, GrProcessorDataManager* procDataManager, - GrTexture* background) const { + const GrFragmentProcessor* dst) const { if (fp) { *fp = GrArithmeticFP::Create(procDataManager, SkScalarToFloat(fK[0]), @@ -245,7 +245,7 @@ bool SkArithmeticMode_scalar::asFragmentProcessor(GrFragmentProcessor** fp, SkScalarToFloat(fK[2]), SkScalarToFloat(fK[3]), fEnforcePMColor, - background); + dst); } return true; } diff --git a/src/effects/SkArithmeticMode_gpu.cpp b/src/effects/SkArithmeticMode_gpu.cpp index fd20b73cdc..5f149d0712 100644 --- a/src/effects/SkArithmeticMode_gpu.cpp +++ b/src/effects/SkArithmeticMode_gpu.cpp @@ -21,16 +21,16 @@ static const bool gUseUnpremul = false; static void add_arithmetic_code(GrGLFragmentBuilder* fsBuilder, - const char* inputColor, + const char* srcColor, const char* dstColor, const char* outputColor, const char* kUni, bool enforcePMColor) { // We don't try to optimize for this case at all - if (nullptr == inputColor) { + if (nullptr == srcColor) { fsBuilder->codeAppend("const vec4 src = vec4(1);"); } else { - fsBuilder->codeAppendf("vec4 src = %s;", inputColor); + fsBuilder->codeAppendf("vec4 src = %s;", srcColor); if (gUseUnpremul) { fsBuilder->codeAppend("src.rgb = clamp(src.rgb / src.a, 0.0, 1.0);"); } @@ -54,26 +54,21 @@ static void add_arithmetic_code(GrGLFragmentBuilder* fsBuilder, class GLArithmeticFP : public GrGLFragmentProcessor { public: - GLArithmeticFP(const GrProcessor&) - : fEnforcePMColor(true) { - } + GLArithmeticFP(const GrProcessor&) : fEnforcePMColor(true) {} ~GLArithmeticFP() override {} void emitCode(EmitArgs& args) override { GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); - fsBuilder->codeAppend("vec4 bgColor = "); - fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(), - args.fCoords[0].getType()); - fsBuilder->codeAppendf(";"); - const char* dstColor = "bgColor"; + fsBuilder->codeAppend("vec4 _dstColor;"); + this->emitChild(0, nullptr, "_dstColor", args); fKUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility, - kVec4f_GrSLType, kDefault_GrSLPrecision, - "k"); + kVec4f_GrSLType, kDefault_GrSLPrecision, + "k"); const char* kUni = args.fBuilder->getUniformCStr(fKUni); - add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputColor, kUni, + add_arithmetic_code(fsBuilder, args.fInputColor, "_dstColor", args.fOutputColor, kUni, fEnforcePMColor); } @@ -100,17 +95,13 @@ private: /////////////////////////////////////////////////////////////////////////////// GrArithmeticFP::GrArithmeticFP(GrProcessorDataManager*, float k1, float k2, float k3, float k4, - bool enforcePMColor, GrTexture* background) + bool enforcePMColor, const GrFragmentProcessor* dst) : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { this->initClassID<GrArithmeticFP>(); - SkASSERT(background); - - fBackgroundTransform.reset(kLocal_GrCoordSet, background, - GrTextureParams::kNone_FilterMode); - this->addCoordTransform(&fBackgroundTransform); - fBackgroundAccess.reset(background); - this->addTextureAccess(&fBackgroundAccess); + SkASSERT(dst); + SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); + SkASSERT(0 == dstIndex); } void GrArithmeticFP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const { @@ -144,7 +135,8 @@ const GrFragmentProcessor* GrArithmeticFP::TestCreate(GrProcessorTestData* d) { float k4 = d->fRandom->nextF(); bool enforcePMColor = d->fRandom->nextBool(); - return new GrArithmeticFP(d->fProcDataManager, k1, k2, k3, k4, enforcePMColor, d->fTextures[0]); + SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChildFP(d)); + return new GrArithmeticFP(d->fProcDataManager, k1, k2, k3, k4, enforcePMColor, dst); } GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticFP); diff --git a/src/effects/SkArithmeticMode_gpu.h b/src/effects/SkArithmeticMode_gpu.h index 7b343ee35f..d415cc4a49 100644 --- a/src/effects/SkArithmeticMode_gpu.h +++ b/src/effects/SkArithmeticMode_gpu.h @@ -31,10 +31,10 @@ class GrGLArtithmeticFP; class GrArithmeticFP : public GrFragmentProcessor { public: - static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, float k1, float k2, - float k3, float k4, bool enforcePMColor, - GrTexture* background) { - return new GrArithmeticFP(procDataManager, k1, k2, k3, k4, enforcePMColor, background); + static const GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, + float k1, float k2, float k3, float k4, + bool enforcePMColor, const GrFragmentProcessor* dst) { + return new GrArithmeticFP(procDataManager, k1, k2, k3, k4, enforcePMColor, dst); } ~GrArithmeticFP() override {}; @@ -57,12 +57,10 @@ private: void onComputeInvariantOutput(GrInvariantOutput* inout) const override; GrArithmeticFP(GrProcessorDataManager*, float k1, float k2, float k3, float k4, - bool enforcePMColor, GrTexture* background); + bool enforcePMColor, const GrFragmentProcessor* dst); float fK1, fK2, fK3, fK4; bool fEnforcePMColor; - GrCoordTransform fBackgroundTransform; - GrTextureAccess fBackgroundAccess; GR_DECLARE_FRAGMENT_PROCESSOR_TEST; typedef GrFragmentProcessor INHERITED; diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp index c5d4fc5a35..da5635cf71 100644 --- a/src/effects/SkColorCubeFilter.cpp +++ b/src/effects/SkColorCubeFilter.cpp @@ -304,7 +304,7 @@ void GrColorCubeEffect::GLProcessor::GenKey(const GrProcessor& proc, } bool SkColorCubeFilter::asFragmentProcessors(GrContext* context, GrProcessorDataManager*, - SkTDArray<GrFragmentProcessor*>* array) const { + SkTDArray<const GrFragmentProcessor*>* array) const { static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); GrUniqueKey key; GrUniqueKey::Builder builder(&key, kDomain, 2); diff --git a/src/effects/SkColorFilters.cpp b/src/effects/SkColorFilters.cpp index c38328ccbb..ece3295107 100644 --- a/src/effects/SkColorFilters.cpp +++ b/src/effects/SkColorFilters.cpp @@ -65,305 +65,36 @@ SkFlattenable* SkModeColorFilter::CreateProc(SkReadBuffer& buffer) { /////////////////////////////////////////////////////////////////////////////// #if SK_SUPPORT_GPU #include "GrBlend.h" -#include "GrFragmentProcessor.h" #include "GrInvariantOutput.h" -#include "GrProcessorUnitTest.h" +#include "effects/GrXfermodeFragmentProcessor.h" +#include "effects/GrConstColorProcessor.h" #include "SkGr.h" -#include "gl/GrGLFragmentProcessor.h" -#include "gl/builders/GrGLProgramBuilder.h" - -namespace { -/** - * A definition of blend equation for one coefficient. Generates a - * blend_coeff * value "expression". - */ -template<typename ColorExpr> -static inline ColorExpr blend_term(SkXfermode::Coeff coeff, - const ColorExpr& src, - const ColorExpr& dst, - const ColorExpr& value) { - switch (coeff) { - default: - SkFAIL("Unexpected xfer coeff."); - case SkXfermode::kZero_Coeff: /** 0 */ - return ColorExpr(0); - case SkXfermode::kOne_Coeff: /** 1 */ - return value; - case SkXfermode::kSC_Coeff: - return src * value; - case SkXfermode::kISC_Coeff: - return (ColorExpr(1) - src) * dst; - case SkXfermode::kDC_Coeff: - return dst * value; - case SkXfermode::kIDC_Coeff: - return (ColorExpr(1) - dst) * value; - case SkXfermode::kSA_Coeff: /** src alpha */ - return src.a() * value; - case SkXfermode::kISA_Coeff: /** inverse src alpha (i.e. 1 - sa) */ - return (typename ColorExpr::AExpr(1) - src.a()) * value; - case SkXfermode::kDA_Coeff: /** dst alpha */ - return dst.a() * value; - case SkXfermode::kIDA_Coeff: /** inverse dst alpha (i.e. 1 - da) */ - return (typename ColorExpr::AExpr(1) - dst.a()) * value; - } -} -/** - * Creates a color filter expression which modifies the color by - * the specified color filter. - */ -template <typename ColorExpr> -static inline ColorExpr color_filter_expression(const SkXfermode::Mode& mode, - const ColorExpr& filterColor, - const ColorExpr& inColor) { - SkXfermode::Coeff colorCoeff; - SkXfermode::Coeff filterColorCoeff; - SkAssertResult(SkXfermode::ModeAsCoeff(mode, &filterColorCoeff, &colorCoeff)); - return blend_term(colorCoeff, filterColor, inColor, inColor) + - blend_term(filterColorCoeff, filterColor, inColor, filterColor); -} - -} - -class ModeColorFilterEffect : public GrFragmentProcessor { -public: - static GrFragmentProcessor* Create(const GrColor& c, SkXfermode::Mode mode) { - // TODO: Make the effect take the coeffs rather than mode since we already do the - // conversion here. - SkXfermode::Coeff srcCoeff, dstCoeff; - if (!SkXfermode::ModeAsCoeff(mode, &srcCoeff, &dstCoeff)) { -// SkDebugf("Failing to create color filter for mode %d\n", mode); - return nullptr; - } - return new ModeColorFilterEffect(c, mode); - } - - bool willUseFilterColor() const { - SkXfermode::Coeff dstCoeff; - SkXfermode::Coeff srcCoeff; - SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); - if (SkXfermode::kZero_Coeff == srcCoeff) { - return GrBlendCoeffRefsSrc(sk_blend_to_grblend(dstCoeff)); - } - return true; - } - - const char* name() const override { return "ModeColorFilterEffect"; } - - SkXfermode::Mode mode() const { return fMode; } - GrColor color() const { return fColor; } - - class GLProcessor : public GrGLFragmentProcessor { - public: - GLProcessor(const GrProcessor&) { - } - - virtual void emitCode(EmitArgs& args) override { - SkXfermode::Mode mode = args.fFp.cast<ModeColorFilterEffect>().mode(); - - SkASSERT(SkXfermode::kDst_Mode != mode); - const char* colorFilterColorUniName = nullptr; - if (args.fFp.cast<ModeColorFilterEffect>().willUseFilterColor()) { - fFilterColorUni = args.fBuilder->addUniform( - GrGLProgramBuilder::kFragment_Visibility, - kVec4f_GrSLType, kDefault_GrSLPrecision, - "FilterColor", - &colorFilterColorUniName); - } - - GrGLSLExpr4 filter = - color_filter_expression(mode, GrGLSLExpr4(colorFilterColorUniName), - GrGLSLExpr4(args.fInputColor)); - - args.fBuilder->getFragmentShaderBuilder()-> - codeAppendf("\t%s = %s;\n", args.fOutputColor, filter.c_str()); - } - - static void GenKey(const GrProcessor& fp, const GrGLSLCaps&, - GrProcessorKeyBuilder* b) { - const ModeColorFilterEffect& colorModeFilter = fp.cast<ModeColorFilterEffect>(); - // The SL code does not depend on filter color at the moment, so no need to represent it - // in the key. - b->add32(colorModeFilter.mode()); - } - - protected: - virtual void onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& fp) override { - if (fFilterColorUni.isValid()) { - const ModeColorFilterEffect& colorModeFilter = fp.cast<ModeColorFilterEffect>(); - GrGLfloat c[4]; - GrColorToRGBAFloat(colorModeFilter.color(), c); - pdman.set4fv(fFilterColorUni, 1, c); - } - } - - private: - - GrGLProgramDataManager::UniformHandle fFilterColorUni; - typedef GrGLFragmentProcessor INHERITED; - }; - - GR_DECLARE_FRAGMENT_PROCESSOR_TEST; - -private: - ModeColorFilterEffect(GrColor color, SkXfermode::Mode mode) - : fMode(mode), - fColor(color) { - this->initClassID<ModeColorFilterEffect>(); - } - - GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLProcessor(*this); } - - virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, - GrProcessorKeyBuilder* b) const override { - GLProcessor::GenKey(*this, caps, b); - } - - bool onIsEqual(const GrFragmentProcessor& other) const override { - const ModeColorFilterEffect& s = other.cast<ModeColorFilterEffect>(); - return fMode == s.fMode && fColor == s.fColor; - } - - void onComputeInvariantOutput(GrInvariantOutput* inout) const override; - - SkXfermode::Mode fMode; - GrColor fColor; - - typedef GrFragmentProcessor INHERITED; -}; - -namespace { - -/** Function color_component_to_int tries to reproduce the GLSL rounding. The spec doesn't specify - * to which direction the 0.5 goes. - */ -static inline int color_component_to_int(float value) { - return sk_float_round2int(SkTMax(0.f, SkTMin(1.f, value)) * 255.f); -} - -/** MaskedColorExpr is used to evaluate the color and valid color component flags through the - * blending equation. It has members similar to GrGLSLExpr so that it can be used with the - * templated helpers above. - */ -class MaskedColorExpr { -public: - MaskedColorExpr(const float color[], uint32_t flags) - : fFlags(flags) { - fColor[0] = color[0]; - fColor[1] = color[1]; - fColor[2] = color[2]; - fColor[3] = color[3]; - } - - MaskedColorExpr(float v, uint32_t flags = kRGBA_GrColorComponentFlags) - : fFlags(flags) { - fColor[0] = v; - fColor[1] = v; - fColor[2] = v; - fColor[3] = v; - } - - MaskedColorExpr operator*(const MaskedColorExpr& other) const { - float tmp[4]; - tmp[0] = fColor[0] * other.fColor[0]; - tmp[1] = fColor[1] * other.fColor[1]; - tmp[2] = fColor[2] * other.fColor[2]; - tmp[3] = fColor[3] * other.fColor[3]; - - return MaskedColorExpr(tmp, fFlags & other.fFlags); - } - - MaskedColorExpr operator+(const MaskedColorExpr& other) const { - float tmp[4]; - tmp[0] = fColor[0] + other.fColor[0]; - tmp[1] = fColor[1] + other.fColor[1]; - tmp[2] = fColor[2] + other.fColor[2]; - tmp[3] = fColor[3] + other.fColor[3]; - - return MaskedColorExpr(tmp, fFlags & other.fFlags); - } - - MaskedColorExpr operator-(const MaskedColorExpr& other) const { - float tmp[4]; - tmp[0] = fColor[0] - other.fColor[0]; - tmp[1] = fColor[1] - other.fColor[1]; - tmp[2] = fColor[2] - other.fColor[2]; - tmp[3] = fColor[3] - other.fColor[3]; - - return MaskedColorExpr(tmp, fFlags & other.fFlags); - } - - MaskedColorExpr a() const { - uint32_t flags = (fFlags & kA_GrColorComponentFlag) ? kRGBA_GrColorComponentFlags : 0; - return MaskedColorExpr(fColor[3], flags); - } - - GrColor getColor() const { - return GrColorPackRGBA(color_component_to_int(fColor[0]), - color_component_to_int(fColor[1]), - color_component_to_int(fColor[2]), - color_component_to_int(fColor[3])); - } - - uint32_t getValidComponents() const { return fFlags; } - - typedef MaskedColorExpr AExpr; -private: - float fColor[4]; - uint32_t fFlags; -}; - -} - -void ModeColorFilterEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { - float inputColor[4]; - GrColorToRGBAFloat(inout->color(), inputColor); - float filterColor[4]; - GrColorToRGBAFloat(fColor, filterColor); - MaskedColorExpr result = - color_filter_expression(fMode, - MaskedColorExpr(filterColor, kRGBA_GrColorComponentFlags), - MaskedColorExpr(inputColor, inout->validFlags())); - - // Check if we will use the input color - SkXfermode::Coeff dstCoeff; - SkXfermode::Coeff srcCoeff; - SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); - GrInvariantOutput::ReadInput readInput = GrInvariantOutput::kWill_ReadInput; - // These could be calculated from the blend equation with template trickery.. - if (SkXfermode::kZero_Coeff == dstCoeff && - !GrBlendCoeffRefsDst(sk_blend_to_grblend(srcCoeff))) { - readInput = GrInvariantOutput::kWillNot_ReadInput; - } - inout->setToOther(result.getValidComponents(), result.getColor(), readInput); -} - -GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); -const GrFragmentProcessor* ModeColorFilterEffect::TestCreate(GrProcessorTestData* d) { - SkXfermode::Mode mode = SkXfermode::kDst_Mode; - while (SkXfermode::kDst_Mode == mode) { - mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU(0, SkXfermode::kLastCoeffMode)); - } - - // pick a random premul color - uint8_t alpha = d->fRandom->nextULessThan(256); - GrColor color = GrColorPackRGBA(d->fRandom->nextRangeU(0, alpha), - d->fRandom->nextRangeU(0, alpha), - d->fRandom->nextRangeU(0, alpha), - alpha); - return ModeColorFilterEffect::Create(color, mode); -} bool SkModeColorFilter::asFragmentProcessors(GrContext*, GrProcessorDataManager*, - SkTDArray<GrFragmentProcessor*>* array) const { + SkTDArray<const GrFragmentProcessor*>* array) const { if (SkXfermode::kDst_Mode != fMode) { - GrFragmentProcessor* frag = ModeColorFilterEffect::Create(SkColor2GrColor(fColor), fMode); - if (frag) { + SkAutoTUnref<const GrFragmentProcessor> constFP( + GrConstColorProcessor::Create(SkColor2GrColor(fColor), + GrConstColorProcessor::kIgnore_InputMode)); + const GrFragmentProcessor* fp = + GrXfermodeFragmentProcessor::CreateFromSrcProcessor(constFP, fMode); + if (fp) { +#ifdef SK_DEBUG + // With a solid color input this should always be able to compute the blended color + // (at least for coeff modes) + if (fMode <= SkXfermode::kLastCoeffMode) { + static SkRandom gRand; + GrInvariantOutput io(GrPremulColor(gRand.nextU()), kRGBA_GrColorComponentFlags, + false); + fp->computeInvariantOutput(&io); + SkASSERT(io.validFlags() == kRGBA_GrColorComponentFlags); + } +#endif if (array) { - *array->append() = frag; + *array->append() = fp; } else { - frag->unref(); - SkDEBUGCODE(frag = nullptr;) + fp->unref(); + SkDEBUGCODE(fp = nullptr;) } return true; } diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index 1eedef1343..6131b264e7 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -537,7 +537,7 @@ const GrFragmentProcessor* ColorMatrixEffect::TestCreate(GrProcessorTestData* d) } bool SkColorMatrixFilter::asFragmentProcessors(GrContext*, GrProcessorDataManager*, - SkTDArray<GrFragmentProcessor*>* array) const { + SkTDArray<const GrFragmentProcessor*>* array) const { GrFragmentProcessor* frag = ColorMatrixEffect::Create(fMatrix); if (frag) { if (array) { diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp index e161d170b2..7e16f3ac89 100644 --- a/src/effects/SkLumaColorFilter.cpp +++ b/src/effects/SkLumaColorFilter.cpp @@ -109,7 +109,7 @@ private: }; bool SkLumaColorFilter::asFragmentProcessors(GrContext*, GrProcessorDataManager*, - SkTDArray<GrFragmentProcessor*>* array) const { + SkTDArray<const GrFragmentProcessor*>* array) const { GrFragmentProcessor* frag = LumaColorFilterEffect::Create(); if (frag) { diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 1a2b1343b6..85e3a317bb 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -49,7 +49,7 @@ public: #if SK_SUPPORT_GPU bool asFragmentProcessors(GrContext*, GrProcessorDataManager*, - SkTDArray<GrFragmentProcessor*>*) const override; + SkTDArray<const GrFragmentProcessor*>*) const override; #endif void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override; @@ -521,7 +521,7 @@ bool ColorTableEffect::onIsEqual(const GrFragmentProcessor& other) const { void ColorTableEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { // If we kept the table in the effect then we could actually run known inputs through the // table. - uint8_t invalidateFlags = 0; + GrColorComponentFlags invalidateFlags = kNone_GrColorComponentFlags; if (fFlags & SkTable_ColorFilter::kR_Flag) { invalidateFlags |= kR_GrColorComponentFlag; } @@ -563,7 +563,7 @@ const GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d) (flags & (1 << 3)) ? luts[3] : nullptr )); - SkTDArray<GrFragmentProcessor*> array; + SkTDArray<const GrFragmentProcessor*> array; if (filter->asFragmentProcessors(d->fContext, d->fProcDataManager, &array)) { SkASSERT(1 == array.count()); // TableColorFilter only returns 1 return array[0]; @@ -573,7 +573,7 @@ const GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d) bool SkTable_ColorFilter::asFragmentProcessors(GrContext* context, GrProcessorDataManager*, - SkTDArray<GrFragmentProcessor*>* array) const { + SkTDArray<const GrFragmentProcessor*>* array) const { SkBitmap bitmap; this->asComponentTable(&bitmap); diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index 9ffbe62bdc..e357b0f23d 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -16,6 +16,7 @@ #include "GrContext.h" #include "GrDrawContext.h" #include "effects/GrTextureDomain.h" +#include "effects/GrSimpleTextureEffect.h" #include "SkGr.h" #endif @@ -153,7 +154,7 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, GrTexture* foregroundTex = foreground.getTexture(); GrContext* context = foregroundTex->getContext(); - GrFragmentProcessor* xferProcessor = nullptr; + const GrFragmentProcessor* xferFP = nullptr; GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; @@ -166,8 +167,11 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, } GrPaint paint; - if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, paint.getProcessorDataManager(), - backgroundTex)) { + SkMatrix bgMatrix; + bgMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()); + SkAutoTUnref<const GrFragmentProcessor> bgFP( + GrSimpleTextureEffect::Create(paint.getProcessorDataManager(), backgroundTex, bgMatrix)); + if (!fMode || !fMode->asFragmentProcessor(&xferFP, paint.getProcessorDataManager(), bgFP)) { // canFilterImageGPU() should've taken care of this SkASSERT(false); return false; @@ -190,7 +194,9 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, ); paint.addColorFragmentProcessor(foregroundDomain.get()); - paint.addColorFragmentProcessor(xferProcessor)->unref(); + if (xferFP) { + paint.addColorFragmentProcessor(xferFP)->unref(); + } SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); if (!drawContext) { |