bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrDrawState.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 9 | |
egdaniel | b1cff03 | 2014-11-13 06:19:25 -0800 | [diff] [blame] | 10 | #include "GrBlend.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 11 | #include "GrOptDrawState.h" |
| 12 | #include "GrPaint.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 13 | #include "GrProcOptInfo.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 14 | #include "GrXferProcessor.h" |
| 15 | #include "effects/GrPorterDuffXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 16 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 17 | /////////////////////////////////////////////////////////////////////////////// |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 18 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 19 | bool GrDrawState::isEqual(const GrDrawState& that) const { |
| 20 | bool usingVertexColors = this->hasColorVertexAttribute(); |
| 21 | if (!usingVertexColors && this->fColor != that.fColor) { |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | if (this->getRenderTarget() != that.getRenderTarget() || |
| 26 | this->fColorStages.count() != that.fColorStages.count() || |
| 27 | this->fCoverageStages.count() != that.fCoverageStages.count() || |
| 28 | !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
| 29 | this->fSrcBlend != that.fSrcBlend || |
| 30 | this->fDstBlend != that.fDstBlend || |
| 31 | this->fBlendConstant != that.fBlendConstant || |
| 32 | this->fFlagBits != that.fFlagBits || |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 33 | this->fStencilSettings != that.fStencilSettings || |
| 34 | this->fDrawFace != that.fDrawFace) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | bool usingVertexCoverage = this->hasCoverageVertexAttribute(); |
| 39 | if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | bool explicitLocalCoords = this->hasLocalCoordAttribute(); |
| 44 | if (this->hasGeometryProcessor()) { |
| 45 | if (!that.hasGeometryProcessor()) { |
| 46 | return false; |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 47 | } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProcessor())) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 48 | return false; |
| 49 | } |
| 50 | } else if (that.hasGeometryProcessor()) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | for (int i = 0; i < this->numColorStages(); i++) { |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 55 | if (!GrFragmentStage::AreCompatible(this->getColorStage(i), that.getColorStage(i), |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 56 | explicitLocalCoords)) { |
| 57 | return false; |
| 58 | } |
| 59 | } |
| 60 | for (int i = 0; i < this->numCoverageStages(); i++) { |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 61 | if (!GrFragmentStage::AreCompatible(this->getCoverageStage(i), that.getCoverageStage(i), |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 62 | explicitLocalCoords)) { |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 67 | return true; |
| 68 | } |
| 69 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 70 | //////////////////////////////////////////////////////////////////////////////s |
| 71 | |
egdaniel | 69bb90c | 2014-11-11 07:32:45 -0800 | [diff] [blame] | 72 | GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) { |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 73 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 74 | *this = state; |
| 75 | if (!preConcatMatrix.isIdentity()) { |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 76 | for (int i = 0; i < this->numColorStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 77 | fColorStages[i].localCoordChange(preConcatMatrix); |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 78 | } |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 79 | for (int i = 0; i < this->numCoverageStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 80 | fCoverageStages[i].localCoordChange(preConcatMatrix); |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 81 | } |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 86 | fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 87 | fColor = that.fColor; |
| 88 | fViewMatrix = that.fViewMatrix; |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 89 | fSrcBlend = that.fSrcBlend; |
| 90 | fDstBlend = that.fDstBlend; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 91 | fBlendConstant = that.fBlendConstant; |
| 92 | fFlagBits = that.fFlagBits; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 93 | fStencilSettings = that.fStencilSettings; |
| 94 | fCoverage = that.fCoverage; |
| 95 | fDrawFace = that.fDrawFace; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 96 | fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 97 | fXPFactory.reset(SkRef(that.getXPFactory())); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 98 | fColorStages = that.fColorStages; |
| 99 | fCoverageStages = that.fCoverageStages; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 100 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 101 | fHints = that.fHints; |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 102 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 103 | fColorProcInfoValid = that.fColorProcInfoValid; |
| 104 | fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
| 105 | if (fColorProcInfoValid) { |
| 106 | fColorProcInfo = that.fColorProcInfo; |
| 107 | } |
| 108 | if (fCoverageProcInfoValid) { |
| 109 | fCoverageProcInfo = that.fCoverageProcInfo; |
| 110 | } |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 111 | return *this; |
| 112 | } |
| 113 | |
| 114 | void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
| 115 | SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 116 | fRenderTarget.reset(NULL); |
bsalomon | 2a9ca78 | 2014-09-05 14:27:43 -0700 | [diff] [blame] | 117 | |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 118 | fGeometryProcessor.reset(NULL); |
egdaniel | c016fb8 | 2014-12-03 11:41:54 -0800 | [diff] [blame^] | 119 | fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 120 | fColorStages.reset(); |
| 121 | fCoverageStages.reset(); |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 122 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 123 | fColor = 0xffffffff; |
| 124 | if (NULL == initialViewMatrix) { |
| 125 | fViewMatrix.reset(); |
| 126 | } else { |
| 127 | fViewMatrix = *initialViewMatrix; |
| 128 | } |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 129 | fSrcBlend = kOne_GrBlendCoeff; |
| 130 | fDstBlend = kZero_GrBlendCoeff; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 131 | fBlendConstant = 0x0; |
| 132 | fFlagBits = 0x0; |
| 133 | fStencilSettings.setDisabled(); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 134 | fCoverage = 0xff; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 135 | fDrawFace = kBoth_DrawFace; |
| 136 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 137 | fHints = 0; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 138 | |
| 139 | fColorProcInfoValid = false; |
| 140 | fCoverageProcInfoValid = false; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 141 | } |
| 142 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 143 | bool GrDrawState::setIdentityViewMatrix() { |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 144 | if (this->numFragmentStages()) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 145 | SkMatrix invVM; |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 146 | if (!fViewMatrix.invert(&invVM)) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 147 | // sad trombone sound |
| 148 | return false; |
| 149 | } |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 150 | for (int s = 0; s < this->numColorStages(); ++s) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 151 | fColorStages[s].localCoordChange(invVM); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 152 | } |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 153 | for (int s = 0; s < this->numCoverageStages(); ++s) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 154 | fCoverageStages[s].localCoordChange(invVM); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 157 | fViewMatrix.reset(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 161 | void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRenderTarget* rt) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 162 | SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 163 | |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 164 | fGeometryProcessor.reset(NULL); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 165 | fColorStages.reset(); |
| 166 | fCoverageStages.reset(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 167 | |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 168 | for (int i = 0; i < paint.numColorStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 169 | fColorStages.push_back(paint.getColorStage(i)); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 170 | } |
| 171 | |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 172 | for (int i = 0; i < paint.numCoverageStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 173 | fCoverageStages.push_back(paint.getCoverageStage(i)); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 174 | } |
| 175 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 176 | fXPFactory.reset(SkRef(paint.getXPFactory())); |
| 177 | |
| 178 | this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 179 | this->setRenderTarget(rt); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 180 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 181 | fViewMatrix = vm; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 182 | |
| 183 | // These have no equivalent in GrPaint, set them to defaults |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 184 | fBlendConstant = 0x0; |
| 185 | fDrawFace = kBoth_DrawFace; |
| 186 | fStencilSettings.setDisabled(); |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 187 | fFlagBits = 0; |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 188 | fHints = 0; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 189 | |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 190 | // Enable the clip bit |
| 191 | this->enableState(GrDrawState::kClip_StateBit); |
| 192 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 193 | this->setColor(paint.getColor()); |
bsalomon@google.com | c7448ce | 2012-10-05 19:04:13 +0000 | [diff] [blame] | 194 | this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 195 | this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 196 | |
joshualitt | 4052a8e | 2014-11-11 13:46:30 -0800 | [diff] [blame] | 197 | this->setCoverage(0xFF); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 198 | fColorProcInfoValid = false; |
| 199 | fCoverageProcInfoValid = false; |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 200 | } |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 201 | |
| 202 | //////////////////////////////////////////////////////////////////////////////// |
| 203 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 204 | bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const { |
| 205 | if (caps.dualSourceBlendingSupport()) { |
| 206 | return true; |
| 207 | } |
| 208 | // we can correctly apply coverage if a) we have dual source blending |
| 209 | // or b) one of our blend optimizations applies |
| 210 | // or c) the src, dst blend coeffs are 1,0 and we will read Dst Color |
| 211 | GrBlendCoeff srcCoeff; |
| 212 | GrBlendCoeff dstCoeff; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 213 | BlendOpt opt = this->getBlendOpt(true, &srcCoeff, &dstCoeff); |
| 214 | return GrDrawState::kNone_BlendOpt != opt || |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 215 | (this->willEffectReadDstColor() && |
| 216 | kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff); |
| 217 | } |
| 218 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 219 | bool GrDrawState::hasSolidCoverage() const { |
| 220 | // If we're drawing coverage directly then coverage is effectively treated as color. |
| 221 | if (this->isCoverageDrawing()) { |
| 222 | return true; |
| 223 | } |
| 224 | |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 225 | if (this->numCoverageStages() > 0) { |
| 226 | return false; |
| 227 | } |
| 228 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 229 | this->calcCoverageInvariantOutput(); |
| 230 | return fCoverageProcInfo.isSolidWhite(); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 231 | } |
| 232 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 233 | //////////////////////////////////////////////////////////////////////////////s |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 234 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 235 | bool GrDrawState::willEffectReadDstColor() const { |
| 236 | if (!this->isColorWriteDisabled()) { |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 237 | this->calcColorInvariantOutput(); |
| 238 | if (fColorProcInfo.readsDst()) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 242 | this->calcCoverageInvariantOutput(); |
| 243 | return fCoverageProcInfo.readsDst(); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 244 | } |
| 245 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 246 | void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 247 | if (fDrawState) { |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 248 | // See the big comment on the class definition about GPs. |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 249 | if (SK_InvalidUniqueID == fOriginalGPID) { |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 250 | fDrawState->fGeometryProcessor.reset(NULL); |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 251 | } else { |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 252 | SkASSERT(fDrawState->getGeometryProcessor()->getUniqueID() == |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 253 | fOriginalGPID); |
| 254 | fOriginalGPID = SK_InvalidUniqueID; |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 255 | } |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 256 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 257 | int m = fDrawState->numColorStages() - fColorEffectCnt; |
| 258 | SkASSERT(m >= 0); |
| 259 | fDrawState->fColorStages.pop_back_n(m); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 260 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 261 | int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; |
| 262 | SkASSERT(n >= 0); |
| 263 | fDrawState->fCoverageStages.pop_back_n(n); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 264 | if (m + n > 0) { |
| 265 | fDrawState->fColorProcInfoValid = false; |
| 266 | fDrawState->fCoverageProcInfoValid = false; |
| 267 | } |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 268 | SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 269 | } |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 270 | fDrawState = ds; |
| 271 | if (NULL != ds) { |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 272 | SkASSERT(SK_InvalidUniqueID == fOriginalGPID); |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 273 | if (NULL != ds->getGeometryProcessor()) { |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 274 | fOriginalGPID = ds->getGeometryProcessor()->getUniqueID(); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 275 | } |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 276 | fColorEffectCnt = ds->numColorStages(); |
| 277 | fCoverageEffectCnt = ds->numCoverageStages(); |
| 278 | SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) |
| 279 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 280 | } |
| 281 | |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 282 | //////////////////////////////////////////////////////////////////////////////// |
| 283 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 284 | // Some blend modes allow folding a fractional coverage value into the color's alpha channel, while |
| 285 | // others will blend incorrectly. |
| 286 | bool GrDrawState::canTweakAlphaForCoverage() const { |
| 287 | /* |
| 288 | The fractional coverage is f. |
| 289 | The src and dst coeffs are Cs and Cd. |
| 290 | The dst and src colors are S and D. |
| 291 | We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the source color's alpha |
| 292 | we're replacing S with S'=fS. It's obvious that that first term will always be ok. The second |
| 293 | term can be rearranged as [1-(1-Cd)f]D. By substituting in the various possibilities for Cd we |
| 294 | find that only 1, ISA, and ISC produce the correct destination when applied to S' and D. |
| 295 | Also, if we're directly rendering coverage (isCoverageDrawing) then coverage is treated as |
| 296 | color by definition. |
| 297 | */ |
| 298 | return kOne_GrBlendCoeff == fDstBlend || |
| 299 | kISA_GrBlendCoeff == fDstBlend || |
| 300 | kISC_GrBlendCoeff == fDstBlend || |
| 301 | this->isCoverageDrawing(); |
| 302 | } |
| 303 | |
| 304 | //////////////////////////////////////////////////////////////////////////////// |
| 305 | |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 306 | void GrDrawState::AutoViewMatrixRestore::restore() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 307 | if (fDrawState) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 308 | SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 309 | fDrawState->fViewMatrix = fViewMatrix; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 310 | SkASSERT(fDrawState->numColorStages() >= fNumColorStages); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 311 | int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 312 | SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 313 | |
| 314 | int i = 0; |
| 315 | for (int s = 0; s < fNumColorStages; ++s, ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 316 | fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 317 | } |
| 318 | for (int s = 0; s < numCoverageStages; ++s, ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 319 | fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]); |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 320 | } |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 321 | fDrawState = NULL; |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 322 | } |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 326 | const SkMatrix& preconcatMatrix) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 327 | this->restore(); |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 328 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 329 | SkASSERT(NULL == fDrawState); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 330 | if (NULL == drawState || preconcatMatrix.isIdentity()) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 331 | return; |
| 332 | } |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 333 | fDrawState = drawState; |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 334 | |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 335 | fViewMatrix = drawState->getViewMatrix(); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 336 | drawState->fViewMatrix.preConcat(preconcatMatrix); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 337 | |
| 338 | this->doEffectCoordChanges(preconcatMatrix); |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 339 | SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 340 | } |
| 341 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 342 | bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 343 | this->restore(); |
| 344 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 345 | if (NULL == drawState) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 346 | return false; |
skia.committer@gmail.com | f467ce7 | 2012-10-09 02:01:37 +0000 | [diff] [blame] | 347 | } |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 348 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 349 | if (drawState->getViewMatrix().isIdentity()) { |
| 350 | return true; |
| 351 | } |
| 352 | |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 353 | fViewMatrix = drawState->getViewMatrix(); |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 354 | if (0 == drawState->numFragmentStages()) { |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 355 | drawState->fViewMatrix.reset(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 356 | fDrawState = drawState; |
| 357 | fNumColorStages = 0; |
| 358 | fSavedCoordChanges.reset(0); |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 359 | SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 360 | return true; |
| 361 | } else { |
| 362 | SkMatrix inv; |
| 363 | if (!fViewMatrix.invert(&inv)) { |
| 364 | return false; |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 365 | } |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 366 | drawState->fViewMatrix.reset(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 367 | fDrawState = drawState; |
| 368 | this->doEffectCoordChanges(inv); |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 369 | SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 370 | return true; |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 371 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& coordChangeMatrix) { |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 375 | fSavedCoordChanges.reset(fDrawState->numFragmentStages()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 376 | int i = 0; |
| 377 | |
| 378 | fNumColorStages = fDrawState->numColorStages(); |
| 379 | for (int s = 0; s < fNumColorStages; ++s, ++i) { |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 380 | fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 381 | fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 382 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 383 | |
| 384 | int numCoverageStages = fDrawState->numCoverageStages(); |
| 385 | for (int s = 0; s < numCoverageStages; ++s, ++i) { |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 386 | fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 387 | fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 388 | } |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 389 | } |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 390 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 391 | //////////////////////////////////////////////////////////////////////////////// |
| 392 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 393 | GrDrawState::~GrDrawState() { |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 394 | SkASSERT(0 == fBlockEffectRemovalCnt); |
| 395 | } |
| 396 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 397 | //////////////////////////////////////////////////////////////////////////////// |
| 398 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 399 | GrDrawState::BlendOpt GrDrawState::getBlendOpt(bool forceCoverage, |
| 400 | GrBlendCoeff* srcCoeff, |
| 401 | GrBlendCoeff* dstCoeff) const { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 402 | GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| 403 | if (NULL == srcCoeff) { |
| 404 | srcCoeff = &bogusSrcCoeff; |
| 405 | } |
| 406 | if (NULL == dstCoeff) { |
| 407 | dstCoeff = &bogusDstCoeff; |
| 408 | } |
| 409 | |
| 410 | *srcCoeff = this->getSrcBlendCoeff(); |
| 411 | *dstCoeff = this->getDstBlendCoeff(); |
| 412 | |
| 413 | if (this->isColorWriteDisabled()) { |
| 414 | *srcCoeff = kZero_GrBlendCoeff; |
| 415 | *dstCoeff = kOne_GrBlendCoeff; |
| 416 | } |
| 417 | |
| 418 | bool srcAIsOne = this->srcAlphaWillBeOne(); |
| 419 | bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || |
| 420 | (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 421 | bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || |
| 422 | (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 423 | |
| 424 | // When coeffs are (0,1) there is no reason to draw at all, unless |
| 425 | // stenciling is enabled. Having color writes disabled is effectively |
| 426 | // (0,1). |
| 427 | if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne)) { |
| 428 | if (this->getStencil().doesWrite()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 429 | return kEmitCoverage_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 430 | } else { |
| 431 | *dstCoeff = kOne_GrBlendCoeff; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 432 | return kSkipDraw_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
| 436 | bool hasCoverage = forceCoverage || !this->hasSolidCoverage(); |
| 437 | |
| 438 | // if we don't have coverage we can check whether the dst |
| 439 | // has to read at all. If not, we'll disable blending. |
| 440 | if (!hasCoverage) { |
| 441 | if (dstCoeffIsZero) { |
| 442 | if (kOne_GrBlendCoeff == *srcCoeff) { |
| 443 | // if there is no coverage and coeffs are (1,0) then we |
| 444 | // won't need to read the dst at all, it gets replaced by src |
| 445 | *dstCoeff = kZero_GrBlendCoeff; |
| 446 | return kNone_BlendOpt; |
| 447 | } else if (kZero_GrBlendCoeff == *srcCoeff) { |
| 448 | // if the op is "clear" then we don't need to emit a color |
| 449 | // or blend, just write transparent black into the dst. |
| 450 | *srcCoeff = kOne_GrBlendCoeff; |
| 451 | *dstCoeff = kZero_GrBlendCoeff; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 452 | return kEmitTransBlack_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | } else if (this->isCoverageDrawing()) { |
| 456 | // we have coverage but we aren't distinguishing it from alpha by request. |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 457 | return kCoverageAsAlpha_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 458 | } else { |
| 459 | // check whether coverage can be safely rolled into alpha |
| 460 | // of if we can skip color computation and just emit coverage |
| 461 | if (this->canTweakAlphaForCoverage()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 462 | return kCoverageAsAlpha_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 463 | } |
| 464 | if (dstCoeffIsZero) { |
| 465 | if (kZero_GrBlendCoeff == *srcCoeff) { |
| 466 | // the source color is not included in the blend |
| 467 | // the dst coeff is effectively zero so blend works out to: |
| 468 | // (c)(0)D + (1-c)D = (1-c)D. |
| 469 | *dstCoeff = kISA_GrBlendCoeff; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 470 | return kEmitCoverage_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 471 | } else if (srcAIsOne) { |
| 472 | // the dst coeff is effectively zero so blend works out to: |
| 473 | // cS + (c)(0)D + (1-c)D = cS + (1-c)D. |
| 474 | // If Sa is 1 then we can replace Sa with c |
| 475 | // and set dst coeff to 1-Sa. |
| 476 | *dstCoeff = kISA_GrBlendCoeff; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 477 | return kCoverageAsAlpha_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 478 | } |
| 479 | } else if (dstCoeffIsOne) { |
| 480 | // the dst coeff is effectively one so blend works out to: |
| 481 | // cS + (c)(1)D + (1-c)D = cS + D. |
| 482 | *dstCoeff = kOne_GrBlendCoeff; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 483 | return kCoverageAsAlpha_BlendOpt; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
| 487 | return kNone_BlendOpt; |
| 488 | } |
| 489 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 490 | bool GrDrawState::srcAlphaWillBeOne() const { |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 491 | this->calcColorInvariantOutput(); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 492 | if (this->isCoverageDrawing()) { |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 493 | this->calcCoverageInvariantOutput(); |
| 494 | return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque()); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 495 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 496 | return fColorProcInfo.isOpaque(); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 497 | } |
| 498 | |
egdaniel | cd8b630 | 2014-11-11 14:46:05 -0800 | [diff] [blame] | 499 | bool GrDrawState::willBlendWithDst() const { |
| 500 | if (!this->hasSolidCoverage()) { |
| 501 | return true; |
| 502 | } |
| 503 | |
egdaniel | b1cff03 | 2014-11-13 06:19:25 -0800 | [diff] [blame] | 504 | if (this->willEffectReadDstColor()) { |
| 505 | return true; |
egdaniel | cd8b630 | 2014-11-11 14:46:05 -0800 | [diff] [blame] | 506 | } |
egdaniel | b1cff03 | 2014-11-13 06:19:25 -0800 | [diff] [blame] | 507 | |
| 508 | if (GrBlendCoeffRefsDst(this->getSrcBlendCoeff())) { |
| 509 | return true; |
| 510 | } |
| 511 | |
| 512 | GrBlendCoeff dstCoeff = this->getDstBlendCoeff(); |
| 513 | if (!(kZero_GrBlendCoeff == dstCoeff || |
| 514 | (kISA_GrBlendCoeff == dstCoeff && this->srcAlphaWillBeOne()))) { |
egdaniel | cd8b630 | 2014-11-11 14:46:05 -0800 | [diff] [blame] | 515 | return true; |
| 516 | } |
| 517 | |
| 518 | return false; |
| 519 | } |
| 520 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 521 | void GrDrawState::calcColorInvariantOutput() const { |
| 522 | if (!fColorProcInfoValid) { |
| 523 | GrColor color; |
| 524 | GrColorComponentFlags flags; |
| 525 | if (this->hasColorVertexAttribute()) { |
| 526 | if (fHints & kVertexColorsAreOpaque_Hint) { |
| 527 | flags = kA_GrColorComponentFlag; |
| 528 | color = 0xFF << GrColor_SHIFT_A; |
| 529 | } else { |
| 530 | flags = static_cast<GrColorComponentFlags>(0); |
| 531 | color = 0; |
| 532 | } |
| 533 | } else { |
| 534 | flags = kRGBA_GrColorComponentFlags; |
| 535 | color = this->getColor(); |
| 536 | } |
| 537 | fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), |
| 538 | color, flags, false); |
| 539 | fColorProcInfoValid = true; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | void GrDrawState::calcCoverageInvariantOutput() const { |
| 544 | if (!fCoverageProcInfoValid) { |
| 545 | GrColor color; |
| 546 | GrColorComponentFlags flags; |
| 547 | // Check if per-vertex or constant color may have partial alpha |
| 548 | if (this->hasCoverageVertexAttribute()) { |
| 549 | flags = static_cast<GrColorComponentFlags>(0); |
| 550 | color = 0; |
| 551 | } else { |
| 552 | flags = kRGBA_GrColorComponentFlags; |
| 553 | color = this->getCoverageColor(); |
| 554 | } |
| 555 | fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(), |
| 556 | color, flags, true, fGeometryProcessor.get()); |
| 557 | fCoverageProcInfoValid = true; |
| 558 | } |
| 559 | } |
| 560 | |