Add a state bit to GrDrawState that forces coverage to be blended.
Use this mode in GrClipMaskManager.
R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6945048
git-svn-id: http://skia.googlecode.com/svn/trunk@6790 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 6927895..92b8a03 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -806,14 +806,15 @@
* 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 substituing in the various possbilities
+ * 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 depth
- * coeffecient in terms of S' and D.
+ * coefficient in terms of S' and D.
*/
GrBlendCoeff dstCoeff = this->getDrawState().getDstBlendCoeff();
return kOne_GrBlendCoeff == dstCoeff ||
kISA_GrBlendCoeff == dstCoeff ||
- kISC_GrBlendCoeff == dstCoeff;
+ kISC_GrBlendCoeff == dstCoeff ||
+ this->getDrawState().isCoverageDrawing();
}
bool GrDrawTarget::srcAlphaWillBeOne(GrVertexLayout layout) const {
@@ -830,10 +831,20 @@
if (SkXfermode::kDst_Mode != drawState.getColorFilterMode()) {
return false;
}
+ int stageCnt;
+ // Check whether coverage is treated as color
+ if (drawState.isCoverageDrawing()) {
+ if (0xff != GrColorUnpackA(drawState.getCoverage())) {
+ return false;
+ }
+ stageCnt = GrDrawState::kNumStages;
+ } else {
+ stageCnt = drawState.getFirstCoverageStage();
+ }
// Check if a color stage could create a partial alpha
- for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) {
- if (this->isStageEnabled(s)) {
- const GrEffect* effect = drawState.getStage(s).getEffect();
+ for (int s = 0; s < stageCnt; ++s) {
+ const GrEffect* effect = drawState.getStage(s).getEffect();
+ if (NULL != effect) {
// FIXME: The param indicates whether the texture is opaque or not. However, the effect
// already controls its textures. It really needs to know whether the incoming color
// (from a uni, per-vertex colors, or previous stage) is opaque or not.
@@ -877,17 +888,6 @@
}
*dstCoeff = drawState.getDstBlendCoeff();
- // We don't ever expect source coeffecients to reference the source
- GrAssert(kSA_GrBlendCoeff != *srcCoeff &&
- kISA_GrBlendCoeff != *srcCoeff &&
- kSC_GrBlendCoeff != *srcCoeff &&
- kISC_GrBlendCoeff != *srcCoeff);
- // same for dst
- GrAssert(kDA_GrBlendCoeff != *dstCoeff &&
- kIDA_GrBlendCoeff != *dstCoeff &&
- kDC_GrBlendCoeff != *dstCoeff &&
- kIDC_GrBlendCoeff != *dstCoeff);
-
if (drawState.isColorWriteDisabled()) {
*srcCoeff = kZero_GrBlendCoeff;
*dstCoeff = kOne_GrBlendCoeff;
@@ -899,13 +899,13 @@
bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff ||
(kISA_GrBlendCoeff == *dstCoeff && srcAIsOne);
-
+ bool covIsZero = !drawState.isCoverageDrawing() &&
+ !(layout & kCoverage_VertexLayoutBit) &&
+ 0 == drawState.getCoverage();
// 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). The same applies when coverage is known to be 0.
- if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) ||
- (!(layout & kCoverage_VertexLayoutBit) &&
- 0 == drawState.getCoverage())) {
+ if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) {
if (drawState.getStencil().doesWrite()) {
return kDisableBlend_BlendOptFlag |
kEmitTransBlack_BlendOptFlag;
@@ -941,10 +941,12 @@
// or blend, just write transparent black into the dst.
*srcCoeff = kOne_GrBlendCoeff;
*dstCoeff = kZero_GrBlendCoeff;
- return kDisableBlend_BlendOptFlag |
- kEmitTransBlack_BlendOptFlag;
+ return kDisableBlend_BlendOptFlag | kEmitTransBlack_BlendOptFlag;
}
}
+ } else if (drawState.isCoverageDrawing()) {
+ // we have coverage but we aren't distinguishing it from alpha by request.
+ return kCoverageAsAlpha_BlendOptFlag;
} else {
// check whether coverage can be safely rolled into alpha
// of if we can skip color computation and just emit coverage