Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: src/gpu/GrDrawState.cpp

Issue 766653008: Revert of Make all blending up to GrOptDrawState be handled by the xp/xp factory. (Closed) Base URL: https://skia.googlesource.com/skia.git@xferFactorySolo
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrOptDrawState.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDrawState.cpp
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index 51ef6cf5d3c8302c815aacb2ba356278c35c25f5..8c2d75f0b502715d2d8d0e25411b08530d1b4671 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -14,6 +14,8 @@
#include "GrXferProcessor.h"
#include "effects/GrPorterDuffXferProcessor.h"
+///////////////////////////////////////////////////////////////////////////////
+
bool GrDrawState::isEqual(const GrDrawState& that) const {
bool usingVertexColors = this->hasColorVertexAttribute();
if (!usingVertexColors && this->fColor != that.fColor) {
@@ -24,6 +26,9 @@
this->fColorStages.count() != that.fColorStages.count() ||
this->fCoverageStages.count() != that.fCoverageStages.count() ||
!this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
+ this->fSrcBlend != that.fSrcBlend ||
+ this->fDstBlend != that.fDstBlend ||
+ this->fBlendConstant != that.fBlendConstant ||
this->fFlagBits != that.fFlagBits ||
this->fStencilSettings != that.fStencilSettings ||
this->fDrawFace != that.fDrawFace) {
@@ -85,6 +90,9 @@
fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get()));
fColor = that.fColor;
fViewMatrix = that.fViewMatrix;
+ fSrcBlend = that.fSrcBlend;
+ fDstBlend = that.fDstBlend;
+ fBlendConstant = that.fBlendConstant;
fFlagBits = that.fFlagBits;
fStencilSettings = that.fStencilSettings;
fCoverage = that.fCoverage;
@@ -122,6 +130,9 @@
} else {
fViewMatrix = *initialViewMatrix;
}
+ fSrcBlend = kOne_GrBlendCoeff;
+ fDstBlend = kZero_GrBlendCoeff;
+ fBlendConstant = 0x0;
fFlagBits = 0x0;
fStencilSettings.setDisabled();
fCoverage = 0xff;
@@ -168,11 +179,13 @@
fXPFactory.reset(SkRef(paint.getXPFactory()));
+ this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff());
this->setRenderTarget(rt);
fViewMatrix = vm;
// These have no equivalent in GrPaint, set them to defaults
+ fBlendConstant = 0x0;
fDrawFace = kBoth_DrawFace;
fStencilSettings.setDisabled();
fFlagBits = 0;
@@ -196,11 +209,15 @@
if (caps.dualSourceBlendingSupport()) {
return true;
}
-
- this->calcColorInvariantOutput();
- this->calcCoverageInvariantOutput();
- return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo,
- this->isCoverageDrawing(), this->isColorWriteDisabled());
+ // we can correctly apply coverage if a) we have dual source blending
+ // or b) one of our blend optimizations applies
+ // or c) the src, dst blend coeffs are 1,0 and we will read Dst Color
+ GrBlendCoeff srcCoeff;
+ GrBlendCoeff dstCoeff;
+ BlendOpt opt = this->getBlendOpt(true, &srcCoeff, &dstCoeff);
+ return GrDrawState::kNone_BlendOpt != opt ||
+ (this->willEffectReadDstColor() &&
+ kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff);
}
bool GrDrawState::hasSolidCoverage() const {
@@ -220,22 +237,13 @@
//////////////////////////////////////////////////////////////////////////////s
bool GrDrawState::willEffectReadDstColor() const {
- this->calcColorInvariantOutput();
- this->calcCoverageInvariantOutput();
- // TODO: Remove need to create the XP here.
- // Also once all custom blends are turned into XPs we can remove the need
- // to check other stages since only xp's will be able to read dst
- SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor(fColorProcInfo,
- fCoverageProcInfo));
- if (xferProcessor && xferProcessor->willReadDstColor()) {
- return true;
- }
-
if (!this->isColorWriteDisabled()) {
+ this->calcColorInvariantOutput();
if (fColorProcInfo.readsDst()) {
return true;
}
}
+ this->calcCoverageInvariantOutput();
return fCoverageProcInfo.readsDst();
}
@@ -280,7 +288,21 @@
// Some blend modes allow folding a fractional coverage value into the color's alpha channel, while
// others will blend incorrectly.
bool GrDrawState::canTweakAlphaForCoverage() const {
- return fXPFactory->canTweakAlphaForCoverage(this->isCoverageDrawing());
+ /*
+ The fractional coverage is f.
+ The src and dst coeffs are Cs and Cd.
+ The dst and src colors are S and D.
+ We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the source color's alpha
+ we're replacing S with S'=fS. It's obvious that that first term will always be ok. The second
+ term can be rearranged as [1-(1-Cd)f]D. By substituting in the various possibilities for Cd we
+ find that only 1, ISA, and ISC produce the correct destination when applied to S' and D.
+ Also, if we're directly rendering coverage (isCoverageDrawing) then coverage is treated as
+ color by definition.
+ */
+ return kOne_GrBlendCoeff == fDstBlend ||
+ kISA_GrBlendCoeff == fDstBlend ||
+ kISC_GrBlendCoeff == fDstBlend ||
+ this->isCoverageDrawing();
}
////////////////////////////////////////////////////////////////////////////////
@@ -378,6 +400,97 @@
////////////////////////////////////////////////////////////////////////////////
+GrDrawState::BlendOpt GrDrawState::getBlendOpt(bool forceCoverage,
+ GrBlendCoeff* srcCoeff,
+ GrBlendCoeff* dstCoeff) const {
+ GrBlendCoeff bogusSrcCoeff, bogusDstCoeff;
+ if (NULL == srcCoeff) {
+ srcCoeff = &bogusSrcCoeff;
+ }
+ if (NULL == dstCoeff) {
+ dstCoeff = &bogusDstCoeff;
+ }
+
+ *srcCoeff = this->getSrcBlendCoeff();
+ *dstCoeff = this->getDstBlendCoeff();
+
+ if (this->isColorWriteDisabled()) {
+ *srcCoeff = kZero_GrBlendCoeff;
+ *dstCoeff = kOne_GrBlendCoeff;
+ }
+
+ bool srcAIsOne = this->srcAlphaWillBeOne();
+ bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff ||
+ (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne);
+ bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff ||
+ (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne);
+
+ // When coeffs are (0,1) there is no reason to draw at all, unless
+ // stenciling is enabled. Having color writes disabled is effectively
+ // (0,1).
+ if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne)) {
+ if (this->getStencil().doesWrite()) {
+ return kEmitCoverage_BlendOpt;
+ } else {
+ *dstCoeff = kOne_GrBlendCoeff;
+ return kSkipDraw_BlendOpt;
+ }
+ }
+
+ bool hasCoverage = forceCoverage || !this->hasSolidCoverage();
+
+ // if we don't have coverage we can check whether the dst
+ // has to read at all. If not, we'll disable blending.
+ if (!hasCoverage) {
+ if (dstCoeffIsZero) {
+ if (kOne_GrBlendCoeff == *srcCoeff) {
+ // if there is no coverage and coeffs are (1,0) then we
+ // won't need to read the dst at all, it gets replaced by src
+ *dstCoeff = kZero_GrBlendCoeff;
+ return kNone_BlendOpt;
+ } else if (kZero_GrBlendCoeff == *srcCoeff) {
+ // if the op is "clear" then we don't need to emit a color
+ // or blend, just write transparent black into the dst.
+ *srcCoeff = kOne_GrBlendCoeff;
+ *dstCoeff = kZero_GrBlendCoeff;
+ return kEmitTransBlack_BlendOpt;
+ }
+ }
+ } else if (this->isCoverageDrawing()) {
+ // we have coverage but we aren't distinguishing it from alpha by request.
+ return kCoverageAsAlpha_BlendOpt;
+ } else {
+ // check whether coverage can be safely rolled into alpha
+ // of if we can skip color computation and just emit coverage
+ if (this->canTweakAlphaForCoverage()) {
+ return kCoverageAsAlpha_BlendOpt;
+ }
+ if (dstCoeffIsZero) {
+ if (kZero_GrBlendCoeff == *srcCoeff) {
+ // the source color is not included in the blend
+ // the dst coeff is effectively zero so blend works out to:
+ // (c)(0)D + (1-c)D = (1-c)D.
+ *dstCoeff = kISA_GrBlendCoeff;
+ return kEmitCoverage_BlendOpt;
+ } else if (srcAIsOne) {
+ // the dst coeff is effectively zero so blend works out to:
+ // cS + (c)(0)D + (1-c)D = cS + (1-c)D.
+ // If Sa is 1 then we can replace Sa with c
+ // and set dst coeff to 1-Sa.
+ *dstCoeff = kISA_GrBlendCoeff;
+ return kCoverageAsAlpha_BlendOpt;
+ }
+ } else if (dstCoeffIsOne) {
+ // the dst coeff is effectively one so blend works out to:
+ // cS + (c)(1)D + (1-c)D = cS + D.
+ *dstCoeff = kOne_GrBlendCoeff;
+ return kCoverageAsAlpha_BlendOpt;
+ }
+ }
+
+ return kNone_BlendOpt;
+}
+
bool GrDrawState::srcAlphaWillBeOne() const {
this->calcColorInvariantOutput();
if (this->isCoverageDrawing()) {
@@ -388,10 +501,25 @@
}
bool GrDrawState::willBlendWithDst() const {
- this->calcColorInvariantOutput();
- this->calcCoverageInvariantOutput();
- return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo,
- this->isCoverageDrawing(), this->isColorWriteDisabled());
+ if (!this->hasSolidCoverage()) {
+ return true;
+ }
+
+ if (this->willEffectReadDstColor()) {
+ return true;
+ }
+
+ if (GrBlendCoeffRefsDst(this->getSrcBlendCoeff())) {
+ return true;
+ }
+
+ GrBlendCoeff dstCoeff = this->getDstBlendCoeff();
+ if (!(kZero_GrBlendCoeff == dstCoeff ||
+ (kISA_GrBlendCoeff == dstCoeff && this->srcAlphaWillBeOne()))) {
+ return true;
+ }
+
+ return false;
}
void GrDrawState::calcColorInvariantOutput() const {
@@ -433,3 +561,4 @@
fCoverageProcInfoValid = true;
}
}
+
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrOptDrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698