Remove willReadDst from GrFragmentProcessor.
Since only XP's can read dst now, there is no reason to have this query on GrFP. This also triggered a chain reaction of cleaning up/removing unnecessary code elsewhere. BUG=skia: Review URL: https://codereview.chromium.org/851143003
This commit is contained in:
parent
b2b416d384
commit
71e236c03e
@ -24,7 +24,6 @@ class GrFragmentProcessor : public GrProcessor {
|
||||
public:
|
||||
GrFragmentProcessor()
|
||||
: INHERITED()
|
||||
, fWillReadDstColor(false)
|
||||
, fWillUseInputColor(true)
|
||||
, fUsesLocalCoords(false) {}
|
||||
|
||||
@ -51,9 +50,6 @@ public:
|
||||
return fCoordTransforms;
|
||||
}
|
||||
|
||||
/** Will this prceossor read the destination pixel value? */
|
||||
bool willReadDstColor() const { return fWillReadDstColor; }
|
||||
|
||||
/** Will this prceossor read the source color value? */
|
||||
bool willUseInputColor() const { return fWillUseInputColor; }
|
||||
|
||||
@ -105,13 +101,6 @@ protected:
|
||||
*/
|
||||
void addCoordTransform(const GrCoordTransform*);
|
||||
|
||||
/**
|
||||
* If the prceossor subclass will read the destination pixel value then it must call this
|
||||
* function from its constructor. Otherwise, when its generated backend-specific prceossor class
|
||||
* attempts to generate code that reads the destination pixel it will fail.
|
||||
*/
|
||||
void setWillReadDstColor() { fWillReadDstColor = true; }
|
||||
|
||||
/**
|
||||
* If the prceossor will generate a result that does not depend on the input color value then it
|
||||
* must call this function from its constructor. Otherwise, when its generated backend-specific
|
||||
@ -136,7 +125,6 @@ private:
|
||||
bool hasSameTransforms(const GrFragmentProcessor&) const;
|
||||
|
||||
SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
|
||||
bool fWillReadDstColor;
|
||||
bool fWillUseInputColor;
|
||||
bool fUsesLocalCoords;
|
||||
|
||||
|
@ -205,10 +205,7 @@ public:
|
||||
/**
|
||||
* Returns true if the XP generated by this factory will read dst.
|
||||
*/
|
||||
// TODO: Currently this function must also check if the color/coverage stages read dst.
|
||||
// Once only XP's can read dst we can remove the ProcOptInfo's from this function.
|
||||
virtual bool willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const = 0;
|
||||
virtual bool willReadDst() const = 0;
|
||||
|
||||
bool isEqual(const GrXPFactory& that) const {
|
||||
if (this->classID() != that.classID()) {
|
||||
|
@ -41,9 +41,6 @@ public:
|
||||
kCoverage_PrimaryOutputType,
|
||||
// Modulate color and coverage, write result as the color output.
|
||||
kModulate_PrimaryOutputType,
|
||||
// Combines the coverage, dst, and color as coverage * color + (1 - coverage) * dst. This
|
||||
// can only be set if fDstReadKey is non-zero.
|
||||
kCombineWithDst_PrimaryOutputType,
|
||||
};
|
||||
|
||||
enum SecondaryOutputType {
|
||||
@ -97,7 +94,7 @@ private:
|
||||
bool doesStencilWrite);
|
||||
|
||||
void calcOutputTypes(GrXferProcessor::OptFlags blendOpts, const GrDrawTargetCaps& caps,
|
||||
bool hasSolidCoverage, bool readDst);
|
||||
bool hasSolidCoverage);
|
||||
|
||||
GrBlendCoeff fSrcBlend;
|
||||
GrBlendCoeff fDstBlend;
|
||||
@ -135,8 +132,7 @@ public:
|
||||
void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI,
|
||||
GrXPFactory::InvariantOutput*) const SK_OVERRIDE;
|
||||
|
||||
bool willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const SK_OVERRIDE;
|
||||
bool willReadDst() const SK_OVERRIDE { return false; }
|
||||
|
||||
private:
|
||||
GrPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst);
|
||||
|
@ -154,10 +154,7 @@ public:
|
||||
void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI,
|
||||
GrXPFactory::InvariantOutput*) const SK_OVERRIDE;
|
||||
|
||||
bool willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const SK_OVERRIDE {
|
||||
return true;
|
||||
}
|
||||
bool willReadDst() const SK_OVERRIDE { return true; }
|
||||
|
||||
private:
|
||||
GrArithmeticXPFactory(float k1, float k2, float k3, float k4, bool enforcePMColor);
|
||||
|
@ -147,11 +147,8 @@ bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////s
|
||||
|
||||
bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const {
|
||||
this->calcColorInvariantOutput(pp);
|
||||
this->calcCoverageInvariantOutput(pp);
|
||||
|
||||
return fXPFactory->willReadDst(fColorProcInfo, fCoverageProcInfo);
|
||||
bool GrDrawState::willEffectReadDstColor() const {
|
||||
return fXPFactory->willReadDst();
|
||||
}
|
||||
|
||||
void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
|
||||
|
@ -108,10 +108,10 @@ public:
|
||||
const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
|
||||
|
||||
/**
|
||||
* Checks whether any of the effects will read the dst pixel color.
|
||||
* TODO remove when we have an XP
|
||||
* Checks whether the xp will read the dst pixel color.
|
||||
* TODO: remove when we have dstCpy contained inside of GrXP
|
||||
*/
|
||||
bool willEffectReadDstColor(const GrPrimitiveProcessor*) const;
|
||||
bool willEffectReadDstColor() const;
|
||||
|
||||
/**
|
||||
* The xfer processor factory.
|
||||
|
@ -383,10 +383,9 @@ bool GrDrawTarget::checkDraw(const GrDrawState& drawState,
|
||||
}
|
||||
|
||||
bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds,
|
||||
const GrPrimitiveProcessor* primProc,
|
||||
GrDeviceCoordTexture* dstCopy,
|
||||
const SkRect* drawBounds) {
|
||||
if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor(primProc)) {
|
||||
if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor()) {
|
||||
return true;
|
||||
}
|
||||
SkIRect copyRect;
|
||||
@ -470,7 +469,7 @@ void GrDrawTarget::drawIndexed(GrDrawState* ds,
|
||||
|
||||
// TODO: We should continue with incorrect blending.
|
||||
GrDeviceCoordTexture dstCopy;
|
||||
if (!this->setupDstReadIfNecessary(ds, gp, &dstCopy, devBounds)) {
|
||||
if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) {
|
||||
return;
|
||||
}
|
||||
this->setDrawBuffers(&info, gp->getVertexStride());
|
||||
@ -513,7 +512,7 @@ void GrDrawTarget::drawNonIndexed(GrDrawState* ds,
|
||||
|
||||
// TODO: We should continue with incorrect blending.
|
||||
GrDeviceCoordTexture dstCopy;
|
||||
if (!this->setupDstReadIfNecessary(ds, gp, &dstCopy, devBounds)) {
|
||||
if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -611,7 +610,7 @@ void GrDrawTarget::drawPath(GrDrawState* ds,
|
||||
&stencilSettings);
|
||||
|
||||
GrDeviceCoordTexture dstCopy;
|
||||
if (!this->setupDstReadIfNecessary(ds, pathProc, &dstCopy, &devBounds)) {
|
||||
if (!this->setupDstReadIfNecessary(ds, &dstCopy, &devBounds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -655,7 +654,7 @@ void GrDrawTarget::drawPaths(GrDrawState* ds,
|
||||
// point, because any context that supports NV_path_rendering will also
|
||||
// support NV_blend_equation_advanced.
|
||||
GrDeviceCoordTexture dstCopy;
|
||||
if (!this->setupDstReadIfNecessary(ds, pathProc, &dstCopy, NULL)) {
|
||||
if (!this->setupDstReadIfNecessary(ds, &dstCopy, NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -768,7 +767,7 @@ void GrDrawTarget::drawIndexedInstances(GrDrawState* ds,
|
||||
|
||||
// TODO: We should continue with incorrect blending.
|
||||
GrDeviceCoordTexture dstCopy;
|
||||
if (!this->setupDstReadIfNecessary(ds, gp, &dstCopy, devBounds)) {
|
||||
if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -661,7 +661,6 @@ protected:
|
||||
// but couldn't be made. Otherwise, returns true. This method needs to be protected because it
|
||||
// needs to be accessed by GLPrograms to setup a correct drawstate
|
||||
bool setupDstReadIfNecessary(GrDrawState*,
|
||||
const GrPrimitiveProcessor*,
|
||||
GrDeviceCoordTexture* dstCopy,
|
||||
const SkRect* drawBounds);
|
||||
|
||||
|
@ -89,6 +89,8 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
|
||||
this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coveragePOI,
|
||||
&firstColorStageIdx, &firstCoverageStageIdx);
|
||||
|
||||
fDescInfo.fReadsDst = fXferProcessor->willReadDstColor();
|
||||
|
||||
bool usesLocalCoords = false;
|
||||
|
||||
// Copy Stages from DS to ODS
|
||||
@ -124,31 +126,22 @@ void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds,
|
||||
const GrProcOptInfo& coveragePOI,
|
||||
int* firstColorStageIdx,
|
||||
int* firstCoverageStageIdx) {
|
||||
fDescInfo.fReadsDst = false;
|
||||
fDescInfo.fReadsFragPosition = false;
|
||||
|
||||
if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) ||
|
||||
(flags & GrXferProcessor::kOverrideColor_OptFlag)) {
|
||||
*firstColorStageIdx = ds.numColorStages();
|
||||
} else {
|
||||
fDescInfo.fReadsDst = colorPOI.readsDst();
|
||||
fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition();
|
||||
}
|
||||
|
||||
if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) {
|
||||
*firstCoverageStageIdx = ds.numCoverageStages();
|
||||
} else {
|
||||
if (coveragePOI.readsDst()) {
|
||||
fDescInfo.fReadsDst = true;
|
||||
}
|
||||
if (coveragePOI.readsFragPosition()) {
|
||||
fDescInfo.fReadsFragPosition = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fXferProcessor->willReadDstColor()) {
|
||||
fDescInfo.fReadsDst = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GrOptDrawState::finalize(GrGpu* gpu) {
|
||||
|
@ -48,7 +48,6 @@ void GrProcOptInfo::internalCalc(const GrFragmentStage* stages,
|
||||
fFirstEffectStageIndex = 0;
|
||||
fInputColorIsUsed = true;
|
||||
fInputColor = fInOut.color();
|
||||
fReadsDst = false;
|
||||
fReadsFragPosition = initWillReadFragmentPosition;
|
||||
|
||||
for (int i = 0; i < stageCount; ++i) {
|
||||
@ -60,12 +59,8 @@ void GrProcOptInfo::internalCalc(const GrFragmentStage* stages,
|
||||
fFirstEffectStageIndex = i;
|
||||
fInputColorIsUsed = false;
|
||||
// Reset these since we don't care if previous stages read these values
|
||||
fReadsDst = false;
|
||||
fReadsFragPosition = initWillReadFragmentPosition;
|
||||
}
|
||||
if (processor->willReadDstColor()) {
|
||||
fReadsDst = true;
|
||||
}
|
||||
if (processor->willReadFragmentPosition()) {
|
||||
fReadsFragPosition = true;
|
||||
}
|
||||
@ -77,7 +72,6 @@ void GrProcOptInfo::internalCalc(const GrFragmentStage* stages,
|
||||
// zero stages that don't multiply the inputColor.
|
||||
fInOut.resetNonMulStageFound();
|
||||
// Reset these since we don't care if previous stages read these values
|
||||
fReadsDst = false;
|
||||
fReadsFragPosition = initWillReadFragmentPosition;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ public:
|
||||
, fFirstEffectStageIndex(0)
|
||||
, fInputColorIsUsed(true)
|
||||
, fInputColor(0)
|
||||
, fReadsDst(false)
|
||||
, fReadsFragPosition(false) {}
|
||||
|
||||
void calcWithInitialValues(const GrFragmentStage*, int stageCount, GrColor startColor,
|
||||
@ -74,11 +73,6 @@ public:
|
||||
*/
|
||||
GrColor inputColorToEffectiveStage() const { return fInputColor; }
|
||||
|
||||
/**
|
||||
* Returns true if any of the stages preserved by GrProcOptInfo read the dst color.
|
||||
*/
|
||||
bool readsDst() const { return fReadsDst; }
|
||||
|
||||
/**
|
||||
* Returns true if any of the stages preserved by GrProcOptInfo read the frag position.
|
||||
*/
|
||||
@ -91,7 +85,6 @@ private:
|
||||
int fFirstEffectStageIndex;
|
||||
bool fInputColorIsUsed;
|
||||
GrColor fInputColor;
|
||||
bool fReadsDst;
|
||||
bool fReadsFragPosition;
|
||||
};
|
||||
|
||||
|
@ -195,22 +195,13 @@ void GrCoverageSetOpXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI,
|
||||
output->fBlendedColorFlags = 0;
|
||||
}
|
||||
|
||||
if (coveragePOI.readsDst()) {
|
||||
output->fWillBlendWithDst = true;
|
||||
} else {
|
||||
output->fWillBlendWithDst = false;
|
||||
}
|
||||
output->fWillBlendWithDst = false;
|
||||
} else {
|
||||
output->fBlendedColorFlags = 0;
|
||||
output->fWillBlendWithDst = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool GrCoverageSetOpXPFactory::willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const {
|
||||
return coveragePOI.readsDst();
|
||||
}
|
||||
|
||||
GR_DEFINE_XP_FACTORY_TEST(GrCoverageSetOpXPFactory);
|
||||
|
||||
GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(SkRandom* random,
|
||||
|
@ -83,8 +83,7 @@ public:
|
||||
void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI,
|
||||
GrXPFactory::InvariantOutput*) const SK_OVERRIDE;
|
||||
|
||||
bool willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const SK_OVERRIDE;
|
||||
bool willReadDst() const SK_OVERRIDE { return false; }
|
||||
|
||||
private:
|
||||
GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage);
|
||||
|
@ -126,10 +126,7 @@ public:
|
||||
void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI,
|
||||
GrXPFactory::InvariantOutput*) const SK_OVERRIDE;
|
||||
|
||||
bool willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const SK_OVERRIDE {
|
||||
return true;
|
||||
}
|
||||
bool willReadDst() const SK_OVERRIDE { return true; }
|
||||
|
||||
private:
|
||||
bool onIsEqual(const GrXPFactory& xpfBase) const SK_OVERRIDE {
|
||||
|
@ -81,10 +81,7 @@ public:
|
||||
output->fWillBlendWithDst = 0;
|
||||
}
|
||||
|
||||
bool willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const SK_OVERRIDE {
|
||||
return false;
|
||||
}
|
||||
bool willReadDst() const SK_OVERRIDE { return false; }
|
||||
|
||||
private:
|
||||
GrDisableColorXPFactory();
|
||||
|
@ -72,14 +72,8 @@ public:
|
||||
fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputCoverage);
|
||||
break;
|
||||
case GrPorterDuffXferProcessor::kModulate_PrimaryOutputType:
|
||||
case GrPorterDuffXferProcessor::kCombineWithDst_PrimaryOutputType:
|
||||
fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInputColor,
|
||||
args.fInputCoverage);
|
||||
if (GrPorterDuffXferProcessor::kCombineWithDst_PrimaryOutputType ==
|
||||
xp.primaryOutputType()){
|
||||
fsBuilder->codeAppendf("%s += (vec4(1.0) - %s) * %s;", args.fOutputPrimary,
|
||||
args.fInputCoverage, fsBuilder->dstColor());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
SkFAIL("Unexpected Primary Output");
|
||||
@ -144,14 +138,13 @@ GrPorterDuffXferProcessor::getOptimizations(const GrProcOptInfo& colorPOI,
|
||||
coveragePOI,
|
||||
doesStencilWrite);
|
||||
}
|
||||
this->calcOutputTypes(optFlags, caps, coveragePOI.isSolidWhite(),
|
||||
colorPOI.readsDst() || coveragePOI.readsDst());
|
||||
this->calcOutputTypes(optFlags, caps, coveragePOI.isSolidWhite());
|
||||
return optFlags;
|
||||
}
|
||||
|
||||
void GrPorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFlags,
|
||||
const GrDrawTargetCaps& caps,
|
||||
bool hasSolidCoverage, bool readsDst) {
|
||||
bool hasSolidCoverage) {
|
||||
if (optFlags & kIgnoreColor_OptFlag) {
|
||||
if (optFlags & kIgnoreCoverage_OptFlag) {
|
||||
fPrimaryOutputType = kNone_PrimaryOutputType;
|
||||
@ -184,10 +177,6 @@ void GrPorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFla
|
||||
fSecondaryOutputType = kCoverageISC_SecondaryOutputType;
|
||||
fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
|
||||
}
|
||||
} else if (readsDst &&
|
||||
kOne_GrBlendCoeff == fSrcBlend &&
|
||||
kZero_GrBlendCoeff == fDstBlend) {
|
||||
fPrimaryOutputType = kCombineWithDst_PrimaryOutputType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -419,13 +408,6 @@ bool GrPorterDuffXPFactory::canApplyCoverage(const GrProcOptInfo& colorPOI,
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: once all SkXferEffects are XP's then we will never reads dst here since only XP's
|
||||
// will readDst and PD XP's don't read dst.
|
||||
if ((colorPOI.readsDst() || coveragePOI.readsDst()) &&
|
||||
kOne_GrBlendCoeff == fSrcCoeff && kZero_GrBlendCoeff == fDstCoeff) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -499,20 +481,9 @@ void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI,
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: once all SkXferEffects are XP's then we will never reads dst here since only XP's
|
||||
// will readDst and PD XP's don't read dst.
|
||||
if (colorPOI.readsDst() || coveragePOI.readsDst()) {
|
||||
output->fWillBlendWithDst = true;
|
||||
return;
|
||||
}
|
||||
output->fWillBlendWithDst = false;
|
||||
}
|
||||
|
||||
bool GrPorterDuffXPFactory::willReadDst(const GrProcOptInfo& colorPOI,
|
||||
const GrProcOptInfo& coveragePOI) const {
|
||||
return colorPOI.readsDst() || coveragePOI.readsDst();
|
||||
}
|
||||
|
||||
GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory);
|
||||
|
||||
GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random,
|
||||
|
@ -359,14 +359,11 @@ void GrGLProgramBuilder::verify(const GrPrimitiveProcessor& gp) {
|
||||
}
|
||||
|
||||
void GrGLProgramBuilder::verify(const GrXferProcessor& xp) {
|
||||
// TODO: Once will readDst is only xp enable this assert and remove it from the
|
||||
// FragmentProcessor verify()
|
||||
//SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor());
|
||||
SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor());
|
||||
}
|
||||
|
||||
void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) {
|
||||
SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition());
|
||||
SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor());
|
||||
}
|
||||
|
||||
template <class Proc>
|
||||
|
@ -157,11 +157,6 @@ static void set_random_color_coverage_stages(GrGLGpu* gpu,
|
||||
dummyTextures));
|
||||
SkASSERT(fp);
|
||||
|
||||
// don't add dst color reads to coverage stage
|
||||
if (s >= numColorProcs && fp->willReadDstColor()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If adding this effect would exceed the max texture coord set count then generate a
|
||||
// new random effect.
|
||||
if (usePathRendering && gpu->glPathRendering()->texturingMode() ==
|
||||
@ -310,7 +305,7 @@ bool GrDrawTarget::programUnitTest(int maxStages) {
|
||||
} else {
|
||||
primProc = pathProc.get();
|
||||
}
|
||||
if (!this->setupDstReadIfNecessary(&ds, primProc, &dstCopy, NULL)) {
|
||||
if (!this->setupDstReadIfNecessary(&ds, &dstCopy, NULL)) {
|
||||
SkDebugf("Couldn't setup dst read texture");
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user