diff options
author | 2014-08-18 11:49:37 -0700 | |
---|---|---|
committer | 2014-08-18 11:49:38 -0700 | |
commit | 637e57e3beca3a2b488b16997d428406bb6f655f (patch) | |
tree | cbd30c0cc143e5771a3d3cc01c72b9d7854976a4 | |
parent | 62b67ae96e94fd22569b058a3bc4625b9f52ed56 (diff) |
Fix srcAlpaWillBeOne() for coverage drawing
R=egdaniel@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/480113002
-rw-r--r-- | src/gpu/GrDrawState.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp index d54d085d0e..e13c6057f8 100644 --- a/src/gpu/GrDrawState.cpp +++ b/src/gpu/GrDrawState.cpp @@ -396,22 +396,32 @@ bool GrDrawState::srcAlphaWillBeOne() const { // Check whether coverage is treated as color. If so we run through the coverage computation. if (this->isCoverageDrawing()) { - GrColor coverageColor = this->getCoverageColor(); - GrColor oldColor = color; - color = 0; - for (int c = 0; c < 4; ++c) { - if (validComponentFlags & (1 << c)) { - U8CPU a = (oldColor >> (c * 8)) & 0xff; - U8CPU b = (coverageColor >> (c * 8)) & 0xff; - color |= (SkMulDiv255Round(a, b) << (c * 8)); - } + // 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. + GrColor coverage; + uint32_t coverageComponentFlags; + if (this->hasCoverageVertexAttribute()) { + coverageComponentFlags = 0; + coverage = 0; // suppresses any warnings. + } else { + coverageComponentFlags = kRGBA_GrColorComponentFlags; + coverage = this->getCoverageColor(); } + + // Run through the coverage stages for (int s = 0; s < this->numCoverageStages(); ++s) { const GrEffect* effect = this->getCoverageStage(s).getEffect(); - effect->getConstantColorComponents(&color, &validComponentFlags); + effect->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 (kA_GrColorComponentFlag & validComponentFlags & coverageComponentFlags) && + 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage); + } - return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnpackA(color); + + return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnpackA(color); } bool GrDrawState::hasSolidCoverage() const { |