From: egdaniel Date: Wed, 12 Nov 2014 16:35:25 +0000 (-0800) Subject: Move GrInvariantOutput out of GrProcessor and into its own class. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~4931 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=605dd0fbce9dbb2a0d3313e13e161f2bd54870d7;p=platform%2Fupstream%2FlibSkiaSharp.git Move GrInvariantOutput out of GrProcessor and into its own class. This will help with the ability to subclass, add to, etc. GrInvariantOutput. Also it was simply getting a little too big to be a "supporting" subclass BUG=skia: Review URL: https://codereview.chromium.org/699943003 --- diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index 7b84365..2cf380b 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -20,6 +20,7 @@ '<(skia_include_path)/gpu/GrFragmentProcessor.h', '<(skia_include_path)/gpu/GrGlyph.h', '<(skia_include_path)/gpu/GrGpuResource.h', + '<(skia_include_path)/gpu/GrInvariantOutput.h', '<(skia_include_path)/gpu/GrPaint.h', '<(skia_include_path)/gpu/GrPathRendererChain.h', '<(skia_include_path)/gpu/GrProcessor.h', @@ -91,6 +92,7 @@ '<(skia_src_path)/gpu/GrGpuResource.cpp', '<(skia_src_path)/gpu/GrGpuFactory.cpp', '<(skia_src_path)/gpu/GrIndexBuffer.h', + '<(skia_src_path)/gpu/GrInvariantOutput.cpp', '<(skia_src_path)/gpu/GrInOrderDrawBuffer.cpp', '<(skia_src_path)/gpu/GrInOrderDrawBuffer.h', '<(skia_src_path)/gpu/GrLayerCache.cpp', diff --git a/include/gpu/GrInvariantOutput.h b/include/gpu/GrInvariantOutput.h new file mode 100644 index 0000000..8f38d1f --- /dev/null +++ b/include/gpu/GrInvariantOutput.h @@ -0,0 +1,148 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrInvariantOutput_DEFINED +#define GrInvariantOutput_DEFINED + +#include "GrColor.h" + +class GrInvariantOutput { +public: + GrInvariantOutput(GrColor color, GrColorComponentFlags flags, bool isSingleComponent) + : fColor(color), fValidFlags(flags), fIsSingleComponent(isSingleComponent), + fNonMulStageFound(false), fWillUseInputColor(true) {} + + virtual ~GrInvariantOutput() {} + + enum ReadInput { + kWill_ReadInput, + kWillNot_ReadInput, + }; + + void mulByUnknownOpaqueColor() { + if (this->isOpaque()) { + fValidFlags = kA_GrColorComponentFlag; + fIsSingleComponent = false; + } else { + // Since the current state is not opaque we no longer care if the color being + // multiplied is opaque. + this->mulByUnknownColor(); + } + } + + void mulByUnknownColor() { + if (this->hasZeroAlpha()) { + this->internalSetToTransparentBlack(); + } else { + this->internalSetToUnknown(); + } + } + + void mulByUnknownAlpha() { + if (this->hasZeroAlpha()) { + this->internalSetToTransparentBlack(); + } else { + // We don't need to change fIsSingleComponent in this case + fValidFlags = 0; + } + } + + void mulByKnownAlpha(uint8_t alpha) { + if (this->hasZeroAlpha() || 0 == alpha) { + this->internalSetToTransparentBlack(); + } else { + if (alpha != 255) { + // Multiply color by alpha + fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor), alpha), + SkMulDiv255Round(GrColorUnpackG(fColor), alpha), + SkMulDiv255Round(GrColorUnpackB(fColor), alpha), + SkMulDiv255Round(GrColorUnpackA(fColor), alpha)); + } + } + } + + void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { + fValidFlags &= ~invalidateFlags; + fIsSingleComponent = false; + fNonMulStageFound = true; + if (kWillNot_ReadInput == readsInput) { + fWillUseInputColor = false; + } + } + + void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { + fValidFlags = validFlags; + fColor = color; + fIsSingleComponent = false; + fNonMulStageFound = true; + if (kWillNot_ReadInput == readsInput) { + fWillUseInputColor = false; + } + } + + void setToUnknown(ReadInput readsInput) { + this->internalSetToUnknown(); + fNonMulStageFound= true; + if (kWillNot_ReadInput == readsInput) { + fWillUseInputColor = false; + } + } + + bool isOpaque() const { + return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(fColor)); + } + + bool isSolidWhite() const { + return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor); + } + + GrColor color() const { return fColor; } + uint8_t validFlags() const { return fValidFlags; } + + bool willUseInputColor() const { return fWillUseInputColor; } + void resetWillUseInputColor() { fWillUseInputColor = true; } + + void resetNonMulStageFound() { fNonMulStageFound = false; } + + /** + * If isSingleComponent is true, then the flag values for r, g, b, and a must all be the + * same. If the flags are all set then all color components must be equal. + */ + SkDEBUGCODE(void validate() const;) + +protected: + GrColor fColor; + uint32_t fValidFlags; + bool fIsSingleComponent; + bool fNonMulStageFound; + bool fWillUseInputColor; + +private: + void internalSetToTransparentBlack() { + fValidFlags = kRGBA_GrColorComponentFlags; + fColor = 0; + fIsSingleComponent = true; + } + + void internalSetToUnknown() { + fValidFlags = 0; + fIsSingleComponent = false; + } + + bool hasZeroAlpha() const { + return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpackA(fColor)); + } + + SkDEBUGCODE(bool colorComponentsAllEqual() const;) + /** + * If alpha is valid, check that any valid R,G,B values are <= A + */ + SkDEBUGCODE(bool validPreMulColor() const;) +}; + +#endif + diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h index 96ce288..2012375 100644 --- a/include/gpu/GrProcessor.h +++ b/include/gpu/GrProcessor.h @@ -17,6 +17,7 @@ class GrContext; class GrCoordTransform; +class GrInvariantOutput; /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be immutable: after being constructed, their fields may not change. @@ -31,137 +32,6 @@ public: virtual ~GrProcessor(); - struct InvariantOutput{ - InvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false), - fNonMulStageFound(false), fWillUseInputColor(true) {} - - enum ReadInput { - kWill_ReadInput, - kWillNot_ReadInput, - }; - - void mulByUnknownOpaqueColor() { - if (this->isOpaque()) { - fValidFlags = kA_GrColorComponentFlag; - fIsSingleComponent = false; - } else { - // Since the current state is not opaque we no longer care if the color being - // multiplied is opaque. - this->mulByUnknownColor(); - } - } - - void mulByUnknownColor() { - if (this->hasZeroAlpha()) { - this->internalSetToTransparentBlack(); - } else { - this->internalSetToUnknown(); - } - } - - void mulByUnknownAlpha() { - if (this->hasZeroAlpha()) { - this->internalSetToTransparentBlack(); - } else { - // We don't need to change fIsSingleComponent in this case - fValidFlags = 0; - } - } - - void mulByKnownAlpha(uint8_t alpha) { - if (this->hasZeroAlpha() || 0 == alpha) { - this->internalSetToTransparentBlack(); - } else { - if (alpha != 255) { - // Multiply color by alpha - fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor), alpha), - SkMulDiv255Round(GrColorUnpackG(fColor), alpha), - SkMulDiv255Round(GrColorUnpackB(fColor), alpha), - SkMulDiv255Round(GrColorUnpackA(fColor), alpha)); - } - } - } - - void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { - fValidFlags &= ~invalidateFlags; - fIsSingleComponent = false; - if (kWillNot_ReadInput == readsInput) { - fWillUseInputColor = false; - } - } - - void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { - fValidFlags = validFlags; - fColor = color; - fIsSingleComponent = false; - fNonMulStageFound = true; - if (kWillNot_ReadInput == readsInput) { - fWillUseInputColor = false; - } - } - - void setToUnknown(ReadInput readsInput) { - this->internalSetToUnknown(); - fNonMulStageFound= true; - if (kWillNot_ReadInput == readsInput) { - fWillUseInputColor = false; - } - } - - bool isOpaque() const { - return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(fColor)); - } - - bool isSolidWhite() const { - return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor); - } - - GrColor color() const { return fColor; } - uint8_t validFlags() const { return fValidFlags; } - - /** - * If isSingleComponent is true, then the flag values for r, g, b, and a must all be the - * same. If the flags are all set then all color components must be equal. - */ - SkDEBUGCODE(void validate() const;) - - private: - void internalSetToTransparentBlack() { - fValidFlags = kRGBA_GrColorComponentFlags; - fColor = 0; - fIsSingleComponent = true; - } - - void internalSetToUnknown() { - fValidFlags = 0; - fIsSingleComponent = false; - } - - bool hasZeroAlpha() const { - return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpackA(fColor)); - } - - SkDEBUGCODE(bool colorComponentsAllEqual() const;) - /** - * If alpha is valid, check that any valid R,G,B values are <= A - */ - SkDEBUGCODE(bool validPreMulColor() const;) - - // Friended class that have "controller" code which loop over stages calling - // computeInvarianteOutput(). These controllers may need to manually adjust the internal - // members of InvariantOutput - friend class GrDrawState; - friend class GrOptDrawState; - friend class GrPaint; - friend class GrProcessor; - - GrColor fColor; - uint32_t fValidFlags; - bool fIsSingleComponent; - bool fNonMulStageFound; - bool fWillUseInputColor; - }; - /** * This function is used to perform optimizations. When called the invarientOuput param * indicate whether the input components to this processor in the FS will have known values. @@ -170,13 +40,7 @@ public: * inout to indicate known values of its output. A component of the color member only has * meaning if the corresponding bit in validFlags is set. */ - void computeInvariantOutput(InvariantOutput* inout) const { - inout->fWillUseInputColor = true; - this->onComputeInvariantOutput(inout); -#ifdef SK_DEBUG - inout->validate(); -#endif - } + void computeInvariantOutput(GrInvariantOutput* inout) const; /** This object, besides creating back-end-specific helper objects, is used for run-time-type- identification. The factory should be an instance of templated class, @@ -247,11 +111,10 @@ protected: void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } private: - /** * Subclass implements this to support getConstantColorComponents(...). */ - virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; bool fWillReadFragmentPosition; diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp index 0cc120d..36be29e 100644 --- a/src/core/SkXfermode.cpp +++ b/src/core/SkXfermode.cpp @@ -777,6 +777,7 @@ void SkXfermode::xferA8(SkAlpha* SK_RESTRICT dst, #include "GrFragmentProcessor.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" #include "GrProcessorUnitTest.h" #include "GrTBackendProcessorFactory.h" #include "gl/GrGLProcessor.h" @@ -1211,8 +1212,8 @@ private: return fMode == s.fMode; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { - inout->setToUnknown(InvariantOutput::kWill_ReadInput); + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { + inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); } SkXfermode::Mode fMode; diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index c3ad87a..bff8772 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -49,6 +49,7 @@ SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, #include "GrContext.h" #include "GrCoordTransform.h" #include "GrFragmentProcessor.h" +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "GrTBackendProcessorFactory.h" @@ -102,7 +103,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GR_DECLARE_FRAGMENT_PROCESSOR_TEST; @@ -227,7 +228,7 @@ bool AlphaThresholdEffect::onIsEqual(const GrFragmentProcessor& sBase) const { this->fOuterThreshold == s.fOuterThreshold); } -void AlphaThresholdEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void AlphaThresholdEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { if (GrPixelConfigIsOpaque(this->texture(0)->config()) && fOuterThreshold >= 1.f) { inout->mulByUnknownOpaqueColor(); } else { diff --git a/src/effects/SkArithmeticMode.cpp b/src/effects/SkArithmeticMode.cpp index 3048aec..13db532 100644 --- a/src/effects/SkArithmeticMode.cpp +++ b/src/effects/SkArithmeticMode.cpp @@ -14,6 +14,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "GrTBackendProcessorFactory.h" @@ -298,7 +299,7 @@ public: private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrArithmeticEffect(float k1, float k2, float k3, float k4, bool enforcePMColor, GrTexture* background); @@ -343,9 +344,9 @@ const GrBackendFragmentProcessorFactory& GrArithmeticEffect::getFactory() const return GrTBackendFragmentProcessorFactory::getInstance(); } -void GrArithmeticEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrArithmeticEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { // TODO: optimize this - inout->setToUnknown(InvariantOutput::kWill_ReadInput); + inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index 13bc43c..1612e3d 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -21,6 +21,7 @@ #include "GrContext.h" #include "GrTexture.h" #include "GrFragmentProcessor.h" +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "effects/GrSimpleTextureEffect.h" @@ -652,7 +653,7 @@ private: GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile); virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; static bool CreateBlurProfileTexture(GrContext *context, float sigma, GrTexture **blurProfileTexture); @@ -825,7 +826,7 @@ bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& sBase) const { return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); } -void GrRectBlurEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } @@ -903,7 +904,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; SkRRect fRRect; float fSigma; @@ -988,7 +989,7 @@ GrFragmentProcessor* GrRRectBlurEffect::Create(GrContext* context, float sigma, return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); } -void GrRRectBlurEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrRRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp index d9d6841..751d974 100644 --- a/src/effects/SkColorCubeFilter.cpp +++ b/src/effects/SkColorCubeFilter.cpp @@ -14,6 +14,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "GrTBackendProcessorFactory.h" @@ -192,6 +193,7 @@ void SkColorCubeFilter::toString(SkString* str) const { /////////////////////////////////////////////////////////////////////////////// #if SK_SUPPORT_GPU + class GrColorCubeEffect : public GrFragmentProcessor { public: static GrFragmentProcessor* Create(GrTexture* colorCube) { @@ -205,7 +207,7 @@ public: static const char* Name() { return "ColorCube"; } - virtual void onComputeInvariantOutput(GrProcessor::InvariantOutput*) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput*) const SK_OVERRIDE; class GLProcessor : public GrGLFragmentProcessor { public: @@ -258,8 +260,8 @@ const GrBackendFragmentProcessorFactory& GrColorCubeEffect::getFactory() const { return GrTBackendFragmentProcessorFactory::getInstance(); } -void GrColorCubeEffect::onComputeInvariantOutput(InvariantOutput* inout) const { - inout->setToUnknown(InvariantOutput::kWill_ReadInput); +void GrColorCubeEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { + inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/SkColorFilters.cpp b/src/effects/SkColorFilters.cpp index 4c6474a..0f6018f 100644 --- a/src/effects/SkColorFilters.cpp +++ b/src/effects/SkColorFilters.cpp @@ -124,6 +124,7 @@ SkFlattenable* SkModeColorFilter::CreateProc(SkReadBuffer& buffer) { #if SK_SUPPORT_GPU #include "GrBlend.h" #include "GrFragmentProcessor.h" +#include "GrInvariantOutput.h" #include "GrProcessorUnitTest.h" #include "GrTBackendProcessorFactory.h" #include "gl/GrGLProcessor.h" @@ -281,7 +282,7 @@ private: return fMode == s.fMode && fColor == s.fColor; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; SkXfermode::Mode fMode; GrColor fColor; @@ -372,7 +373,7 @@ private: } -void ModeColorFilterEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void ModeColorFilterEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { float inputColor[4]; GrColorToRGBAFloat(inout->color(), inputColor); float filterColor[4]; @@ -386,11 +387,11 @@ void ModeColorFilterEffect::onComputeInvariantOutput(InvariantOutput* inout) con SkXfermode::Coeff dstCoeff; SkXfermode::Coeff srcCoeff; SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); - InvariantOutput::ReadInput readInput = InvariantOutput::kWill_ReadInput; + 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 = InvariantOutput::kWillNot_ReadInput; + readInput = GrInvariantOutput::kWillNot_ReadInput; } inout->setToOther(result.getValidComponents(), result.getColor(), readInput); } diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index 844a376..f8b9101 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -333,6 +333,7 @@ bool SkColorMatrixFilter::asColorMatrix(SkScalar matrix[20]) const { #if SK_SUPPORT_GPU #include "GrFragmentProcessor.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" @@ -426,7 +427,7 @@ private: return cme.fMatrix == fMatrix; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { // We only bother to check whether the alpha channel will be constant. If SkColorMatrix had // type flags it might be worth checking the other components. @@ -453,7 +454,7 @@ private: // then we can't know the final result. if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) { if (!(inout->validFlags() & kRGBAFlags[i])) { - inout->setToUnknown(InvariantOutput::kWill_ReadInput); + inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); return; } else { uint32_t component = (inout->color() >> kShifts[i]) & 0xFF; @@ -468,7 +469,7 @@ private: // result if the matrix could over/underflow for any component? inout->setToOther(kA_GrColorComponentFlag, static_cast(SkScalarPin(outputA, 0, 255)) << GrColor_SHIFT_A, - InvariantOutput::kWill_ReadInput); + GrInvariantOutput::kWill_ReadInput); } SkColorMatrix fMatrix; diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 62e041a..d2d85814 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -13,6 +13,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "GrTBackendProcessorFactory.h" @@ -354,7 +355,7 @@ public: private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, @@ -489,13 +490,13 @@ const GrBackendFragmentProcessorFactory& GrDisplacementMapEffect::getFactory() c return GrTBackendFragmentProcessorFactory::getInstance(); } -void GrDisplacementMapEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { // Any displacement offset bringing a pixel out of bounds will output a color of (0,0,0,0), // so the only way we'd get a constant alpha is if the input color image has a constant alpha // and no displacement offset push any texture coordinates out of bounds OR if the constant // alpha is 0. Since this isn't trivial to compute at this point, let's assume the output is // not of constant color when a displacement effect is applied. - inout->setToUnknown(InvariantOutput::kWillNot_ReadInput); + inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 24bfbbd..5baae4a 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -19,6 +19,7 @@ #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "GrFragmentProcessor.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" class GrGLDiffuseLightingEffect; @@ -353,7 +354,7 @@ public: protected: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { // lighting shaders are complicated. We just throw up our hands. inout->mulByUnknownColor(); } diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp index b1b2ffd..f3e6e78 100644 --- a/src/effects/SkLumaColorFilter.cpp +++ b/src/effects/SkLumaColorFilter.cpp @@ -14,6 +14,7 @@ #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "GrContext.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" #endif @@ -111,10 +112,10 @@ public: private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE { return true; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { // The output is always black. The alpha value for the color passed in is arbitrary. inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0), - InvariantOutput::kWill_ReadInput); + GrInvariantOutput::kWill_ReadInput); } }; diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index e69ac58..35f39c3 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -19,6 +19,7 @@ #include "gl/builders/GrGLProgramBuilder.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" class GrGLMagnifierEffect; @@ -74,7 +75,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GR_DECLARE_FRAGMENT_PROCESSOR_TEST; @@ -226,7 +227,7 @@ bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) const { this->fYInvInset == s.fYInvInset); } -void GrMagnifierEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrMagnifierEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { this->updateInvariantOutputForModulation(inout); } diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 72c98dd..6f821bd 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -14,6 +14,7 @@ #include "SkMorphology_opts.h" #if SK_SUPPORT_GPU #include "GrContext.h" +#include "GrInvariantOutput.h" #include "GrTexture.h" #include "GrTBackendProcessorFactory.h" #include "gl/GrGLProcessor.h" @@ -317,7 +318,7 @@ protected: private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); @@ -455,7 +456,7 @@ bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { this->type() == s.type()); } -void GrMorphologyEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { // This is valid because the color components of the result of the kernel all come // exactly from existing values in the source texture. this->updateInvariantOutputForModulation(inout); diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index 3ce1060..5f400b5 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -17,6 +17,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "GrTBackendProcessorFactory.h" @@ -583,8 +584,8 @@ private: fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataInit; } - void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { - inout->setToUnknown(InvariantOutput::kWillNot_ReadInput); + void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { + inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); } GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type, diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index e4daf20..ac12327 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -276,6 +276,7 @@ bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const { #if SK_SUPPORT_GPU #include "GrFragmentProcessor.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" #include "SkGr.h" #include "effects/GrTextureStripAtlas.h" @@ -302,7 +303,7 @@ public: private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atlas, int row, unsigned flags); @@ -469,7 +470,7 @@ bool ColorTableEffect::onIsEqual(const GrFragmentProcessor& other) const { return fRow == that.fRow; } -void ColorTableEffect::onComputeInvariantOutput(InvariantOutput* inout) 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; @@ -485,7 +486,7 @@ void ColorTableEffect::onComputeInvariantOutput(InvariantOutput* inout) const { if (fFlags & SkTable_ColorFilter::kA_Flag) { invalidateFlags |= kA_GrColorComponentFlag; } - inout->invalidateComponents(invalidateFlags, InvariantOutput::kWill_ReadInput); + inout->invalidateComponents(invalidateFlags, GrInvariantOutput::kWill_ReadInput); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 0d17308..b1a3bf0 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -945,6 +945,7 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END #if SK_SUPPORT_GPU #include "effects/GrTextureStripAtlas.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" #include "gl/builders/GrGLProgramBuilder.h" #include "SkGr.h" @@ -1208,7 +1209,7 @@ bool GrGradientEffect::onIsEqual(const GrFragmentProcessor& processor) const { return false; } -void GrGradientEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrGradientEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { if (fIsOpaque) { inout->mulByUnknownOpaqueColor(); } else { diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index 15f94d4..20f8112 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -303,6 +303,7 @@ static inline int next_dither_toggle16(int toggle) { class GrFragmentStage; class GrBackendProcessorFactory; +class GrInvariantOutput; /* * The interpretation of the texture matrix depends on the sample mode. The @@ -375,7 +376,7 @@ protected: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; const GrCoordTransform& getCoordTransform() const { return fCoordTransform; } diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index 3325b1c..c3275c8 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -11,6 +11,7 @@ #include "GrContext.h" #include "GrDrawState.h" #include "GrDrawTargetCaps.h" +#include "GrInvariantOutput.h" #include "GrProcessor.h" #include "GrPathUtils.h" #include "GrTBackendProcessorFactory.h" @@ -586,7 +587,7 @@ private: return true; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp index 46196e2..e743ae9 100644 --- a/src/gpu/GrAARectRenderer.cpp +++ b/src/gpu/GrAARectRenderer.cpp @@ -7,6 +7,7 @@ #include "GrAARectRenderer.h" #include "GrGpu.h" +#include "GrInvariantOutput.h" #include "gl/builders/GrGLProgramBuilder.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLGeometryProcessor.h" diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp index 8e93f37..1258d59 100644 --- a/src/gpu/GrDefaultGeoProcFactory.cpp +++ b/src/gpu/GrDefaultGeoProcFactory.cpp @@ -10,6 +10,7 @@ #include "gl/builders/GrGLProgramBuilder.h" #include "gl/GrGLGeometryProcessor.h" #include "GrDrawState.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" /* @@ -62,7 +63,7 @@ private: return true; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp index 296893c..23ebea6 100644 --- a/src/gpu/GrDrawState.cpp +++ b/src/gpu/GrDrawState.cpp @@ -7,6 +7,7 @@ #include "GrDrawState.h" +#include "GrInvariantOutput.h" #include "GrOptDrawState.h" #include "GrPaint.h" @@ -382,15 +383,17 @@ bool GrDrawState::hasSolidCoverage() const { return false; } - GrProcessor::InvariantOutput inout; - inout.fIsSingleComponent = true; + GrColor color; + GrColorComponentFlags flags; // Initialize to an unknown starting coverage if per-vertex coverage is specified. if (this->hasCoverageVertexAttribute()) { - inout.fValidFlags = 0; + color = 0; + flags = static_cast(0); } else { - inout.fColor = this->getCoverageColor(); - inout.fValidFlags = kRGBA_GrColorComponentFlags; + color = this->getCoverageColor(); + flags = kRGBA_GrColorComponentFlags; } + GrInvariantOutput inout(color, flags, true); // check the coverage output from the GP if (this->hasGeometryProcessor()) { @@ -687,22 +690,22 @@ GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, bool GrDrawState::srcAlphaWillBeOne() const { - GrProcessor::InvariantOutput inoutColor; - inoutColor.fIsSingleComponent = false; + GrColor color; + GrColorComponentFlags flags; // Check if per-vertex or constant color may have partial alpha if (this->hasColorVertexAttribute()) { if (fHints & kVertexColorsAreOpaque_Hint) { - inoutColor.fValidFlags = kA_GrColorComponentFlag; - inoutColor.fColor = 0xFF << GrColor_SHIFT_A; + flags = kA_GrColorComponentFlag; + color = 0xFF << GrColor_SHIFT_A; } else { - inoutColor.fValidFlags = 0; - // not strictly necessary but we get false alarms from tools about uninit. - inoutColor.fColor = 0; + flags = static_cast(0); + color = 0; } } else { - inoutColor.fValidFlags = kRGBA_GrColorComponentFlags; - inoutColor.fColor = this->getColor(); + flags = kRGBA_GrColorComponentFlags; + color = this->getColor(); } + GrInvariantOutput inoutColor(color, flags, false); // Run through the color stages for (int s = 0; s < this->numColorStages(); ++s) { @@ -714,15 +717,14 @@ bool GrDrawState::srcAlphaWillBeOne() const { if (this->isCoverageDrawing()) { // The shader generated for coverage drawing runs the full coverage computation and then // makes the shader output be the multiplication of color and coverage. We mirror that here. - GrProcessor::InvariantOutput inoutCoverage; - inoutCoverage.fIsSingleComponent = true; if (this->hasCoverageVertexAttribute()) { - inoutCoverage.fValidFlags = 0; - inoutCoverage.fColor = 0; // suppresses any warnings. + flags = static_cast(0); + color = 0; } else { - inoutCoverage.fValidFlags = kRGBA_GrColorComponentFlags; - inoutCoverage.fColor = this->getCoverageColor(); + flags = kRGBA_GrColorComponentFlags; + color = this->getCoverageColor(); } + GrInvariantOutput inoutCoverage(color, flags, true); if (this->hasGeometryProcessor()) { fGeometryProcessor->computeInvariantOutput(&inoutCoverage); diff --git a/src/gpu/GrInvariantOutput.cpp b/src/gpu/GrInvariantOutput.cpp new file mode 100644 index 0000000..6f9a9d1 --- /dev/null +++ b/src/gpu/GrInvariantOutput.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrInvariantOutput.h" + +#ifdef SK_DEBUG + +void GrInvariantOutput::validate() const { + if (fIsSingleComponent) { + SkASSERT(0 == fValidFlags || kRGBA_GrColorComponentFlags == fValidFlags); + if (kRGBA_GrColorComponentFlags == fValidFlags) { + SkASSERT(this->colorComponentsAllEqual()); + } + } + + SkASSERT(this->validPreMulColor()); + + // If we claim that we are not using the input color we must not be modulating the input. + SkASSERT(fNonMulStageFound || fWillUseInputColor); +} + +bool GrInvariantOutput::colorComponentsAllEqual() const { + unsigned colorA = GrColorUnpackA(fColor); + return(GrColorUnpackR(fColor) == colorA && + GrColorUnpackG(fColor) == colorA && + GrColorUnpackB(fColor) == colorA); +} + +bool GrInvariantOutput::validPreMulColor() const { + if (kA_GrColorComponentFlag & fValidFlags) { + float c[4]; + GrColorToRGBAFloat(fColor, c); + if (kR_GrColorComponentFlag & fValidFlags) { + if (c[0] > c[3]) { + return false; + } + } + if (kG_GrColorComponentFlag & fValidFlags) { + if (c[1] > c[3]) { + return false; + } + } + if (kB_GrColorComponentFlag & fValidFlags) { + if (c[2] > c[3]) { + return false; + } + } + } + return true; +} +#endif // end DEBUG + diff --git a/src/gpu/GrOptDrawState.cpp b/src/gpu/GrOptDrawState.cpp index 79eef0c..7d8b06c 100644 --- a/src/gpu/GrOptDrawState.cpp +++ b/src/gpu/GrOptDrawState.cpp @@ -11,6 +11,7 @@ #include "GrDrawState.h" #include "GrDrawTargetCaps.h" #include "GrGpu.h" +#include "GrInvariantOutput.h" GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, BlendOptFlags blendOptFlags, @@ -223,37 +224,38 @@ void GrOptDrawState::computeEffectiveColorStages(const GrDrawState& ds, int* firstColorStageIdx, uint8_t* fixedFunctionVAToRemove) { // Set up color and flags for ConstantColorComponent checks - GrProcessor::InvariantOutput inout; - inout.fIsSingleComponent = false; + GrColor color; + GrColorComponentFlags flags; if (!descInfo->hasColorVertexAttribute()) { - inout.fColor = ds.getColor(); - inout.fValidFlags = kRGBA_GrColorComponentFlags; + color = ds.getColor(); + flags = kRGBA_GrColorComponentFlags; } else { if (ds.vertexColorsAreOpaque()) { - inout.fColor = 0xFF << GrColor_SHIFT_A; - inout.fValidFlags = kA_GrColorComponentFlag; + color = 0xFF << GrColor_SHIFT_A; + flags = kA_GrColorComponentFlag; } else { - inout.fValidFlags = 0; + flags = static_cast(0); // not strictly necessary but we get false alarms from tools about uninit. - inout.fColor = 0; + color = 0; } } + GrInvariantOutput inout(color, flags, false); for (int i = 0; i < ds.numColorStages(); ++i) { const GrFragmentProcessor* fp = ds.getColorStage(i).getProcessor(); fp->computeInvariantOutput(&inout); - if (!inout.fWillUseInputColor) { + if (!inout.willUseInputColor()) { *firstColorStageIdx = i; descInfo->fInputColorIsUsed = false; } - if (kRGBA_GrColorComponentFlags == inout.fValidFlags) { + if (kRGBA_GrColorComponentFlags == inout.validFlags()) { *firstColorStageIdx = i + 1; - fColor = inout.fColor; + fColor = inout.color(); descInfo->fInputColorIsUsed = true; *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; // Since we are clearing all previous color stages we are in a state where we have found // zero stages that don't multiply the inputColor. - inout.fNonMulStageFound = false; + inout.resetNonMulStageFound(); } } } @@ -268,7 +270,7 @@ void GrOptDrawState::computeEffectiveCoverageStages(const GrDrawState& ds, // Don't do any optimizations on coverage stages. It should not be the case where we do not use // input coverage in an effect #ifdef OptCoverageStages - GrProcessor::InvariantOutput inout; + GrInvariantOutput inout; for (int i = 0; i < ds.numCoverageStages(); ++i) { const GrFragmentProcessor* fp = ds.getCoverageStage(i).getProcessor(); fp->computeInvariantOutput(&inout); diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index c06909d..2bb674a 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -17,6 +17,7 @@ #include "GrDrawState.h" #include "GrDrawTarget.h" #include "GrGpu.h" +#include "GrInvariantOutput.h" #include "SkRRect.h" #include "SkStrokeRec.h" @@ -144,7 +145,7 @@ private: return cee.fStroke == fStroke; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } @@ -286,7 +287,7 @@ private: return eee.fStroke == fStroke; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } @@ -451,7 +452,7 @@ private: return eee.fMode == fMode; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp index 56e8aa0..3663787 100644 --- a/src/gpu/GrPaint.cpp +++ b/src/gpu/GrPaint.cpp @@ -9,6 +9,7 @@ #include "GrPaint.h" #include "GrBlend.h" +#include "GrInvariantOutput.h" #include "effects/GrSimpleTextureEffect.h" void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { @@ -52,21 +53,18 @@ bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, // TODO: Share this implementation with GrDrawState - GrProcessor::InvariantOutput inout; - inout.fColor = 0xFFFFFFFF; - inout.fValidFlags = kRGBA_GrColorComponentFlags; - inout.fIsSingleComponent = true; + GrInvariantOutput inoutCoverage(0xFFFFFFFF, + kRGBA_GrColorComponentFlags, + true); int count = fCoverageStages.count(); for (int i = 0; i < count; ++i) { - fCoverageStages[i].getProcessor()->computeInvariantOutput(&inout); + fCoverageStages[i].getProcessor()->computeInvariantOutput(&inoutCoverage); } - if (!inout.isSolidWhite()) { + if (!inoutCoverage.isSolidWhite()) { return false; } - inout.fColor = fColor; - inout.fValidFlags = kRGBA_GrColorComponentFlags; - inout.fIsSingleComponent = false; + GrInvariantOutput inout(fColor, kRGBA_GrColorComponentFlags, false); count = fColorStages.count(); for (int i = 0; i < count; ++i) { fColorStages[i].getProcessor()->computeInvariantOutput(&inout); @@ -76,7 +74,7 @@ bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, GrBlendCoeff srcCoeff = fSrcBlendCoeff; GrBlendCoeff dstCoeff = fDstBlendCoeff; - GrSimplifyBlend(&srcCoeff, &dstCoeff, inout.fColor, inout.fValidFlags, + GrSimplifyBlend(&srcCoeff, &dstCoeff, inout.color(), inout.validFlags(), 0, 0, 0); bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff); @@ -89,8 +87,8 @@ bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, break; case kOne_GrBlendCoeff: - *solidColor = inout.fColor; - *solidColorKnownComponents = inout.fValidFlags; + *solidColor = inout.color(); + *solidColorKnownComponents = inout.validFlags(); break; // The src coeff should never refer to the src and if it refers to dst then opaque diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp index 3de1dcf..31f0004 100644 --- a/src/gpu/GrProcessor.cpp +++ b/src/gpu/GrProcessor.cpp @@ -9,6 +9,7 @@ #include "GrBackendProcessorFactory.h" #include "GrContext.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" #include "GrMemoryPool.h" #include "SkTLS.h" @@ -128,52 +129,13 @@ bool GrProcessor::hasSameTextureAccesses(const GrProcessor& that) const { return true; } +void GrProcessor::computeInvariantOutput(GrInvariantOutput* inout) const { + inout->resetWillUseInputColor(); + this->onComputeInvariantOutput(inout); #ifdef SK_DEBUG - -void GrProcessor::InvariantOutput::validate() const { - if (fIsSingleComponent) { - SkASSERT(0 == fValidFlags || kRGBA_GrColorComponentFlags == fValidFlags); - if (kRGBA_GrColorComponentFlags == fValidFlags) { - SkASSERT(this->colorComponentsAllEqual()); - } - } - - SkASSERT(this->validPreMulColor()); - - // If we claim that we are not using the input color we must not be modulating the input. - SkASSERT(fNonMulStageFound || fWillUseInputColor); -} - -bool GrProcessor::InvariantOutput::colorComponentsAllEqual() const { - unsigned colorA = GrColorUnpackA(fColor); - return(GrColorUnpackR(fColor) == colorA && - GrColorUnpackG(fColor) == colorA && - GrColorUnpackB(fColor) == colorA); -} - -bool GrProcessor::InvariantOutput::validPreMulColor() const { - if (kA_GrColorComponentFlag & fValidFlags) { - float c[4]; - GrColorToRGBAFloat(fColor, c); - if (kR_GrColorComponentFlag & fValidFlags) { - if (c[0] > c[3]) { - return false; - } - } - if (kG_GrColorComponentFlag & fValidFlags) { - if (c[1] > c[3]) { - return false; - } - } - if (kB_GrColorComponentFlag & fValidFlags) { - if (c[2] > c[3]) { - return false; - } - } - } - return true; + inout->validate(); +#endif } -#endif // end DEBUG /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrBezierEffect.h b/src/gpu/effects/GrBezierEffect.h index 5d2917d..9b71f7d 100644 --- a/src/gpu/effects/GrBezierEffect.h +++ b/src/gpu/effects/GrBezierEffect.h @@ -11,6 +11,7 @@ #include "GrDrawTargetCaps.h" #include "GrProcessor.h" #include "GrGeometryProcessor.h" +#include "GrInvariantOutput.h" #include "GrTypesPriv.h" /** @@ -101,7 +102,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } @@ -170,7 +171,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } @@ -241,7 +242,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp index 5ed8ece..ce7810d 100644 --- a/src/gpu/effects/GrBicubicEffect.cpp +++ b/src/gpu/effects/GrBicubicEffect.cpp @@ -7,7 +7,7 @@ #include "gl/builders/GrGLProgramBuilder.h" #include "GrBicubicEffect.h" - +#include "GrInvariantOutput.h" #define DS(x) SkDoubleToScalar(x) @@ -168,7 +168,7 @@ bool GrBicubicEffect::onIsEqual(const GrFragmentProcessor& sBase) const { fDomain == s.fDomain; } -void GrBicubicEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrBicubicEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { // FIXME: Perhaps we can do better. inout->mulByUnknownAlpha(); } diff --git a/src/gpu/effects/GrBicubicEffect.h b/src/gpu/effects/GrBicubicEffect.h index 642f7cf..8f11825 100644 --- a/src/gpu/effects/GrBicubicEffect.h +++ b/src/gpu/effects/GrBicubicEffect.h @@ -14,6 +14,7 @@ #include "GrTBackendProcessorFactory.h" class GrGLBicubicEffect; +class GrInvariantOutput; class GrBicubicEffect : public GrSingleTextureEffect { public: @@ -92,7 +93,7 @@ private: const SkMatrix &matrix, const SkRect& domain); virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; float fCoefficients[16]; GrTextureDomain fDomain; diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index edbd0b2..6f02f30 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -7,6 +7,7 @@ #include "GrConfigConversionEffect.h" #include "GrContext.h" +#include "GrInvariantOutput.h" #include "GrTBackendProcessorFactory.h" #include "GrSimpleTextureEffect.h" #include "gl/GrGLProcessor.h" @@ -125,7 +126,7 @@ bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& s) const { other.fPMConversion == fPMConversion; } -void GrConfigConversionEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrConfigConversionEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { this->updateInvariantOutputForModulation(inout); } diff --git a/src/gpu/effects/GrConfigConversionEffect.h b/src/gpu/effects/GrConfigConversionEffect.h index e1fd7d3..35b3b57 100644 --- a/src/gpu/effects/GrConfigConversionEffect.h +++ b/src/gpu/effects/GrConfigConversionEffect.h @@ -12,6 +12,7 @@ class GrFragmentStage; class GrGLConfigConversionEffect; +class GrInvariantOutput; /** * This class is used to perform config conversions. Clients may want to read/write data that is @@ -63,7 +64,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; bool fSwapRedAndBlue; PMConversion fPMConversion; diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp index c84b540..ff08eae 100644 --- a/src/gpu/effects/GrConvexPolyEffect.cpp +++ b/src/gpu/effects/GrConvexPolyEffect.cpp @@ -7,7 +7,7 @@ #include "gl/builders/GrGLProgramBuilder.h" #include "GrConvexPolyEffect.h" - +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLSL.h" #include "GrTBackendProcessorFactory.h" @@ -43,7 +43,7 @@ private: return fRect == aare.fRect; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { if (fRect.isEmpty()) { // An empty rect will have no coverage anywhere. inout->mulByKnownAlpha(0); @@ -326,7 +326,7 @@ GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType edgeType, co GrConvexPolyEffect::~GrConvexPolyEffect() {} -void GrConvexPolyEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/effects/GrConvexPolyEffect.h b/src/gpu/effects/GrConvexPolyEffect.h index ef96c87..7464d54 100644 --- a/src/gpu/effects/GrConvexPolyEffect.h +++ b/src/gpu/effects/GrConvexPolyEffect.h @@ -13,6 +13,7 @@ #include "GrTypesPriv.h" class GrGLConvexPolyEffect; +class GrInvariantOutput; class SkPath; /** @@ -77,7 +78,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrPrimitiveEdgeType fEdgeType; int fEdgeCount; diff --git a/src/gpu/effects/GrConvolutionEffect.h b/src/gpu/effects/GrConvolutionEffect.h index 5f58009..e99e520 100644 --- a/src/gpu/effects/GrConvolutionEffect.h +++ b/src/gpu/effects/GrConvolutionEffect.h @@ -9,6 +9,7 @@ #define GrConvolutionEffect_DEFINED #include "Gr1DKernelEffect.h" +#include "GrInvariantOutput.h" class GrGLConvolutionEffect; @@ -97,7 +98,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const { // If the texture was opaque we could know that the output color if we knew the sum of the // kernel values. inout->mulByUnknownColor(); diff --git a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp index 77e7994..39f4482 100644 --- a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp +++ b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp @@ -6,6 +6,7 @@ */ #include "GrCustomCoordsTextureEffect.h" +#include "GrInvariantOutput.h" #include "gl/builders/GrGLProgramBuilder.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLSL.h" @@ -66,7 +67,7 @@ bool GrCustomCoordsTextureEffect::onIsEqual(const GrGeometryProcessor& other) co return true; } -void GrCustomCoordsTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { if (GrPixelConfigIsOpaque(this->texture(0)->config())) { inout->mulByUnknownOpaqueColor(); } else { diff --git a/src/gpu/effects/GrCustomCoordsTextureEffect.h b/src/gpu/effects/GrCustomCoordsTextureEffect.h index 3010ba2..103e209 100644 --- a/src/gpu/effects/GrCustomCoordsTextureEffect.h +++ b/src/gpu/effects/GrCustomCoordsTextureEffect.h @@ -12,6 +12,7 @@ #include "GrGeometryProcessor.h" class GrGLCustomCoordsTextureEffect; +class GrInvariantOutput; /** * The output color of this effect is a modulation of the input color and a sample from a texture. @@ -39,7 +40,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrTextureAccess fTextureAccess; const GrShaderVar& fInTextureCoords; diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index 65ba848..bee7b87 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -18,6 +18,7 @@ #include "GrCoordTransform.h" #include "GrDrawTarget.h" #include "GrDrawTargetCaps.h" +#include "GrInvariantOutput.h" #include "GrProcessor.h" #include "GrGpu.h" #include "GrStrokeInfo.h" @@ -463,7 +464,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrPrimitiveEdgeType fEdgeType; const GrShaderVar& fInCoord; @@ -576,7 +577,7 @@ GrGeometryProcessor* DashingCircleEffect::Create(GrPrimitiveEdgeType edgeType, c DashingCircleEffect::~DashingCircleEffect() {} -void DashingCircleEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void DashingCircleEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } @@ -667,7 +668,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrPrimitiveEdgeType fEdgeType; const GrShaderVar& fInCoord; @@ -791,7 +792,7 @@ GrGeometryProcessor* DashingLineEffect::Create(GrPrimitiveEdgeType edgeType, DashingLineEffect::~DashingLineEffect() {} -void DashingLineEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void DashingLineEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp index 0c7a9a3..bc4146d 100755 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp @@ -6,6 +6,7 @@ */ #include "GrDistanceFieldTextureEffect.h" +#include "GrInvariantOutput.h" #include "gl/builders/GrGLProgramBuilder.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLSL.h" @@ -189,7 +190,7 @@ bool GrDistanceFieldTextureEffect::onIsEqual(const GrGeometryProcessor& other) c fFlags == cte.fFlags; } -void GrDistanceFieldTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrDistanceFieldTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } @@ -363,7 +364,7 @@ bool GrDistanceFieldNoGammaTextureEffect::onIsEqual(const GrGeometryProcessor& o return fFlags == cte.fFlags; } -void GrDistanceFieldNoGammaTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrDistanceFieldNoGammaTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } @@ -606,7 +607,7 @@ bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrGeometryProcessor& other fFlags == cte.fFlags); } -void GrDistanceFieldLCDTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrDistanceFieldLCDTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownColor(); } diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.h b/src/gpu/effects/GrDistanceFieldTextureEffect.h index ea02d19..bcc4088 100644 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.h +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.h @@ -14,6 +14,7 @@ class GrGLDistanceFieldTextureEffect; class GrGLDistanceFieldNoGammaTextureEffect; class GrGLDistanceFieldLCDTextureEffect; +class GrInvariantOutput; enum GrDistanceFieldEffectFlags { kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix @@ -80,7 +81,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrTextureAccess fTextureAccess; #ifdef SK_GAMMA_APPLY_TO_A8 @@ -126,7 +127,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrTextureAccess fTextureAccess; uint32_t fFlags; @@ -172,7 +173,7 @@ private: virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GrTextureAccess fTextureAccess; GrTextureAccess fGammaTextureAccess; diff --git a/src/gpu/effects/GrDitherEffect.cpp b/src/gpu/effects/GrDitherEffect.cpp index 643829b..37655a7 100644 --- a/src/gpu/effects/GrDitherEffect.cpp +++ b/src/gpu/effects/GrDitherEffect.cpp @@ -7,7 +7,7 @@ #include "gl/builders/GrGLProgramBuilder.h" #include "GrDitherEffect.h" - +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLSL.h" #include "GrTBackendProcessorFactory.h" @@ -42,15 +42,15 @@ private: // All dither effects are equal virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE { return true; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GR_DECLARE_FRAGMENT_PROCESSOR_TEST; typedef GrFragmentProcessor INHERITED; }; -void DitherEffect::onComputeInvariantOutput(InvariantOutput* inout) const { - inout->setToUnknown(InvariantOutput::kWill_ReadInput); +void DitherEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { + inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.h b/src/gpu/effects/GrMatrixConvolutionEffect.h index 5aee6c5..9996062 100644 --- a/src/gpu/effects/GrMatrixConvolutionEffect.h +++ b/src/gpu/effects/GrMatrixConvolutionEffect.h @@ -9,6 +9,7 @@ #define GrMatrixConvolutionEffect_DEFINED #include "GrSingleTextureEffect.h" +#include "GrInvariantOutput.h" #include "GrTextureDomain.h" // A little bit less than the minimum # uniforms required by DX9SM2 (32). @@ -79,7 +80,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { // TODO: Try to do better? inout->mulByUnknownColor(); } diff --git a/src/gpu/effects/GrOvalEffect.cpp b/src/gpu/effects/GrOvalEffect.cpp index 8965c99..26b96ad 100644 --- a/src/gpu/effects/GrOvalEffect.cpp +++ b/src/gpu/effects/GrOvalEffect.cpp @@ -7,7 +7,7 @@ #include "gl/builders/GrGLProgramBuilder.h" #include "GrOvalEffect.h" - +#include "GrInvariantOutput.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLSL.h" #include "GrTBackendProcessorFactory.h" @@ -39,7 +39,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; SkPoint fCenter; SkScalar fRadius; @@ -56,7 +56,7 @@ GrFragmentProcessor* CircleEffect::Create(GrPrimitiveEdgeType edgeType, const Sk return SkNEW_ARGS(CircleEffect, (edgeType, center, radius)); } -void CircleEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void CircleEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } @@ -211,7 +211,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; SkPoint fCenter; SkVector fRadii; @@ -230,7 +230,7 @@ GrFragmentProcessor* EllipseEffect::Create(GrPrimitiveEdgeType edgeType, return SkNEW_ARGS(EllipseEffect, (edgeType, center, rx, ry)); } -void EllipseEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void EllipseEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp index 2f4ff2b..b378b10 100644 --- a/src/gpu/effects/GrRRectEffect.cpp +++ b/src/gpu/effects/GrRRectEffect.cpp @@ -11,6 +11,7 @@ #include "gl/GrGLProcessor.h" #include "gl/GrGLSL.h" #include "GrConvexPolyEffect.h" +#include "GrInvariantOutput.h" #include "GrOvalEffect.h" #include "GrTBackendProcessorFactory.h" @@ -66,7 +67,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; SkRRect fRRect; GrPrimitiveEdgeType fEdgeType; @@ -86,7 +87,7 @@ GrFragmentProcessor* CircularRRectEffect::Create(GrPrimitiveEdgeType edgeType, return SkNEW_ARGS(CircularRRectEffect, (edgeType, circularCornerFlags, rrect)); } -void CircularRRectEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void CircularRRectEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } @@ -406,7 +407,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; SkRRect fRRect; GrPrimitiveEdgeType fEdgeType; @@ -424,7 +425,7 @@ EllipticalRRectEffect::Create(GrPrimitiveEdgeType edgeType, const SkRRect& rrect return SkNEW_ARGS(EllipticalRRectEffect, (edgeType, rrect)); } -void EllipticalRRectEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void EllipticalRRectEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { inout->mulByUnknownAlpha(); } diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp index 4da9e8e..9c0ff35 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.cpp +++ b/src/gpu/effects/GrSimpleTextureEffect.cpp @@ -5,13 +5,14 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrSimpleTextureEffect.h" +#include "GrInvariantOutput.h" +#include "GrTBackendProcessorFactory.h" +#include "GrTexture.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" -#include "GrTBackendProcessorFactory.h" -#include "GrTexture.h" +#include "gl/builders/GrGLProgramBuilder.h" class GrGLSimpleTextureEffect : public GrGLFragmentProcessor { public: @@ -41,7 +42,7 @@ private: /////////////////////////////////////////////////////////////////////////////// -void GrSimpleTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { this->updateInvariantOutputForModulation(inout); } diff --git a/src/gpu/effects/GrSimpleTextureEffect.h b/src/gpu/effects/GrSimpleTextureEffect.h index 4c79aab..f2c8d16 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.h +++ b/src/gpu/effects/GrSimpleTextureEffect.h @@ -11,6 +11,7 @@ #include "GrSingleTextureEffect.h" class GrGLSimpleTextureEffect; +class GrInvariantOutput; /** * The output color of this effect is a modulation of the input color and a sample from a texture. @@ -70,7 +71,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { return true; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GR_DECLARE_FRAGMENT_PROCESSOR_TEST; diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h index 836c54c..efdf255 100644 --- a/src/gpu/effects/GrSingleTextureEffect.h +++ b/src/gpu/effects/GrSingleTextureEffect.h @@ -9,8 +9,9 @@ #define GrSingleTextureEffect_DEFINED #include "GrFragmentProcessor.h" -#include "SkMatrix.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" +#include "SkMatrix.h" class GrTexture; @@ -38,7 +39,7 @@ protected: * the subclass output color will be a modulation of the input color with a value read from the * texture. */ - void updateInvariantOutputForModulation(InvariantOutput* inout) const { + void updateInvariantOutputForModulation(GrInvariantOutput* inout) const { if (GrPixelConfigIsOpaque(this->texture(0)->config())) { inout->mulByUnknownOpaqueColor(); } else { diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp index 2a0cd20..db3ef2c 100644 --- a/src/gpu/effects/GrTextureDomain.cpp +++ b/src/gpu/effects/GrTextureDomain.cpp @@ -7,6 +7,7 @@ #include "gl/builders/GrGLProgramBuilder.h" #include "GrTextureDomain.h" +#include "GrInvariantOutput.h" #include "GrSimpleTextureEffect.h" #include "GrTBackendProcessorFactory.h" #include "gl/GrGLProcessor.h" @@ -268,7 +269,7 @@ bool GrTextureDomainEffect::onIsEqual(const GrFragmentProcessor& sBase) const { return this->fTextureDomain == s.fTextureDomain; } -void GrTextureDomainEffect::onComputeInvariantOutput(InvariantOutput* inout) const { +void GrTextureDomainEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { if (GrTextureDomain::kDecal_Mode == fTextureDomain.mode()) { // TODO: helper inout->mulByUnknownColor(); } else { diff --git a/src/gpu/effects/GrTextureDomain.h b/src/gpu/effects/GrTextureDomain.h index 6f56f91..19b07ad 100644 --- a/src/gpu/effects/GrTextureDomain.h +++ b/src/gpu/effects/GrTextureDomain.h @@ -13,6 +13,7 @@ class GrGLProgramBuilder; class GrGLShaderBuilder; +class GrInvariantOutput; struct SkRect; /** @@ -175,7 +176,7 @@ private: virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; GR_DECLARE_FRAGMENT_PROCESSOR_TEST; diff --git a/src/gpu/effects/GrYUVtoRGBEffect.cpp b/src/gpu/effects/GrYUVtoRGBEffect.cpp index 703c672..f668dba 100644 --- a/src/gpu/effects/GrYUVtoRGBEffect.cpp +++ b/src/gpu/effects/GrYUVtoRGBEffect.cpp @@ -9,6 +9,7 @@ #include "GrYUVtoRGBEffect.h" #include "GrCoordTransform.h" +#include "GrInvariantOutput.h" #include "GrProcessor.h" #include "gl/GrGLProcessor.h" #include "GrTBackendProcessorFactory.h" @@ -106,10 +107,10 @@ private: return fColorSpace == s.getColorSpace(); } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { // YUV is opaque inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A, - InvariantOutput::kWillNot_ReadInput); + GrInvariantOutput::kWillNot_ReadInput); } GrCoordTransform fCoordTransform; diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 9be082a..dd731e0 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -13,6 +13,7 @@ #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS #include "GrContextFactory.h" +#include "GrInvariantOutput.h" #include "GrOptDrawState.h" #include "GrTBackendProcessorFactory.h" #include "GrTest.h" @@ -50,7 +51,7 @@ public: private: BigKeyProcessor() { } virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE { return true; } - virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { } + virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { } GR_DECLARE_FRAGMENT_PROCESSOR_TEST; diff --git a/tests/GpuColorFilterTest.cpp b/tests/GpuColorFilterTest.cpp index 82f5f31..aeee3da 100644 --- a/tests/GpuColorFilterTest.cpp +++ b/tests/GpuColorFilterTest.cpp @@ -11,6 +11,7 @@ #include "GrContext.h" #include "GrContextFactory.h" #include "GrFragmentProcessor.h" +#include "GrInvariantOutput.h" #include "SkColorFilter.h" #include "SkGr.h" #include "Test.h" @@ -99,9 +100,9 @@ static void test_getConstantColorComponents(skiatest::Reporter* reporter, GrCont const GetConstantComponentTestCase& test = filterTests[i]; SkAutoTUnref cf(SkColorFilter::CreateModeFilter(test.filterColor, test.filterMode)); SkAutoTUnref effect(cf->asFragmentProcessor(grContext)); - GrProcessor::InvariantOutput inout; - inout.setToOther(test.inputComponents, test.inputColor, - GrProcessor::InvariantOutput::kWill_ReadInput); + GrInvariantOutput inout(test.inputColor, + static_cast(test.inputComponents), + false); effect->computeInvariantOutput(&inout); REPORTER_ASSERT(reporter, filterColor(inout.color(), inout.validFlags()) == test.outputColor);