virtual ~GrProcessor();
- struct InvariantOutput{
- GrColor fColor;
- uint32_t fValidFlags;
- bool fIsSingleComponent;
-
- bool isOpaque() const {
- return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(fColor));
- }
-
- bool isSolidWhite() const {
- return (fValidFlags == kRGBA_GrColorComponentFlags &&
- 0xFFFFFFFF == GrColorUnpackA(fColor));
- }
-
- /**
- * 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:
- SkDEBUGCODE(bool colorComponentsAllEqual() const;)
-
- /**
- * If alpha is valid, check that any valid R,G,B values are <= A
- */
- SkDEBUGCODE(bool validPreMulColor() const;)
- };
-
/**
- * This function is used to perform optimizations. When called the invarientOuput param
+ * This function is used to perform optimizations. When called the color and validFlags params
* indicate whether the input components to this effect in the FS will have known values.
- * In inout the validFlags member is a bitfield of GrColorComponentFlags. The isSingleComponent
- * member indicates whether the input will be 1 or 4 bytes. The function updates the members of
- * 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.
+ * validFlags is a bitfield of GrColorComponentFlags. The function updates both params to
+ * indicate known values of its output. A component of the color param only has meaning if the
+ * corresponding bit in validFlags is set.
*/
- void computeInvariantOutput(InvariantOutput* inout) const {
- this->onComputeInvariantOutput(inout);
-#ifdef SK_DEBUG
- inout->validate();
-#endif
- }
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const = 0;
/** 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,
getFactory()).*/
virtual bool onIsEqual(const GrProcessor& other) const = 0;
- /**
- * Subclass implements this to support getConstantColorComponents(...).
- */
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0;
friend class GrGeometryProcessor; // to set fRequiresVertexShader and build fVertexAttribTypes.
SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
}
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE {
return GrTBackendFragmentProcessorFactory<XferEffect>::getInstance();
}
return fMode == s.fMode &&
fBackgroundAccess.getTexture() == s.fBackgroundAccess.getTexture();
}
-
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
SkXfermode::Mode fMode;
GrCoordTransform fBackgroundTransform;
static const char* Name() { return "Alpha Threshold"; }
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
float innerThreshold() const { return fInnerThreshold; }
float outerThreshold() const { return fOuterThreshold; }
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
float fInnerThreshold;
this->fOuterThreshold == s.fOuterThreshold);
}
-void AlphaThresholdEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- if (inout->isOpaque() && GrPixelConfigIsOpaque(this->texture(0)->config())) {
- inout->fValidFlags = kA_GrColorComponentFlag;
+void AlphaThresholdEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
+ GrPixelConfigIsOpaque(this->texture(0)->config())) {
+ *validFlags = kA_GrColorComponentFlag;
} else {
- inout->fValidFlags = 0;
+ *validFlags = 0;
}
- inout->fIsSingleComponent = false;
}
#endif
static const char* Name() { return "Arithmetic"; }
GrTexture* backgroundTexture() const { return fBackgroundAccess.getTexture(); }
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
float k1() const { return fK1; }
float k2() const { return fK2; }
float k3() const { return fK3; }
private:
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrArithmeticEffect(float k1, float k2, float k3, float k4, bool enforcePMColor,
GrTexture* background);
float fK1, fK2, fK3, fK4;
return GrTBackendFragmentProcessorFactory<GrArithmeticEffect>::getInstance();
}
-void GrArithmeticEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
+void GrArithmeticEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
// TODO: optimize this
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+ *validFlags = 0;
}
///////////////////////////////////////////////////////////////////////////////
typedef GrGLRectBlurEffect GLProcessor;
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
/**
* Create a simple filter effect with custom bicubic coefficients.
*/
GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile);
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
static bool CreateBlurProfileTexture(GrContext *context, float sigma,
GrTexture **blurProfileTexture);
return this->getSigma() == s.getSigma() && this->getRect() == s.getRect();
}
-void GrRectBlurEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void GrRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
+ return;
}
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
typedef GrGLRRectBlurEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
SkRRect fRRect;
float fSigma;
GrTextureAccess fNinePatchAccess;
return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture));
}
-void GrRRectBlurEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void GrRRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendFragmentProcessorFactory& GrRRectBlurEffect::getFactory() const {
return SkNEW_ARGS(ModeColorFilterEffect, (c, mode));
}
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
bool willUseFilterColor() const {
SkXfermode::Coeff dstCoeff;
SkXfermode::Coeff srcCoeff;
return fMode == s.fMode && fColor == s.fColor;
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
SkXfermode::Mode fMode;
GrColor fColor;
}
-void ModeColorFilterEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
+void ModeColorFilterEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
float inputColor[4];
- GrColorToRGBAFloat(inout->fColor, inputColor);
+ GrColorToRGBAFloat(*color, inputColor);
float filterColor[4];
GrColorToRGBAFloat(fColor, filterColor);
MaskedColorExpr result =
color_filter_expression(fMode,
MaskedColorExpr(filterColor, kRGBA_GrColorComponentFlags),
- MaskedColorExpr(inputColor, inout->fValidFlags));
+ MaskedColorExpr(inputColor, *validFlags));
- inout->fColor = result.getColor();
- inout->fValidFlags = result.getValidComponents();
- inout->fIsSingleComponent = false;
+ *color = result.getColor();
+ *validFlags = result.getValidComponents();
}
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect);
return GrTBackendFragmentProcessorFactory<ColorMatrixEffect>::getInstance();
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) 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.
+
+ // The matrix is defined such the 4th row determines the output alpha. The first four
+ // columns of that row multiply the input r, g, b, and a, respectively, and the last column
+ // is the "translation".
+ static const uint32_t kRGBAFlags[] = {
+ kR_GrColorComponentFlag,
+ kG_GrColorComponentFlag,
+ kB_GrColorComponentFlag,
+ kA_GrColorComponentFlag
+ };
+ static const int kShifts[] = {
+ GrColor_SHIFT_R, GrColor_SHIFT_G, GrColor_SHIFT_B, GrColor_SHIFT_A,
+ };
+ enum {
+ kAlphaRowStartIdx = 15,
+ kAlphaRowTranslateIdx = 19,
+ };
+
+ SkScalar outputA = 0;
+ for (int i = 0; i < 4; ++i) {
+ // If any relevant component of the color to be passed through the matrix is non-const
+ // then we can't know the final result.
+ if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) {
+ if (!(*validFlags & kRGBAFlags[i])) {
+ *validFlags = 0;
+ return;
+ } else {
+ uint32_t component = (*color >> kShifts[i]) & 0xFF;
+ outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component;
+ }
+ }
+ }
+ outputA += fMatrix.fMat[kAlphaRowTranslateIdx];
+ *validFlags = kA_GrColorComponentFlag;
+ // We pin the color to [0,1]. This would happen to the *final* color output from the frag
+ // shader but currently the effect does not pin its own output. So in the case of over/
+ // underflow this may deviate from the actual result. Maybe the effect should pin its
+ // result if the matrix could over/underflow for any component?
+ *color = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_SHIFT_A;
+ }
+
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
class GLProcessor : public GrGLFragmentProcessor {
return cme.fMatrix == fMatrix;
}
- virtual void onComputeInvariantOutput(InvariantOutput* 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.
-
- // The matrix is defined such the 4th row determines the output alpha. The first four
- // columns of that row multiply the input r, g, b, and a, respectively, and the last column
- // is the "translation".
- static const uint32_t kRGBAFlags[] = {
- kR_GrColorComponentFlag,
- kG_GrColorComponentFlag,
- kB_GrColorComponentFlag,
- kA_GrColorComponentFlag
- };
- static const int kShifts[] = {
- GrColor_SHIFT_R, GrColor_SHIFT_G, GrColor_SHIFT_B, GrColor_SHIFT_A,
- };
- enum {
- kAlphaRowStartIdx = 15,
- kAlphaRowTranslateIdx = 19,
- };
-
- SkScalar outputA = 0;
- for (int i = 0; i < 4; ++i) {
- // If any relevant component of the color to be passed through the matrix is non-const
- // then we can't know the final result.
- if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) {
- if (!(inout->fValidFlags & kRGBAFlags[i])) {
- inout->fValidFlags = 0;
- return;
- } else {
- uint32_t component = (inout->fColor >> kShifts[i]) & 0xFF;
- outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component;
- }
- }
- }
- outputA += fMatrix.fMat[kAlphaRowTranslateIdx];
- inout->fValidFlags = kA_GrColorComponentFlag;
- // We pin the color to [0,1]. This would happen to the *final* color output from the frag
- // shader but currently the effect does not pin its own output. So in the case of over/
- // underflow this may deviate from the actual result. Maybe the effect should pin its
- // result if the matrix could over/underflow for any component?
- inout->fColor = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_SHIFT_A;
- inout->fIsSingleComponent = false;
- }
-
SkColorMatrix fMatrix;
typedef GrFragmentProcessor INHERITED;
typedef GrGLDisplacementMapEffect GLProcessor;
static const char* Name() { return "DisplacementMap"; }
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
private:
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
const SkVector& scale,
return GrTBackendFragmentProcessorFactory<GrDisplacementMapEffect>::getInstance();
}
-void GrDisplacementMapEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
+void GrDisplacementMapEffect::getConstantColorComponents(GrColor*,
+ uint32_t* validFlags) 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->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+ *validFlags = 0;
}
///////////////////////////////////////////////////////////////////////////////
SkScalar surfaceScale() const { return fSurfaceScale; }
const SkMatrix& filterMatrix() const { return fFilterMatrix; }
-protected:
- virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
-
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
// lighting shaders are complicated. We just throw up our hands.
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+ *validFlags = 0;
}
+protected:
+ virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
+
private:
typedef GrSingleTextureEffect INHERITED;
const SkLight* fLight;
return GrTBackendFragmentProcessorFactory<LumaColorFilterEffect>::getInstance();
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ // The output is always black.
+ *color = GrColorPackRGBA(0, 0, 0, GrColorUnpackA(*color));
+ *validFlags = kRGB_GrColorComponentFlags;
+ }
+
class GLProcessor : public GrGLFragmentProcessor {
public:
GLProcessor(const GrBackendProcessorFactory& factory,
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE {
return true;
}
-
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- // The output is always black.
- inout->fColor = GrColorPackRGBA(0, 0, 0, GrColorUnpackA(inout->fColor));
- inout->fValidFlags = kRGB_GrColorComponentFlags;
- inout->fIsSingleComponent = false;
- }
};
GrFragmentProcessor* SkLumaColorFilter::asFragmentProcessor(GrContext*) const {
static const char* Name() { return "Magnifier"; }
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
float x_offset() const { return fXOffset; }
float y_offset() const { return fYOffset; }
float x_inv_zoom() const { return fXInvZoom; }
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
float fXOffset;
this->fYInvInset == s.fYInvInset);
}
-void GrMagnifierEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- this->updateInvariantOutputForModulation(inout);
- inout->fIsSingleComponent = false;
+void GrMagnifierEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ this->updateConstantColorComponentsForModulation(color, validFlags);
}
#endif
typedef GrGLMorphologyEffect GLProcessor;
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
protected:
private:
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
this->type() == s.type());
}
-void GrMorphologyEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
+void GrMorphologyEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) 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);
- inout->fIsSingleComponent = false;
+ this->updateConstantColorComponentsForModulation(color, validFlags);
}
///////////////////////////////////////////////////////////////////////////////
fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataInit;
}
- void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0; // This is noise. Nothing is constant.
- inout->fIsSingleComponent = false;
- }
-
GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type,
int numOctaves, bool stitchTiles,
SkPerlinNoiseShader::PaintingData* paintingData,
GrTextureAccess fNoiseAccess;
SkPerlinNoiseShader::PaintingData *fPaintingData;
+ void getConstantColorComponents(GrColor*, uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0; // This is noise. Nothing is constant.
+ }
+
private:
typedef GrFragmentProcessor INHERITED;
};
static const char* Name() { return "ColorTable"; }
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
typedef GLColorTableEffect GLProcessor;
private:
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
explicit ColorTableEffect(GrTexture* texture, unsigned flags);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
GrTextureAccess fTextureAccess;
unsigned fFlags; // currently not used in shader code, just to assist
- // onComputeInvariantOutput().
+ // getConstantColorComponents().
typedef GrFragmentProcessor INHERITED;
};
return this->texture(0) == sBase.texture(0);
}
-void ColorTableEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
+void ColorTableEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
// If we kept the table in the effect then we could actually run known inputs through the
// table.
if (fFlags & SkTable_ColorFilter::kR_Flag) {
- inout->fValidFlags &= ~kR_GrColorComponentFlag;
+ *validFlags &= ~kR_GrColorComponentFlag;
}
if (fFlags & SkTable_ColorFilter::kG_Flag) {
- inout->fValidFlags &= ~kG_GrColorComponentFlag;
+ *validFlags &= ~kG_GrColorComponentFlag;
}
if (fFlags & SkTable_ColorFilter::kB_Flag) {
- inout->fValidFlags &= ~kB_GrColorComponentFlag;
+ *validFlags &= ~kB_GrColorComponentFlag;
}
if (fFlags & SkTable_ColorFilter::kA_Flag) {
- inout->fValidFlags &= ~kA_GrColorComponentFlag;
+ *validFlags &= ~kA_GrColorComponentFlag;
}
- inout->fIsSingleComponent = false;
}
return false;
}
-void GrGradientEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- if (fIsOpaque && inout->isOpaque()) {
- inout->fValidFlags = kA_GrColorComponentFlag;
+void GrGradientEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ if (fIsOpaque && (kA_GrColorComponentFlag & *validFlags) && 0xff == GrColorUnpackA(*color)) {
+ *validFlags = kA_GrColorComponentFlag;
} else {
- inout->fValidFlags = 0;
+ *validFlags = 0;
}
- inout->fIsSingleComponent = false;
}
int GrGradientEffect::RandomGradientParams(SkRandom* random,
bool useAtlas() const { return SkToBool(-1 != fRow); }
SkScalar getYCoord() const { return fYCoord; };
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
SkGradientShaderBase::GpuColorType getColorType() const { return fColorType; }
enum PremulType {
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
const GrCoordTransform& getCoordTransform() const { return fCoordTransform; }
private:
static const char* Name() { return "QuadEdge"; }
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
const GrShaderVar& inQuadEdge() const { return fInQuadEdge; }
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE {
return true;
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
const GrShaderVar& fInQuadEdge;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
static const char* Name() { return "AlignedRectEdge"; }
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
const GrShaderVar& inRect() const { return fInRect; }
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE {
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE { return true; }
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
typedef GrGeometryProcessor INHERITED;
static const char* Name() { return "RectEdge"; }
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
const GrShaderVar& inRectEdge() const { return fInRectEdge; }
const GrShaderVar& inWidthHeight() const { return fInWidthHeight; }
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE { return true; }
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
const GrShaderVar& fInRectEdge;
const GrShaderVar& fInWidthHeight;
return true;
}
- GrProcessor::InvariantOutput inout;
- inout.fIsSingleComponent = false;
+ GrColor coverage;
+ uint32_t validComponentFlags;
// Initialize to an unknown starting coverage if per-vertex coverage is specified.
if (this->hasCoverageVertexAttribute()) {
- inout.fValidFlags = 0;
+ validComponentFlags = 0;
} else {
- inout.fColor = fCoverage;
- inout.fValidFlags = kRGBA_GrColorComponentFlags;
+ coverage = fCoverage;
+ validComponentFlags = kRGBA_GrColorComponentFlags;
}
// Run through the coverage stages and see if the coverage will be all ones at the end.
if (this->hasGeometryProcessor()) {
const GrGeometryProcessor* gp = fGeometryProcessor->getGeometryProcessor();
- gp->computeInvariantOutput(&inout);
+ gp->getConstantColorComponents(&coverage, &validComponentFlags);
}
for (int s = 0; s < this->numCoverageStages(); ++s) {
const GrProcessor* processor = this->getCoverageStage(s).getProcessor();
- processor->computeInvariantOutput(&inout);
+ processor->getConstantColorComponents(&coverage, &validComponentFlags);
}
- return inout.isSolidWhite();
+ return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff == coverage);
}
//////////////////////////////////////////////////////////////////////////////
bool GrDrawState::srcAlphaWillBeOne() const {
- GrProcessor::InvariantOutput inoutColor;
- inoutColor.fIsSingleComponent = false;
+ uint32_t validComponentFlags;
+ GrColor color;
// 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;
+ validComponentFlags = 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;
+ validComponentFlags = 0;
+ color = 0; // not strictly necessary but we get false alarms from tools about uninit.
}
} else {
- inoutColor.fValidFlags = kRGBA_GrColorComponentFlags;
- inoutColor.fColor = this->getColor();
+ validComponentFlags = kRGBA_GrColorComponentFlags;
+ color = this->getColor();
}
// Run through the color stages
for (int s = 0; s < this->numColorStages(); ++s) {
const GrProcessor* processor = this->getColorStage(s).getProcessor();
- processor->computeInvariantOutput(&inoutColor);
+ processor->getConstantColorComponents(&color, &validComponentFlags);
}
// Check whether coverage is treated as color. If so we run through the coverage computation.
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 = false;
+ GrColor coverage;
+ uint32_t coverageComponentFlags;
if (this->hasCoverageVertexAttribute()) {
- inoutCoverage.fValidFlags = 0;
- inoutCoverage.fColor = 0; // suppresses any warnings.
+ coverageComponentFlags = 0;
+ coverage = 0; // suppresses any warnings.
} else {
- inoutCoverage.fValidFlags = kRGBA_GrColorComponentFlags;
- inoutCoverage.fColor = this->getCoverageColor();
+ coverageComponentFlags = kRGBA_GrColorComponentFlags;
+ coverage = this->getCoverageColor();
}
// Run through the coverage stages
for (int s = 0; s < this->numCoverageStages(); ++s) {
const GrProcessor* processor = this->getCoverageStage(s).getProcessor();
- processor->computeInvariantOutput(&inoutCoverage);
+ processor->getConstantColorComponents(&coverage, &coverageComponentFlags);
}
// Since the shader will multiply coverage and color, the only way the final A==1 is if
// coverage and color both have A==1.
- return (inoutColor.isOpaque() && inoutCoverage.isOpaque());
+ return (kA_GrColorComponentFlag & validComponentFlags & coverageComponentFlags) &&
+ 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage);
+
}
- return inoutColor.isOpaque();
+ return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnpackA(color);
}
int firstColorStage = 0;
// Set up color and flags for ConstantColorComponent checks
- GrProcessor::InvariantOutput inout;
- inout.fIsSingleComponent = false;
+ GrColor color;
+ uint32_t validComponentFlags;
if (!this->hasColorVertexAttribute()) {
- inout.fColor = ds.getColor();
- inout.fValidFlags = kRGBA_GrColorComponentFlags;
+ color = ds.getColor();
+ validComponentFlags = kRGBA_GrColorComponentFlags;
} else {
if (ds.vertexColorsAreOpaque()) {
- inout.fColor = 0xFF << GrColor_SHIFT_A;
- inout.fValidFlags = kA_GrColorComponentFlag;
+ color = 0xFF << GrColor_SHIFT_A;
+ validComponentFlags = kA_GrColorComponentFlag;
} else {
- inout.fValidFlags = 0;
- // not strictly necessary but we get false alarms from tools about uninit.
- inout.fColor = 0;
+ validComponentFlags = 0;
+ color = 0; // not strictly necessary but we get false alarms from tools about uninit.
}
}
firstColorStage = i;
fInputColorIsUsed = false;
}
- fp->computeInvariantOutput(&inout);
- if (kRGBA_GrColorComponentFlags == inout.fValidFlags) {
+ fp->getConstantColorComponents(&color, &validComponentFlags);
+ if (kRGBA_GrColorComponentFlags == validComponentFlags) {
firstColorStage = i + 1;
- fColor = inout.fColor;
+ fColor = color;
fInputColorIsUsed = true;
this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribBinding);
}
}
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
const GrShaderVar& inCircleEdge() const { return fInCircleEdge; }
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE {
return cee.fStroke == fStroke;
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
const GrShaderVar& fInCircleEdge;
bool fStroke;
}
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE {
return GrTBackendGeometryProcessorFactory<EllipseEdgeEffect>::getInstance();
}
return eee.fStroke == fStroke;
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
const GrShaderVar& fInEllipseOffset;
const GrShaderVar& fInEllipseRadii;
bool fStroke;
}
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE {
return GrTBackendGeometryProcessorFactory<DIEllipseEdgeEffect>::getInstance();
}
return eee.fMode == fMode;
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
const GrShaderVar& fInEllipseOffsets0;
const GrShaderVar& fInEllipseOffsets1;
Mode fMode;
// TODO: Share this implementation with GrDrawState
- GrProcessor::InvariantOutput inout;
- inout.fColor = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
- inout.fValidFlags = kRGBA_GrColorComponentFlags;
- inout.fIsSingleComponent = false;
+ GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
+ uint32_t coverageComps = kRGBA_GrColorComponentFlags;
int count = fCoverageStages.count();
for (int i = 0; i < count; ++i) {
- fCoverageStages[i].getProcessor()->computeInvariantOutput(&inout);
+ fCoverageStages[i].getProcessor()->getConstantColorComponents(&coverage, &coverageComps);
}
- if (!inout.isSolidWhite()) {
+ if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) {
return false;
}
- inout.fColor = fColor;
- inout.fValidFlags = kRGBA_GrColorComponentFlags;
- inout.fIsSingleComponent = false;
+ GrColor color = fColor;
+ uint32_t colorComps = kRGBA_GrColorComponentFlags;
count = fColorStages.count();
for (int i = 0; i < count; ++i) {
- fColorStages[i].getProcessor()->computeInvariantOutput(&inout);
+ fColorStages[i].getProcessor()->getConstantColorComponents(&color, &colorComps);
}
SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents));
GrBlendCoeff srcCoeff = fSrcBlendCoeff;
GrBlendCoeff dstCoeff = fDstBlendCoeff;
- GrSimplifyBlend(&srcCoeff, &dstCoeff, inout.fColor, inout.fValidFlags,
- 0, 0, 0);
+ GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0);
bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff);
if (solidColor) {
break;
case kOne_GrBlendCoeff:
- *solidColor = inout.fColor;
- *solidColorKnownComponents = inout.fValidFlags;
+ *solidColor = color;
+ *solidColorKnownComponents = colorComps;
break;
// The src coeff should never refer to the src and if it refers to dst then opaque
SkASSERT(this->textureAccess(i) == other.textureAccess(i));
}
}
-
-void GrProcessor::InvariantOutput::validate() const {
- if (fIsSingleComponent) {
- SkASSERT(0 == fValidFlags || kRGBA_GrColorComponentFlags == fValidFlags);
- if (kRGBA_GrColorComponentFlags == fValidFlags) {
- SkASSERT(this->colorComponentsAllEqual());
- }
- }
-
- SkASSERT(this->validPreMulColor());
-}
-
-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;
-}
#endif
-
typedef GrGLConicEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
GrPrimitiveEdgeType fEdgeType;
const GrShaderVar& fInConicCoeffs;
typedef GrGLQuadEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
GrPrimitiveEdgeType fEdgeType;
const GrShaderVar& fInHairQuadEdge;
typedef GrGLCubicEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ *validFlags = 0;
+ }
+
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
GrPrimitiveEdgeType fEdgeType;
const GrShaderVar& fInCubicCoeffs;
fDomain == s.fDomain;
}
-void GrBicubicEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
+void GrBicubicEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
// FIXME: Perhaps we can do better.
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+ *validFlags = 0;
return;
}
typedef GrGLBicubicEffect GLProcessor;
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
const GrTextureDomain& domain() const { return fDomain; }
const SkMatrix &matrix, const SkRect& domain);
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
float fCoefficients[16];
GrTextureDomain fDomain;
other.fPMConversion == fPMConversion;
}
-void GrConfigConversionEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- this->updateInvariantOutputForModulation(inout);
- inout->fIsSingleComponent = false;
+void GrConfigConversionEffect::getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const {
+ this->updateConstantColorComponentsForModulation(color, validFlags);
}
///////////////////////////////////////////////////////////////////////////////
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
bool swapsRedAndBlue() const { return fSwapRedAndBlue; }
PMConversion pmConversion() const { return fPMConversion; }
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
bool fSwapRedAndBlue;
PMConversion fPMConversion;
return SkNEW_ARGS(AARectEffect, (edgeType, rect));
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ if (fRect.isEmpty()) {
+ // An empty rect will have no coverage anywhere.
+ *color = 0x00000000;
+ *validFlags = kRGBA_GrColorComponentFlags;
+ } else {
+ *validFlags = 0;
+ }
+ }
+
GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; }
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
return fRect == aare.fRect;
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- if (fRect.isEmpty()) {
- // An empty rect will have no coverage anywhere.
- inout->fColor = 0x00000000;
- inout->fValidFlags = kRGBA_GrColorComponentFlags;
- } else {
- inout->fValidFlags = 0;
- }
- inout->fIsSingleComponent = false;
- }
-
SkRect fRect;
GrPrimitiveEdgeType fEdgeType;
GrConvexPolyEffect::~GrConvexPolyEffect() {}
-void GrConvexPolyEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendFragmentProcessorFactory& GrConvexPolyEffect::getFactory() const {
typedef GrGLConvexPolyEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrPrimitiveEdgeType fEdgeType;
int fEdgeCount;
SkScalar fEdges[3 * kMaxEdges];
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor*, uint32_t* validFlags) const {
+ // If the texture was opaque we could know that the output color if we knew the sum of the
+ // kernel values.
+ *validFlags = 0;
+ }
+
enum {
// This was decided based on the min allowed value for the max texture
// samples per fragment program run in DX9SM2 (32). A sigma param of 4.0
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const {
- // If the texture was opaque we could know that the output color if we knew the sum of the
- // kernel values.
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef Gr1DKernelEffect INHERITED;
return fTextureAccess == cte.fTextureAccess;
}
-void GrCustomCoordsTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- if (inout->isOpaque() && GrPixelConfigIsOpaque(this->texture(0)->config())) {
- inout->fValidFlags = kA_GrColorComponentFlag;
+void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const {
+ if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
+ GrPixelConfigIsOpaque(this->texture(0)->config())) {
+ *validFlags = kA_GrColorComponentFlag;
} else {
- inout->fValidFlags = 0;
+ *validFlags = 0;
}
- inout->fIsSingleComponent = false;
}
const GrBackendGeometryProcessorFactory& GrCustomCoordsTextureEffect::getFactory() const {
static const char* Name() { return "Texture"; }
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
const GrShaderVar& inTextureCoords() const { return fInTextureCoords; }
typedef GrGLCustomCoordsTextureEffect GLProcessor;
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrTextureAccess fTextureAccess;
const GrShaderVar& fInTextureCoords;
typedef GLDashingCircleEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrPrimitiveEdgeType fEdgeType;
const GrShaderVar& fInCoord;
SkScalar fIntervalLength;
DashingCircleEffect::~DashingCircleEffect() {}
-void DashingCircleEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendGeometryProcessorFactory& DashingCircleEffect::getFactory() const {
typedef GLDashingLineEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrPrimitiveEdgeType fEdgeType;
const GrShaderVar& fInCoord;
SkRect fRect;
DashingLineEffect::~DashingLineEffect() {}
-void DashingLineEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void DashingLineEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendGeometryProcessorFactory& DashingLineEffect::getFactory() const {
fFlags == cte.fFlags;
}
-void GrDistanceFieldTextureEffect::onComputeInvariantOutput(
- InvariantOutput* inout) const {
- if (inout->isOpaque() && GrPixelConfigIsOpaque(this->texture(0)->config())) {
- inout->fValidFlags = kA_GrColorComponentFlag;
+void GrDistanceFieldTextureEffect::getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const {
+ if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
+ GrPixelConfigIsOpaque(this->texture(0)->config())) {
+ *validFlags = kA_GrColorComponentFlag;
} else {
- inout->fValidFlags = 0;
+ *validFlags = 0;
}
- inout->fIsSingleComponent = false;
}
const GrBackendGeometryProcessorFactory& GrDistanceFieldTextureEffect::getFactory() const {
fFlags == cte.fFlags);
}
-void GrDistanceFieldLCDTextureEffect::onComputeInvariantOutput(
- InvariantOutput* inout) const {
- if (inout->isOpaque() && GrPixelConfigIsOpaque(this->texture(0)->config())) {
- inout->fValidFlags = kA_GrColorComponentFlag;
+void GrDistanceFieldLCDTextureEffect::getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const {
+ if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
+ GrPixelConfigIsOpaque(this->texture(0)->config())) {
+ *validFlags = kA_GrColorComponentFlag;
} else {
- inout->fValidFlags = 0;
+ *validFlags = 0;
}
- inout->fIsSingleComponent = false;
}
const GrBackendGeometryProcessorFactory& GrDistanceFieldLCDTextureEffect::getFactory() const {
static const char* Name() { return "DistanceFieldTexture"; }
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
const GrShaderVar& inTextureCoords() const { return fInTextureCoords; }
#ifdef SK_GAMMA_APPLY_TO_A8
float getLuminance() const { return fLuminance; }
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrTextureAccess fTextureAccess;
#ifdef SK_GAMMA_APPLY_TO_A8
GrTextureAccess fGammaTextureAccess;
static const char* Name() { return "DistanceFieldLCDTexture"; }
const GrShaderVar& inTextureCoords() const { return fInTextureCoords; }
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
GrColor getTextColor() const { return fTextColor; }
uint32_t getFlags() const { return fFlags; }
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GrTextureAccess fTextureAccess;
GrTextureAccess fGammaTextureAccess;
GrColor fTextColor;
typedef GLDitherEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE {
return GrTBackendFragmentProcessorFactory<DitherEffect>::getInstance();
}
// All dither effects are equal
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE { return true; }
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef GrFragmentProcessor INHERITED;
};
-void DitherEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void DitherEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
//////////////////////////////////////////////////////////////////////////////
virtual ~GrMatrixConvolutionEffect();
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ // TODO: Try to do better?
+ *validFlags = 0;
+ }
+
static const char* Name() { return "MatrixConvolution"; }
const SkIRect& bounds() const { return fBounds; }
const SkISize& kernelSize() const { return fKernelSize; }
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- // TODO: Try to do better?
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
- }
-
SkIRect fBounds;
SkISize fKernelSize;
float fKernel[MAX_KERNEL_SIZE];
typedef GLCircleEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
SkPoint fCenter;
SkScalar fRadius;
GrPrimitiveEdgeType fEdgeType;
return SkNEW_ARGS(CircleEffect, (edgeType, center, radius));
}
-void CircleEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void CircleEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendFragmentProcessorFactory& CircleEffect::getFactory() const {
typedef GLEllipseEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
SkPoint fCenter;
SkVector fRadii;
GrPrimitiveEdgeType fEdgeType;
return SkNEW_ARGS(EllipseEffect, (edgeType, center, rx, ry));
}
-void EllipseEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void EllipseEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendFragmentProcessorFactory& EllipseEffect::getFactory() const {
typedef GLCircularRRectEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
SkRRect fRRect;
GrPrimitiveEdgeType fEdgeType;
uint32_t fCircularCornerFlags;
return SkNEW_ARGS(CircularRRectEffect, (edgeType, circularCornerFlags, rrect));
}
-void CircularRRectEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void CircularRRectEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendFragmentProcessorFactory& CircularRRectEffect::getFactory() const {
typedef GLEllipticalRRectEffect GLProcessor;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
SkRRect fRRect;
GrPrimitiveEdgeType fEdgeType;
return SkNEW_ARGS(EllipticalRRectEffect, (edgeType, rrect));
}
-void EllipticalRRectEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- inout->fValidFlags = 0;
- inout->fIsSingleComponent = false;
+void EllipticalRRectEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ *validFlags = 0;
}
const GrBackendFragmentProcessorFactory& EllipticalRRectEffect::getFactory() const {
///////////////////////////////////////////////////////////////////////////////
-void GrSimpleTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
- this->updateInvariantOutputForModulation(inout);
- inout->fIsSingleComponent = false;
+void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
+ this->updateConstantColorComponentsForModulation(color, validFlags);
}
const GrBackendFragmentProcessorFactory& GrSimpleTextureEffect::getFactory() const {
static const char* Name() { return "Texture"; }
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
typedef GrGLSimpleTextureEffect GLProcessor;
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
return this->hasSameTextureParamsMatrixAndSourceCoords(ste);
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef GrSingleTextureEffect INHERITED;
}
/**
- * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that
+ * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that
* the subclass output color will be a modulation of the input color with a value read from the
* texture.
*/
- void updateInvariantOutputForModulation(InvariantOutput* inout) const {
- if (inout->isOpaque() && GrPixelConfigIsOpaque(this->texture(0)->config())) {
- inout->fValidFlags = kA_GrColorComponentFlag;
+ void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const {
+ if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
+ GrPixelConfigIsOpaque(this->texture(0)->config())) {
+ *validFlags = kA_GrColorComponentFlag;
} else {
- inout->fValidFlags = 0;
+ *validFlags = 0;
}
}
this->fTextureDomain == s.fTextureDomain;
}
-void GrTextureDomainEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
+void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
if (GrTextureDomain::kDecal_Mode == fTextureDomain.mode()) { // TODO: helper
- inout->fValidFlags = 0;
+ *validFlags = 0;
} else {
- this->updateInvariantOutputForModulation(inout);
+ this->updateConstantColorComponentsForModulation(color, validFlags);
}
- inout->fIsSingleComponent = false;
}
///////////////////////////////////////////////////////////////////////////////
typedef GrGLTextureDomainEffect GLProcessor;
virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
const GrTextureDomain& textureDomain() const { return fTextureDomain; }
virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE;
-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef GrSingleTextureEffect INHERITED;
return GrTBackendFragmentProcessorFactory<YUVtoRGBEffect>::getInstance();
}
+ virtual void getConstantColorComponents(GrColor* color,
+ uint32_t* validFlags) const SK_OVERRIDE {
+ // YUV is opaque
+ *color = 0xFF;
+ *validFlags = kA_GrColorComponentFlag;
+ }
+
SkYUVColorSpace getColorSpace() const {
return fColorSpace;
}
fColorSpace == s.getColorSpace();
}
- virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
- // YUV is opaque
- inout->fColor = 0xFF;
- inout->fValidFlags = kA_GrColorComponentFlag;
- inout->fIsSingleComponent = false;
- }
-
GrCoordTransform fCoordTransform;
GrTextureAccess fYAccess;
GrTextureAccess fUAccess;
const GetConstantComponentTestCase& test = filterTests[i];
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(test.filterColor, test.filterMode));
SkAutoTUnref<GrFragmentProcessor> effect(cf->asFragmentProcessor(grContext));
- GrProcessor::InvariantOutput inout;
- inout.fColor = test.inputColor;
- inout.fValidFlags = test.inputComponents;
- inout.fIsSingleComponent = false;
- effect->computeInvariantOutput(&inout);
-
- REPORTER_ASSERT(reporter, filterColor(inout.fColor, inout.fValidFlags) == test.outputColor);
- REPORTER_ASSERT(reporter, test.outputComponents == inout.fValidFlags);
+ GrColor color = test.inputColor;
+ uint32_t components = test.inputComponents;
+ effect->getConstantColorComponents(&color, &components);
+
+ REPORTER_ASSERT(reporter, filterColor(color, components) == test.outputColor);
+ REPORTER_ASSERT(reporter, test.outputComponents == components);
}
}