| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrDrawState.h" | 8 #include "GrDrawState.h" |
| 9 | 9 |
| 10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
| 11 #include "GrOptDrawState.h" | 11 #include "GrOptDrawState.h" |
| 12 #include "GrPaint.h" | 12 #include "GrPaint.h" |
| 13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
| 14 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
| 15 #include "effects/GrPorterDuffXferProcessor.h" | 15 #include "effects/GrPorterDuffXferProcessor.h" |
| 16 | 16 |
| 17 /////////////////////////////////////////////////////////////////////////////// | |
| 18 | |
| 19 bool GrDrawState::isEqual(const GrDrawState& that) const { | 17 bool GrDrawState::isEqual(const GrDrawState& that) const { |
| 20 bool usingVertexColors = this->hasColorVertexAttribute(); | 18 bool usingVertexColors = this->hasColorVertexAttribute(); |
| 21 if (!usingVertexColors && this->fColor != that.fColor) { | 19 if (!usingVertexColors && this->fColor != that.fColor) { |
| 22 return false; | 20 return false; |
| 23 } | 21 } |
| 24 | 22 |
| 25 if (this->getRenderTarget() != that.getRenderTarget() || | 23 if (this->getRenderTarget() != that.getRenderTarget() || |
| 26 this->fColorStages.count() != that.fColorStages.count() || | 24 this->fColorStages.count() != that.fColorStages.count() || |
| 27 this->fCoverageStages.count() != that.fCoverageStages.count() || | 25 this->fCoverageStages.count() != that.fCoverageStages.count() || |
| 28 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 26 !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 || | 27 this->fFlagBits != that.fFlagBits || |
| 33 this->fStencilSettings != that.fStencilSettings || | 28 this->fStencilSettings != that.fStencilSettings || |
| 34 this->fDrawFace != that.fDrawFace) { | 29 this->fDrawFace != that.fDrawFace) { |
| 35 return false; | 30 return false; |
| 36 } | 31 } |
| 37 | 32 |
| 38 bool usingVertexCoverage = this->hasCoverageVertexAttribute(); | 33 bool usingVertexCoverage = this->hasCoverageVertexAttribute(); |
| 39 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { | 34 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { |
| 40 return false; | 35 return false; |
| 41 } | 36 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 for (int i = 0; i < this->numCoverageStages(); ++i) { | 78 for (int i = 0; i < this->numCoverageStages(); ++i) { |
| 84 fCoverageStages[i].localCoordChange(preConcatMatrix); | 79 fCoverageStages[i].localCoordChange(preConcatMatrix); |
| 85 } | 80 } |
| 86 } | 81 } |
| 87 } | 82 } |
| 88 | 83 |
| 89 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { | 84 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
| 90 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); | 85 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
| 91 fColor = that.fColor; | 86 fColor = that.fColor; |
| 92 fViewMatrix = that.fViewMatrix; | 87 fViewMatrix = that.fViewMatrix; |
| 93 fSrcBlend = that.fSrcBlend; | |
| 94 fDstBlend = that.fDstBlend; | |
| 95 fBlendConstant = that.fBlendConstant; | |
| 96 fFlagBits = that.fFlagBits; | 88 fFlagBits = that.fFlagBits; |
| 97 fStencilSettings = that.fStencilSettings; | 89 fStencilSettings = that.fStencilSettings; |
| 98 fCoverage = that.fCoverage; | 90 fCoverage = that.fCoverage; |
| 99 fDrawFace = that.fDrawFace; | 91 fDrawFace = that.fDrawFace; |
| 100 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); | 92 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); |
| 101 fXPFactory.reset(SkRef(that.getXPFactory())); | 93 fXPFactory.reset(SkRef(that.getXPFactory())); |
| 102 fColorStages = that.fColorStages; | 94 fColorStages = that.fColorStages; |
| 103 fCoverageStages = that.fCoverageStages; | 95 fCoverageStages = that.fCoverageStages; |
| 104 | 96 |
| 105 fHints = that.fHints; | 97 fHints = that.fHints; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 123 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); | 115 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
| 124 fColorStages.reset(); | 116 fColorStages.reset(); |
| 125 fCoverageStages.reset(); | 117 fCoverageStages.reset(); |
| 126 | 118 |
| 127 fColor = 0xffffffff; | 119 fColor = 0xffffffff; |
| 128 if (NULL == initialViewMatrix) { | 120 if (NULL == initialViewMatrix) { |
| 129 fViewMatrix.reset(); | 121 fViewMatrix.reset(); |
| 130 } else { | 122 } else { |
| 131 fViewMatrix = *initialViewMatrix; | 123 fViewMatrix = *initialViewMatrix; |
| 132 } | 124 } |
| 133 fSrcBlend = kOne_GrBlendCoeff; | |
| 134 fDstBlend = kZero_GrBlendCoeff; | |
| 135 fBlendConstant = 0x0; | |
| 136 fFlagBits = 0x0; | 125 fFlagBits = 0x0; |
| 137 fStencilSettings.setDisabled(); | 126 fStencilSettings.setDisabled(); |
| 138 fCoverage = 0xff; | 127 fCoverage = 0xff; |
| 139 fDrawFace = kBoth_DrawFace; | 128 fDrawFace = kBoth_DrawFace; |
| 140 | 129 |
| 141 fHints = 0; | 130 fHints = 0; |
| 142 | 131 |
| 143 fColorProcInfoValid = false; | 132 fColorProcInfoValid = false; |
| 144 fCoverageProcInfoValid = false; | 133 fCoverageProcInfoValid = false; |
| 145 } | 134 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 172 for (int i = 0; i < paint.numColorStages(); ++i) { | 161 for (int i = 0; i < paint.numColorStages(); ++i) { |
| 173 fColorStages.push_back(paint.getColorStage(i)); | 162 fColorStages.push_back(paint.getColorStage(i)); |
| 174 } | 163 } |
| 175 | 164 |
| 176 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 165 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
| 177 fCoverageStages.push_back(paint.getCoverageStage(i)); | 166 fCoverageStages.push_back(paint.getCoverageStage(i)); |
| 178 } | 167 } |
| 179 | 168 |
| 180 fXPFactory.reset(SkRef(paint.getXPFactory())); | 169 fXPFactory.reset(SkRef(paint.getXPFactory())); |
| 181 | 170 |
| 182 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | |
| 183 this->setRenderTarget(rt); | 171 this->setRenderTarget(rt); |
| 184 | 172 |
| 185 fViewMatrix = vm; | 173 fViewMatrix = vm; |
| 186 | 174 |
| 187 // These have no equivalent in GrPaint, set them to defaults | 175 // These have no equivalent in GrPaint, set them to defaults |
| 188 fBlendConstant = 0x0; | |
| 189 fDrawFace = kBoth_DrawFace; | 176 fDrawFace = kBoth_DrawFace; |
| 190 fStencilSettings.setDisabled(); | 177 fStencilSettings.setDisabled(); |
| 191 fFlagBits = 0; | 178 fFlagBits = 0; |
| 192 fHints = 0; | 179 fHints = 0; |
| 193 | 180 |
| 194 // Enable the clip bit | 181 // Enable the clip bit |
| 195 this->enableState(GrDrawState::kClip_StateBit); | 182 this->enableState(GrDrawState::kClip_StateBit); |
| 196 | 183 |
| 197 this->setColor(paint.getColor()); | 184 this->setColor(paint.getColor()); |
| 198 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 185 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 199 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 186 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
| 200 | 187 |
| 201 this->setCoverage(0xFF); | 188 this->setCoverage(0xFF); |
| 202 fColorProcInfoValid = false; | 189 fColorProcInfoValid = false; |
| 203 fCoverageProcInfoValid = false; | 190 fCoverageProcInfoValid = false; |
| 204 } | 191 } |
| 205 | 192 |
| 206 //////////////////////////////////////////////////////////////////////////////// | 193 //////////////////////////////////////////////////////////////////////////////// |
| 207 | 194 |
| 208 bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const { | 195 bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const { |
| 209 if (caps.dualSourceBlendingSupport()) { | 196 if (caps.dualSourceBlendingSupport()) { |
| 210 return true; | 197 return true; |
| 211 } | 198 } |
| 212 // we can correctly apply coverage if a) we have dual source blending | 199 |
| 213 // or b) one of our blend optimizations applies | 200 this->calcColorInvariantOutput(); |
| 214 // or c) the src, dst blend coeffs are 1,0 and we will read Dst Color | 201 this->calcCoverageInvariantOutput(); |
| 215 GrBlendCoeff srcCoeff; | 202 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo, |
| 216 GrBlendCoeff dstCoeff; | 203 this->isCoverageDrawing(), this->isColor
WriteDisabled()); |
| 217 BlendOpt opt = this->getBlendOpt(true, &srcCoeff, &dstCoeff); | |
| 218 return GrDrawState::kNone_BlendOpt != opt || | |
| 219 (this->willEffectReadDstColor() && | |
| 220 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff); | |
| 221 } | 204 } |
| 222 | 205 |
| 223 bool GrDrawState::hasSolidCoverage() const { | 206 bool GrDrawState::hasSolidCoverage() const { |
| 224 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 207 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
| 225 if (this->isCoverageDrawing()) { | 208 if (this->isCoverageDrawing()) { |
| 226 return true; | 209 return true; |
| 227 } | 210 } |
| 228 | 211 |
| 229 if (this->numCoverageStages() > 0) { | 212 if (this->numCoverageStages() > 0) { |
| 230 return false; | 213 return false; |
| 231 } | 214 } |
| 232 | 215 |
| 233 this->calcCoverageInvariantOutput(); | 216 this->calcCoverageInvariantOutput(); |
| 234 return fCoverageProcInfo.isSolidWhite(); | 217 return fCoverageProcInfo.isSolidWhite(); |
| 235 } | 218 } |
| 236 | 219 |
| 237 //////////////////////////////////////////////////////////////////////////////s | 220 //////////////////////////////////////////////////////////////////////////////s |
| 238 | 221 |
| 239 bool GrDrawState::willEffectReadDstColor() const { | 222 bool GrDrawState::willEffectReadDstColor() const { |
| 223 this->calcColorInvariantOutput(); |
| 224 this->calcCoverageInvariantOutput(); |
| 225 // TODO: Remove need to create the XP here. |
| 226 // Also once all custom blends are turned into XPs we can remove the n
eed |
| 227 // to check other stages since only xp's will be able to read dst |
| 228 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor(
fColorProcInfo, |
| 229
fCoverageProcInfo)); |
| 230 if (xferProcessor && xferProcessor->willReadDstColor()) { |
| 231 return true; |
| 232 } |
| 233 |
| 240 if (!this->isColorWriteDisabled()) { | 234 if (!this->isColorWriteDisabled()) { |
| 241 this->calcColorInvariantOutput(); | |
| 242 if (fColorProcInfo.readsDst()) { | 235 if (fColorProcInfo.readsDst()) { |
| 243 return true; | 236 return true; |
| 244 } | 237 } |
| 245 } | 238 } |
| 246 this->calcCoverageInvariantOutput(); | |
| 247 return fCoverageProcInfo.readsDst(); | 239 return fCoverageProcInfo.readsDst(); |
| 248 } | 240 } |
| 249 | 241 |
| 250 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { | 242 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
| 251 if (fDrawState) { | 243 if (fDrawState) { |
| 252 // See the big comment on the class definition about GPs. | 244 // See the big comment on the class definition about GPs. |
| 253 if (SK_InvalidUniqueID == fOriginalGPID) { | 245 if (SK_InvalidUniqueID == fOriginalGPID) { |
| 254 fDrawState->fGeometryProcessor.reset(NULL); | 246 fDrawState->fGeometryProcessor.reset(NULL); |
| 255 } else { | 247 } else { |
| 256 SkASSERT(fDrawState->getGeometryProcessor()->getUniqueID() == | 248 SkASSERT(fDrawState->getGeometryProcessor()->getUniqueID() == |
| (...skipping 24 matching lines...) Expand all Loading... |
| 281 fCoverageEffectCnt = ds->numCoverageStages(); | 273 fCoverageEffectCnt = ds->numCoverageStages(); |
| 282 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) | 274 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) |
| 283 } | 275 } |
| 284 } | 276 } |
| 285 | 277 |
| 286 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
| 287 | 279 |
| 288 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 280 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
| 289 // others will blend incorrectly. | 281 // others will blend incorrectly. |
| 290 bool GrDrawState::canTweakAlphaForCoverage() const { | 282 bool GrDrawState::canTweakAlphaForCoverage() const { |
| 291 /* | 283 return fXPFactory->canTweakAlphaForCoverage(this->isCoverageDrawing()); |
| 292 The fractional coverage is f. | |
| 293 The src and dst coeffs are Cs and Cd. | |
| 294 The dst and src colors are S and D. | |
| 295 We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the sou
rce color's alpha | |
| 296 we're replacing S with S'=fS. It's obvious that that first term will always
be ok. The second | |
| 297 term can be rearranged as [1-(1-Cd)f]D. By substituting in the various poss
ibilities for Cd we | |
| 298 find that only 1, ISA, and ISC produce the correct destination when applied
to S' and D. | |
| 299 Also, if we're directly rendering coverage (isCoverageDrawing) then coverag
e is treated as | |
| 300 color by definition. | |
| 301 */ | |
| 302 return kOne_GrBlendCoeff == fDstBlend || | |
| 303 kISA_GrBlendCoeff == fDstBlend || | |
| 304 kISC_GrBlendCoeff == fDstBlend || | |
| 305 this->isCoverageDrawing(); | |
| 306 } | 284 } |
| 307 | 285 |
| 308 //////////////////////////////////////////////////////////////////////////////// | 286 //////////////////////////////////////////////////////////////////////////////// |
| 309 | 287 |
| 310 void GrDrawState::AutoViewMatrixRestore::restore() { | 288 void GrDrawState::AutoViewMatrixRestore::restore() { |
| 311 if (fDrawState) { | 289 if (fDrawState) { |
| 312 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 290 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
| 313 fDrawState->fViewMatrix = fViewMatrix; | 291 fDrawState->fViewMatrix = fViewMatrix; |
| 314 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); | 292 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); |
| 315 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; | 293 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 371 } |
| 394 | 372 |
| 395 //////////////////////////////////////////////////////////////////////////////// | 373 //////////////////////////////////////////////////////////////////////////////// |
| 396 | 374 |
| 397 GrDrawState::~GrDrawState() { | 375 GrDrawState::~GrDrawState() { |
| 398 SkASSERT(0 == fBlockEffectRemovalCnt); | 376 SkASSERT(0 == fBlockEffectRemovalCnt); |
| 399 } | 377 } |
| 400 | 378 |
| 401 //////////////////////////////////////////////////////////////////////////////// | 379 //////////////////////////////////////////////////////////////////////////////// |
| 402 | 380 |
| 403 GrDrawState::BlendOpt GrDrawState::getBlendOpt(bool forceCoverage, | |
| 404 GrBlendCoeff* srcCoeff, | |
| 405 GrBlendCoeff* dstCoeff) const { | |
| 406 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | |
| 407 if (NULL == srcCoeff) { | |
| 408 srcCoeff = &bogusSrcCoeff; | |
| 409 } | |
| 410 if (NULL == dstCoeff) { | |
| 411 dstCoeff = &bogusDstCoeff; | |
| 412 } | |
| 413 | |
| 414 *srcCoeff = this->getSrcBlendCoeff(); | |
| 415 *dstCoeff = this->getDstBlendCoeff(); | |
| 416 | |
| 417 if (this->isColorWriteDisabled()) { | |
| 418 *srcCoeff = kZero_GrBlendCoeff; | |
| 419 *dstCoeff = kOne_GrBlendCoeff; | |
| 420 } | |
| 421 | |
| 422 bool srcAIsOne = this->srcAlphaWillBeOne(); | |
| 423 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || | |
| 424 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); | |
| 425 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || | |
| 426 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); | |
| 427 | |
| 428 // When coeffs are (0,1) there is no reason to draw at all, unless | |
| 429 // stenciling is enabled. Having color writes disabled is effectively | |
| 430 // (0,1). | |
| 431 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne)) { | |
| 432 if (this->getStencil().doesWrite()) { | |
| 433 return kEmitCoverage_BlendOpt; | |
| 434 } else { | |
| 435 *dstCoeff = kOne_GrBlendCoeff; | |
| 436 return kSkipDraw_BlendOpt; | |
| 437 } | |
| 438 } | |
| 439 | |
| 440 bool hasCoverage = forceCoverage || !this->hasSolidCoverage(); | |
| 441 | |
| 442 // if we don't have coverage we can check whether the dst | |
| 443 // has to read at all. If not, we'll disable blending. | |
| 444 if (!hasCoverage) { | |
| 445 if (dstCoeffIsZero) { | |
| 446 if (kOne_GrBlendCoeff == *srcCoeff) { | |
| 447 // if there is no coverage and coeffs are (1,0) then we | |
| 448 // won't need to read the dst at all, it gets replaced by src | |
| 449 *dstCoeff = kZero_GrBlendCoeff; | |
| 450 return kNone_BlendOpt; | |
| 451 } else if (kZero_GrBlendCoeff == *srcCoeff) { | |
| 452 // if the op is "clear" then we don't need to emit a color | |
| 453 // or blend, just write transparent black into the dst. | |
| 454 *srcCoeff = kOne_GrBlendCoeff; | |
| 455 *dstCoeff = kZero_GrBlendCoeff; | |
| 456 return kEmitTransBlack_BlendOpt; | |
| 457 } | |
| 458 } | |
| 459 } else if (this->isCoverageDrawing()) { | |
| 460 // we have coverage but we aren't distinguishing it from alpha by reques
t. | |
| 461 return kCoverageAsAlpha_BlendOpt; | |
| 462 } else { | |
| 463 // check whether coverage can be safely rolled into alpha | |
| 464 // of if we can skip color computation and just emit coverage | |
| 465 if (this->canTweakAlphaForCoverage()) { | |
| 466 return kCoverageAsAlpha_BlendOpt; | |
| 467 } | |
| 468 if (dstCoeffIsZero) { | |
| 469 if (kZero_GrBlendCoeff == *srcCoeff) { | |
| 470 // the source color is not included in the blend | |
| 471 // the dst coeff is effectively zero so blend works out to: | |
| 472 // (c)(0)D + (1-c)D = (1-c)D. | |
| 473 *dstCoeff = kISA_GrBlendCoeff; | |
| 474 return kEmitCoverage_BlendOpt; | |
| 475 } else if (srcAIsOne) { | |
| 476 // the dst coeff is effectively zero so blend works out to: | |
| 477 // cS + (c)(0)D + (1-c)D = cS + (1-c)D. | |
| 478 // If Sa is 1 then we can replace Sa with c | |
| 479 // and set dst coeff to 1-Sa. | |
| 480 *dstCoeff = kISA_GrBlendCoeff; | |
| 481 return kCoverageAsAlpha_BlendOpt; | |
| 482 } | |
| 483 } else if (dstCoeffIsOne) { | |
| 484 // the dst coeff is effectively one so blend works out to: | |
| 485 // cS + (c)(1)D + (1-c)D = cS + D. | |
| 486 *dstCoeff = kOne_GrBlendCoeff; | |
| 487 return kCoverageAsAlpha_BlendOpt; | |
| 488 } | |
| 489 } | |
| 490 | |
| 491 return kNone_BlendOpt; | |
| 492 } | |
| 493 | |
| 494 bool GrDrawState::srcAlphaWillBeOne() const { | 381 bool GrDrawState::srcAlphaWillBeOne() const { |
| 495 this->calcColorInvariantOutput(); | 382 this->calcColorInvariantOutput(); |
| 496 if (this->isCoverageDrawing()) { | 383 if (this->isCoverageDrawing()) { |
| 497 this->calcCoverageInvariantOutput(); | 384 this->calcCoverageInvariantOutput(); |
| 498 return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque()); | 385 return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque()); |
| 499 } | 386 } |
| 500 return fColorProcInfo.isOpaque(); | 387 return fColorProcInfo.isOpaque(); |
| 501 } | 388 } |
| 502 | 389 |
| 503 bool GrDrawState::willBlendWithDst() const { | 390 bool GrDrawState::willBlendWithDst() const { |
| 504 if (!this->hasSolidCoverage()) { | 391 this->calcColorInvariantOutput(); |
| 505 return true; | 392 this->calcCoverageInvariantOutput(); |
| 506 } | 393 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo, |
| 507 | 394 this->isCoverageDrawing(), this->isColor
WriteDisabled()); |
| 508 if (this->willEffectReadDstColor()) { | |
| 509 return true; | |
| 510 } | |
| 511 | |
| 512 if (GrBlendCoeffRefsDst(this->getSrcBlendCoeff())) { | |
| 513 return true; | |
| 514 } | |
| 515 | |
| 516 GrBlendCoeff dstCoeff = this->getDstBlendCoeff(); | |
| 517 if (!(kZero_GrBlendCoeff == dstCoeff || | |
| 518 (kISA_GrBlendCoeff == dstCoeff && this->srcAlphaWillBeOne()))) { | |
| 519 return true; | |
| 520 } | |
| 521 | |
| 522 return false; | |
| 523 } | 395 } |
| 524 | 396 |
| 525 void GrDrawState::calcColorInvariantOutput() const { | 397 void GrDrawState::calcColorInvariantOutput() const { |
| 526 if (!fColorProcInfoValid) { | 398 if (!fColorProcInfoValid) { |
| 527 GrColor color; | 399 GrColor color; |
| 528 GrColorComponentFlags flags; | 400 GrColorComponentFlags flags; |
| 529 if (this->hasColorVertexAttribute()) { | 401 if (this->hasColorVertexAttribute()) { |
| 530 if (fHints & kVertexColorsAreOpaque_Hint) { | 402 if (fHints & kVertexColorsAreOpaque_Hint) { |
| 531 flags = kA_GrColorComponentFlag; | 403 flags = kA_GrColorComponentFlag; |
| 532 color = 0xFF << GrColor_SHIFT_A; | 404 color = 0xFF << GrColor_SHIFT_A; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 554 color = 0; | 426 color = 0; |
| 555 } else { | 427 } else { |
| 556 flags = kRGBA_GrColorComponentFlags; | 428 flags = kRGBA_GrColorComponentFlags; |
| 557 color = this->getCoverageColor(); | 429 color = this->getCoverageColor(); |
| 558 } | 430 } |
| 559 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), | 431 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), |
| 560 color, flags, true, fGeometryPro
cessor.get()); | 432 color, flags, true, fGeometryPro
cessor.get()); |
| 561 fCoverageProcInfoValid = true; | 433 fCoverageProcInfoValid = true; |
| 562 } | 434 } |
| 563 } | 435 } |
| 564 | |
| OLD | NEW |