diff options
author | Brian Salomon <bsalomon@google.com> | 2017-01-26 17:35:06 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-27 14:56:48 +0000 |
commit | 85eb4226a4cd8c10a0e3f3ba2f3a60efbb2dd61b (patch) | |
tree | 0f740e811d6360b4c5ae059e6a80431e8567ee43 /src/effects | |
parent | bcda1f07d5e1b8d080e0134a24c5bc1707ef3985 (diff) |
Start of rewrite of GrFragmentProcessor optimizations.
This adds a replacement for computeInvariantOutput buts does not use it yet. The replacement allows for three types of optimizations:
* known input color -> known output color for GrFP elimination
* tracking of whether all color processors modulate their input for the "tweak alpha" optimziation
* opaqueness tracking
This loses some of the generality of computInvariantOutput. It does not track the known output status of individual color components (other than opaque alpha). It does not track whether GrFragmentProcessors read their input color. It doesn't allow a processor that will receive non-constant output to advertise that it produces a constant output. These could probably be added back in the unlikely case that they prove valuable.
Unlike computeInvariantOutput the optimizations are decided at instantiation time and constant colors are expressed as GrColor4f rather than GrColor.
Change-Id: I684d3f9050693dde2d28154fa695e049ed8cf61a
Reviewed-on: https://skia-review.googlesource.com/7481
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/effects')
22 files changed, 150 insertions, 107 deletions
diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.cpp b/src/effects/GrAlphaThresholdFragmentProcessor.cpp index a259607444..8f9e45dc2b 100644 --- a/src/effects/GrAlphaThresholdFragmentProcessor.cpp +++ b/src/effects/GrAlphaThresholdFragmentProcessor.cpp @@ -32,6 +32,14 @@ sk_sp<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::Make( bounds)); } +inline GrFragmentProcessor::OptimizationFlags GrAlphaThresholdFragmentProcessor::OptFlags(float outerThreshold) { + if (outerThreshold >= 1.f) { + return kPreservesOpaqueInput_OptimizationFlag | kModulatesInput_OptimizationFlag; + } else { + return kModulatesInput_OptimizationFlag; + } +} + GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor( GrTexture* texture, sk_sp<GrColorSpaceXform> colorSpaceXform, @@ -39,16 +47,17 @@ GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor( float innerThreshold, float outerThreshold, const SkIRect& bounds) - : fInnerThreshold(innerThreshold) - , fOuterThreshold(outerThreshold) - , fImageCoordTransform(SkMatrix::I(), texture, GrSamplerParams::kNone_FilterMode) - , fImageTextureSampler(texture) - , fColorSpaceXform(std::move(colorSpaceXform)) - , fMaskCoordTransform(SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), - SkIntToScalar(-bounds.y())), - maskTexture, - GrSamplerParams::kNone_FilterMode) - , fMaskTextureSampler(maskTexture) { + : INHERITED(OptFlags(outerThreshold)) + , fInnerThreshold(innerThreshold) + , fOuterThreshold(outerThreshold) + , fImageCoordTransform(SkMatrix::I(), texture, GrSamplerParams::kNone_FilterMode) + , fImageTextureSampler(texture) + , fColorSpaceXform(std::move(colorSpaceXform)) + , fMaskCoordTransform( + SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y())), + maskTexture, + GrSamplerParams::kNone_FilterMode) + , fMaskTextureSampler(maskTexture) { this->initClassID<GrAlphaThresholdFragmentProcessor>(); this->addCoordTransform(&fImageCoordTransform); this->addTextureSampler(&fImageTextureSampler); diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.h b/src/effects/GrAlphaThresholdFragmentProcessor.h index f7a2491aee..f2c14c64bc 100644 --- a/src/effects/GrAlphaThresholdFragmentProcessor.h +++ b/src/effects/GrAlphaThresholdFragmentProcessor.h @@ -35,6 +35,8 @@ public: GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); } private: + static OptimizationFlags OptFlags(float outerThreshold); + GrAlphaThresholdFragmentProcessor(GrTexture* texture, sk_sp<GrColorSpaceXform> colorSpaceXform, GrTexture* maskTexture, diff --git a/src/effects/GrCircleBlurFragmentProcessor.cpp b/src/effects/GrCircleBlurFragmentProcessor.cpp index d3eb325b34..91d17d6e6c 100644 --- a/src/effects/GrCircleBlurFragmentProcessor.cpp +++ b/src/effects/GrCircleBlurFragmentProcessor.cpp @@ -88,10 +88,11 @@ GrCircleBlurFragmentProcessor::GrCircleBlurFragmentProcessor(const SkRect& circl float textureRadius, float solidRadius, GrTexture* blurProfile) - : fCircle(circle) - , fSolidRadius(solidRadius) - , fTextureRadius(textureRadius) - , fBlurProfileSampler(blurProfile, GrSamplerParams::kBilerp_FilterMode) { + : INHERITED(kModulatesInput_OptimizationFlag) + , fCircle(circle) + , fSolidRadius(solidRadius) + , fTextureRadius(textureRadius) + , fBlurProfileSampler(blurProfile, GrSamplerParams::kBilerp_FilterMode) { this->initClassID<GrCircleBlurFragmentProcessor>(); this->addTextureSampler(&fBlurProfileSampler); } diff --git a/src/effects/SkArithmeticImageFilter.cpp b/src/effects/SkArithmeticImageFilter.cpp index 8d80984bdf..a9a232554f 100644 --- a/src/effects/SkArithmeticImageFilter.cpp +++ b/src/effects/SkArithmeticImageFilter.cpp @@ -290,9 +290,15 @@ private: inout->setToUnknown(); } + // This could implement the const input -> const output optimization but it's unlikely to help. ArithmeticFP(float k1, float k2, float k3, float k4, bool enforcePMColor, sk_sp<GrFragmentProcessor> dst) - : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { + : INHERITED(kNone_OptimizationFlags) + , fK1(k1) + , fK2(k2) + , fK3(k3) + , fK4(k4) + , fEnforcePMColor(enforcePMColor) { this->initClassID<ArithmeticFP>(); SkASSERT(dst); SkDEBUGCODE(int dstIndex =) this->registerChildProcessor(std::move(dst)); diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index b53fc41dea..bf544077df 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -974,12 +974,13 @@ GrTexture* GrRectBlurEffect::CreateBlurProfileTexture(GrTextureProvider* texture return blurProfile; } -GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blurProfile, +GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture* blurProfile, GrSLPrecision precision) - : fRect(rect) - , fSigma(sigma) - , fBlurProfileSampler(blurProfile) - , fPrecision(precision) { + : INHERITED(kModulatesInput_OptimizationFlag) + , fRect(rect) + , fSigma(sigma) + , fBlurProfileSampler(blurProfile) + , fPrecision(precision) { this->initClassID<GrRectBlurEffect>(); this->addTextureSampler(&fBlurProfileSampler); } @@ -1206,10 +1207,11 @@ void GrRRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const inout->mulByUnknownSingleComponent(); } -GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTexture *ninePatchTexture) - : fRRect(rrect), - fSigma(sigma), - fNinePatchSampler(ninePatchTexture) { +GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTexture* ninePatchTexture) + : INHERITED(kModulatesInput_OptimizationFlag) + , fRRect(rrect) + , fSigma(sigma) + , fNinePatchSampler(ninePatchTexture) { this->initClassID<GrRRectBlurEffect>(); this->addTextureSampler(&fNinePatchSampler); } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index d838e1e347..cee47f4f3f 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -487,24 +487,26 @@ void GrDisplacementMapEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, } GrDisplacementMapEffect::GrDisplacementMapEffect( - SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, - SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, - const SkVector& scale, - GrTexture* displacement, - const SkMatrix& offsetMatrix, - GrTexture* color, - sk_sp<GrColorSpaceXform> colorSpaceXform, - const SkISize& colorDimensions) - : fDisplacementTransform(offsetMatrix, displacement, GrSamplerParams::kNone_FilterMode) - , fDisplacementSampler(displacement) - , fColorTransform(color, GrSamplerParams::kNone_FilterMode) - , fDomain(color, GrTextureDomain::MakeTexelDomain(SkIRect::MakeSize(colorDimensions)), - GrTextureDomain::kDecal_Mode) - , fColorSampler(color) - , fColorSpaceXform(std::move(colorSpaceXform)) - , fXChannelSelector(xChannelSelector) - , fYChannelSelector(yChannelSelector) - , fScale(scale) { + SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, + SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, + const SkVector& scale, + GrTexture* displacement, + const SkMatrix& offsetMatrix, + GrTexture* color, + sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkISize& colorDimensions) + : INHERITED(GrPixelConfigIsOpaque(color->config()) ? kPreservesOpaqueInput_OptimizationFlag + : kNone_OptimizationFlags) + , fDisplacementTransform(offsetMatrix, displacement, GrSamplerParams::kNone_FilterMode) + , fDisplacementSampler(displacement) + , fColorTransform(color, GrSamplerParams::kNone_FilterMode) + , fDomain(color, GrTextureDomain::MakeTexelDomain(SkIRect::MakeSize(colorDimensions)), + GrTextureDomain::kDecal_Mode) + , fColorSampler(color) + , fColorSpaceXform(std::move(colorSpaceXform)) + , fXChannelSelector(xChannelSelector) + , fYChannelSelector(yChannelSelector) + , fScale(scale) { this->initClassID<GrDisplacementMapEffect>(); this->addCoordTransform(&fDisplacementTransform); this->addTextureSampler(&fDisplacementSampler); diff --git a/src/effects/SkGaussianEdgeShader.cpp b/src/effects/SkGaussianEdgeShader.cpp index 7405fd14d9..5bd7dca124 100644 --- a/src/effects/SkGaussianEdgeShader.cpp +++ b/src/effects/SkGaussianEdgeShader.cpp @@ -63,11 +63,11 @@ private: class GaussianEdgeFP : public GrFragmentProcessor { public: - GaussianEdgeFP() { + GaussianEdgeFP() : INHERITED(kNone_OptimizationFlags) { this->initClassID<GaussianEdgeFP>(); // enable output of distance information for shape - fUsesDistanceVectorField = true; + this->setWillUseDistanceVectorField(); } class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { @@ -123,6 +123,8 @@ private: } bool onIsEqual(const GrFragmentProcessor& proc) const override { return true; } + + typedef GrFragmentProcessor INHERITED; }; //////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index da4dcb8bdf..3a03a1701c 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -1625,7 +1625,7 @@ SkString emitNormalFunc(BoundaryMode mode, } -class GrGLLightingEffect : public GrGLSLFragmentProcessor { +class GrGLLightingEffect : public GrGLSLFragmentProcessor { public: GrGLLightingEffect() : fLight(nullptr) { } virtual ~GrGLLightingEffect() { delete fLight; } @@ -1702,12 +1702,13 @@ GrLightingEffect::GrLightingEffect(GrTexture* texture, const SkMatrix& matrix, BoundaryMode boundaryMode, const SkIRect* srcBounds) - : INHERITED(texture, nullptr, SkMatrix::I()) - , fLight(light) - , fSurfaceScale(surfaceScale) - , fFilterMatrix(matrix) - , fBoundaryMode(boundaryMode) - , fDomain(create_domain(texture, srcBounds, GrTextureDomain::kDecal_Mode)) { + // Perhaps this could advertise the opaque or modulating optimizations? + : INHERITED(texture, nullptr, SkMatrix::I(), kNone_OptimizationFlags) + , fLight(light) + , fSurfaceScale(surfaceScale) + , fFilterMatrix(matrix) + , fBoundaryMode(boundaryMode) + , fDomain(create_domain(texture, srcBounds, GrTextureDomain::kDecal_Mode)) { fLight->ref(); } diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp index a9516af63d..1792437e34 100644 --- a/src/effects/SkLumaColorFilter.cpp +++ b/src/effects/SkLumaColorFilter.cpp @@ -98,7 +98,7 @@ public: }; private: - LumaColorFilterEffect() { + LumaColorFilterEffect() : INHERITED(kConstantOutputForConstantInput_OptimizationFlag) { this->initClassID<LumaColorFilterEffect>(); } @@ -117,6 +117,14 @@ private: // The output is always black. The alpha value for the color passed in is arbitrary. inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0)); } + GrColor4f constantOutputForConstantInput(GrColor4f input) const override { + float luma = SK_ITU_BT709_LUM_COEFF_R * input.fRGBA[0] + + SK_ITU_BT709_LUM_COEFF_G * input.fRGBA[1] + + SK_ITU_BT709_LUM_COEFF_B * input.fRGBA[2]; + return GrColor4f(0, 0, 0, luma); + } + + typedef GrFragmentProcessor INHERITED; }; sk_sp<GrFragmentProcessor> SkLumaColorFilter::asFragmentProcessor(GrContext*, SkColorSpace*) const { diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index c8b32aee70..49f4fdddc3 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -27,7 +27,6 @@ #include "../private/GrGLSL.h" class GrMagnifierEffect : public GrSingleTextureEffect { - public: static sk_sp<GrFragmentProcessor> Make(GrTexture* texture, sk_sp<GrColorSpaceXform> colorSpaceXform, @@ -71,14 +70,15 @@ private: float yInvZoom, float xInvInset, float yInvInset) - : INHERITED(texture, std::move(colorSpaceXform), SkMatrix::I()) - , fBounds(bounds) - , fXOffset(xOffset) - , fYOffset(yOffset) - , fXInvZoom(xInvZoom) - , fYInvZoom(yInvZoom) - , fXInvInset(xInvInset) - , fYInvInset(yInvInset) { + : INHERITED(texture, std::move(colorSpaceXform), SkMatrix::I(), + ModulationFlags(texture->config())) + , fBounds(bounds) + , fXOffset(xOffset) + , fYOffset(yOffset) + , fXInvZoom(xInvZoom) + , fYInvZoom(yInvZoom) + , fXInvInset(xInvInset) + , fYInvInset(yInvInset) { this->initClassID<GrMagnifierEffect>(); } diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 6e2a80507f..febde203d5 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -140,9 +140,7 @@ void SkDilateImageFilter::toString(SkString* str) const { * color. */ class GrMorphologyEffect : public Gr1DKernelEffect { - public: - enum MorphologyType { kErode_MorphologyType, kDilate_MorphologyType, @@ -327,9 +325,9 @@ GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, Direction direction, int radius, MorphologyType type) - : INHERITED(texture, direction, radius) - , fType(type) - , fUseRange(false) { + : INHERITED(texture, direction, radius, ModulationFlags(texture->config())) + , fType(type) + , fUseRange(false) { this->initClassID<GrMorphologyEffect>(); } @@ -338,9 +336,9 @@ GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, int radius, MorphologyType type, const float range[2]) - : INHERITED(texture, direction, radius) - , fType(type) - , fUseRange(true) { + : INHERITED(texture, direction, radius, ModulationFlags(texture->config())) + , fType(type) + , fUseRange(true) { this->initClassID<GrMorphologyEffect>(); fRange[0] = range[0]; fRange[1] = range[1]; diff --git a/src/effects/SkOverdrawColorFilter.cpp b/src/effects/SkOverdrawColorFilter.cpp index dea4f8b6de..243ef77cd0 100644 --- a/src/effects/SkOverdrawColorFilter.cpp +++ b/src/effects/SkOverdrawColorFilter.cpp @@ -59,7 +59,6 @@ public: static sk_sp<GrFragmentProcessor> Make(const SkPMColor* colors); const char* name() const override { return "Overdraw"; } - private: GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} @@ -105,7 +104,10 @@ sk_sp<GrFragmentProcessor> OverdrawFragmentProcessor::Make(const SkPMColor* colo return sk_sp<OverdrawFragmentProcessor>(new OverdrawFragmentProcessor(grColors)); } -OverdrawFragmentProcessor::OverdrawFragmentProcessor(const GrColor4f* colors) { +// This could implement the constant input -> constant output optimization, but we don't really +// care given how this is used. +OverdrawFragmentProcessor::OverdrawFragmentProcessor(const GrColor4f* colors) + : INHERITED(kNone_OptimizationFlags) { this->initClassID<OverdrawFragmentProcessor>(); memcpy(fColors, colors, SkOverdrawColorFilter::kNumColors * sizeof(GrColor4f)); } diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index 3798a407ac..450fcaa4ef 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -538,18 +538,18 @@ private: inout->setToUnknown(); } - GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type, - int numOctaves, bool stitchTiles, + GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type, int numOctaves, bool stitchTiles, SkPerlinNoiseShader::PaintingData* paintingData, GrTexture* permutationsTexture, GrTexture* noiseTexture, const SkMatrix& matrix) - : fType(type) - , fCoordTransform(matrix) - , fNumOctaves(numOctaves) - , fStitchTiles(stitchTiles) - , fPermutationsSampler(permutationsTexture) - , fNoiseSampler(noiseTexture) - , fPaintingData(paintingData) { + : INHERITED(kNone_OptimizationFlags) + , fType(type) + , fCoordTransform(matrix) + , fNumOctaves(numOctaves) + , fStitchTiles(stitchTiles) + , fPermutationsSampler(permutationsTexture) + , fNoiseSampler(noiseTexture) + , fPaintingData(paintingData) { this->initClassID<GrPerlinNoiseEffect>(); this->addTextureSampler(&fPermutationsSampler); this->addTextureSampler(&fNoiseSampler); diff --git a/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp b/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp index 5da3ed1eb1..223887bab9 100644 --- a/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp +++ b/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp @@ -207,9 +207,7 @@ public: }; RRectsGaussianEdgeFP(const SkRRect& first, const SkRRect& second, SkScalar radius) - : fFirst(first) - , fSecond(second) - , fRadius(radius) { + : INHERITED(kNone_OptimizationFlags), fFirst(first), fSecond(second), fRadius(radius) { this->initClassID<RRectsGaussianEdgeFP>(); fFirstMode = ComputeMode(fFirst); diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 1fd4c90eed..9198460c66 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -512,10 +512,11 @@ sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, SkBitmap b ColorTableEffect::ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atlas, int row, unsigned flags) - : fTextureSampler(texture) - , fFlags(flags) - , fAtlas(atlas) - , fRow(row) { + : INHERITED(kNone_OptimizationFlags) // Not bothering with table-specific optimizations. + , fTextureSampler(texture) + , fFlags(flags) + , fAtlas(atlas) + , fRow(row) { this->initClassID<ColorTableEffect>(); this->addTextureSampler(&fTextureSampler); } diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index b1d3e13a46..9a3438efe0 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -1572,7 +1572,13 @@ void GrGradientEffect::GLSLProcessor::emitColor(GrGLSLFPFragmentBuilder* fragBui ///////////////////////////////////////////////////////////////////// -GrGradientEffect::GrGradientEffect(const CreateArgs& args) { +inline GrFragmentProcessor::OptimizationFlags GrGradientEffect::OptFlags(bool isOpaque) { + return isOpaque ? kPreservesOpaqueInput_OptimizationFlag | kModulatesInput_OptimizationFlag + : kModulatesInput_OptimizationFlag; +} + +GrGradientEffect::GrGradientEffect(const CreateArgs& args, bool isOpaque) + : INHERITED(OptFlags(isOpaque)) { const SkGradientShaderBase& shader(*args.fShader); fIsOpaque = shader.isOpaque(); diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index 48ccbd50d0..6f46698eba 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -352,8 +352,6 @@ public: class GLSLProcessor; - GrGradientEffect(const CreateArgs&); - virtual ~GrGradientEffect(); bool useAtlas() const { return SkToBool(-1 != fRow); } @@ -402,6 +400,8 @@ public: } protected: + GrGradientEffect(const CreateArgs&, bool isOpaque); + /** Helper struct that stores (and populates) parameters to construct a random gradient. If fUseColors4f is true, then the SkColor4f factory should be called, with fColors4f and fColorSpace. Otherwise, the SkColor factory should be called, with fColors. fColorCount @@ -430,6 +430,8 @@ protected: const GrCoordTransform& getCoordTransform() const { return fCoordTransform; } private: + static OptimizationFlags OptFlags(bool isOpaque); + // If we're in legacy mode, then fColors will be populated. If we're gamma-correct, then // fColors4f and fColorSpaceXform will be populated. SkTDArray<SkColor> fColors; diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index aab1ac787a..07418e8010 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -426,8 +426,7 @@ public: const char* name() const override { return "Linear Gradient"; } private: - GrLinearGradient(const CreateArgs& args) - : INHERITED(args) { + GrLinearGradient(const CreateArgs& args) : INHERITED(args, args.fShader->colorsAreOpaque()) { this->initClassID<GrLinearGradient>(); } diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp index 887410aa96..4eb3e6d93a 100644 --- a/src/effects/gradients/SkRadialGradient.cpp +++ b/src/effects/gradients/SkRadialGradient.cpp @@ -256,8 +256,7 @@ public: const char* name() const override { return "Radial Gradient"; } private: - GrRadialGradient(const CreateArgs& args) - : INHERITED(args) { + GrRadialGradient(const CreateArgs& args) : INHERITED(args, args.fShader->colorsAreOpaque()) { this->initClassID<GrRadialGradient>(); } diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 64778c3a54..7e93a21de4 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -138,8 +138,7 @@ public: const char* name() const override { return "Sweep Gradient"; } private: - GrSweepGradient(const CreateArgs& args) - : INHERITED(args) { + GrSweepGradient(const CreateArgs& args) : INHERITED(args, args.fShader->colorsAreOpaque()) { this->initClassID<GrSweepGradient>(); } diff --git a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp index 5f26dcdb13..75b1cf7090 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp @@ -92,7 +92,7 @@ private: } Edge2PtConicalEffect(const CreateArgs& args) - : INHERITED(args) { + : INHERITED(args, false /* opaque: draws transparent black outside of the cone. */) { const SkTwoPointConicalGradient& shader = *static_cast<const SkTwoPointConicalGradient*>(args.fShader); fCenterX1 = shader.getCenterX1(); @@ -398,10 +398,15 @@ private: this->fIsFlipped == s.fIsFlipped); } + static bool IsFlipped(const CreateArgs& args) { + // eww. + return static_cast<const SkTwoPointConicalGradient*>(args.fShader)->isFlippedGrad(); + } + FocalOutside2PtConicalEffect(const CreateArgs& args, SkScalar focalX) - : INHERITED(args) - , fFocalX(focalX) - , fIsFlipped(static_cast<const SkTwoPointConicalGradient*>(args.fShader)->isFlippedGrad()) { + : INHERITED(args, false /* opaque: draws transparent black outside of the cone. */) + , fFocalX(focalX) + , fIsFlipped(IsFlipped(args)) { this->initClassID<FocalOutside2PtConicalEffect>(); } @@ -413,7 +418,7 @@ private: typedef GrGradientEffect INHERITED; }; -class FocalOutside2PtConicalEffect::GLSLFocalOutside2PtConicalProcessor +class FocalOutside2PtConicalEffect::GLSLFocalOutside2PtConicalProcessor : public GrGradientEffect::GLSLProcessor { public: GLSLFocalOutside2PtConicalProcessor(const GrProcessor&); @@ -606,7 +611,7 @@ private: } FocalInside2PtConicalEffect(const CreateArgs& args, SkScalar focalX) - : INHERITED(args), fFocalX(focalX) { + : INHERITED(args, args.fShader->colorsAreOpaque()), fFocalX(focalX) { this->initClassID<FocalInside2PtConicalEffect>(); } @@ -847,7 +852,7 @@ private: } CircleInside2PtConicalEffect(const CreateArgs& args, const CircleConicalInfo& info) - : INHERITED(args), fInfo(info) { + : INHERITED(args, args.fShader->colorsAreOpaque()), fInfo(info) { this->initClassID<CircleInside2PtConicalEffect>(); } @@ -1064,7 +1069,8 @@ private: } CircleOutside2PtConicalEffect(const CreateArgs& args, const CircleConicalInfo& info) - : INHERITED(args), fInfo(info) { + : INHERITED(args, false /* opaque: draws transparent black outside of the cone. */) + , fInfo(info) { this->initClassID<CircleOutside2PtConicalEffect>(); const SkTwoPointConicalGradient& shader = *static_cast<const SkTwoPointConicalGradient*>(args.fShader); diff --git a/src/effects/shadows/SkAmbientShadowMaskFilter.cpp b/src/effects/shadows/SkAmbientShadowMaskFilter.cpp index d92a7b548c..e7d8d31302 100755 --- a/src/effects/shadows/SkAmbientShadowMaskFilter.cpp +++ b/src/effects/shadows/SkAmbientShadowMaskFilter.cpp @@ -140,9 +140,7 @@ void SkAmbientShadowMaskFilterImpl::flatten(SkWriteBuffer& buffer) const { // class ShadowEdgeFP : public GrFragmentProcessor { public: - ShadowEdgeFP() { - this->initClassID<ShadowEdgeFP>(); - } + ShadowEdgeFP() : INHERITED(kNone_OptimizationFlags) { this->initClassID<ShadowEdgeFP>(); } class GLSLShadowEdgeFP : public GrGLSLFragmentProcessor { public: @@ -179,6 +177,8 @@ private: } bool onIsEqual(const GrFragmentProcessor& proc) const override { return true; } + + typedef GrFragmentProcessor INHERITED; }; /////////////////////////////////////////////////////////////////////////////////////////////////// |