| 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 #include "GrPaint.h" | 9 #include "GrPaint.h" |
| 10 | 10 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 332 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 333 | 333 |
| 334 bool covIsZero = !this->isCoverageDrawing() && | 334 bool covIsZero = !this->isCoverageDrawing() && |
| 335 !this->hasCoverageVertexAttribute() && | 335 !this->hasCoverageVertexAttribute() && |
| 336 0 == this->getCoverageColor(); | 336 0 == this->getCoverageColor(); |
| 337 // When coeffs are (0,1) there is no reason to draw at all, unless | 337 // When coeffs are (0,1) there is no reason to draw at all, unless |
| 338 // stenciling is enabled. Having color writes disabled is effectively | 338 // stenciling is enabled. Having color writes disabled is effectively |
| 339 // (0,1). The same applies when coverage is known to be 0. | 339 // (0,1). The same applies when coverage is known to be 0. |
| 340 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { | 340 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { |
| 341 if (this->getStencil().doesWrite()) { | 341 if (this->getStencil().doesWrite()) { |
| 342 return kDisableBlend_BlendOptFlag | | 342 return kEmitCoverage_BlendOptFlag; |
| 343 kEmitCoverage_BlendOptFlag; | |
| 344 } else { | 343 } else { |
| 345 return kSkipDraw_BlendOptFlag; | 344 return kSkipDraw_BlendOptFlag; |
| 346 } | 345 } |
| 347 } | 346 } |
| 348 | 347 |
| 349 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage | 348 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage |
| 350 bool hasCoverage = forceCoverage || | 349 bool hasCoverage = forceCoverage || |
| 351 0xffffffff != this->getCoverageColor() || | 350 0xffffffff != this->getCoverageColor() || |
| 352 this->hasCoverageVertexAttribute() || | 351 this->hasCoverageVertexAttribute() || |
| 353 fCoverageStages.count() > 0; | 352 fCoverageStages.count() > 0; |
| 354 | 353 |
| 355 // if we don't have coverage we can check whether the dst | 354 // if we don't have coverage we can check whether the dst |
| 356 // has to read at all. If not, we'll disable blending. | 355 // has to read at all. If not, we'll disable blending. |
| 357 if (!hasCoverage) { | 356 if (!hasCoverage) { |
| 358 if (dstCoeffIsZero) { | 357 if (dstCoeffIsZero) { |
| 359 if (kOne_GrBlendCoeff == *srcCoeff) { | 358 if (kOne_GrBlendCoeff == *srcCoeff) { |
| 360 // if there is no coverage and coeffs are (1,0) then we | 359 // if there is no coverage and coeffs are (1,0) then we |
| 361 // won't need to read the dst at all, it gets replaced by src | 360 // won't need to read the dst at all, it gets replaced by src |
| 362 return kDisableBlend_BlendOptFlag; | 361 *dstCoeff = kZero_GrBlendCoeff; |
| 362 return kNone_BlendOpt; |
| 363 } else if (kZero_GrBlendCoeff == *srcCoeff) { | 363 } else if (kZero_GrBlendCoeff == *srcCoeff) { |
| 364 // if the op is "clear" then we don't need to emit a color | 364 // if the op is "clear" then we don't need to emit a color |
| 365 // or blend, just write transparent black into the dst. | 365 // or blend, just write transparent black into the dst. |
| 366 *srcCoeff = kOne_GrBlendCoeff; | 366 *srcCoeff = kOne_GrBlendCoeff; |
| 367 *dstCoeff = kZero_GrBlendCoeff; | 367 *dstCoeff = kZero_GrBlendCoeff; |
| 368 return kDisableBlend_BlendOptFlag | kEmitTransBlack_BlendOptFlag
; | 368 return kEmitTransBlack_BlendOptFlag; |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 } else if (this->isCoverageDrawing()) { | 371 } else if (this->isCoverageDrawing()) { |
| 372 // we have coverage but we aren't distinguishing it from alpha by reques
t. | 372 // we have coverage but we aren't distinguishing it from alpha by reques
t. |
| 373 return kCoverageAsAlpha_BlendOptFlag; | 373 return kCoverageAsAlpha_BlendOptFlag; |
| 374 } else { | 374 } else { |
| 375 // check whether coverage can be safely rolled into alpha | 375 // check whether coverage can be safely rolled into alpha |
| 376 // of if we can skip color computation and just emit coverage | 376 // of if we can skip color computation and just emit coverage |
| 377 if (this->canTweakAlphaForCoverage()) { | 377 if (this->canTweakAlphaForCoverage()) { |
| 378 return kCoverageAsAlpha_BlendOptFlag; | 378 return kCoverageAsAlpha_BlendOptFlag; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 392 *dstCoeff = kISA_GrBlendCoeff; | 392 *dstCoeff = kISA_GrBlendCoeff; |
| 393 return kCoverageAsAlpha_BlendOptFlag; | 393 return kCoverageAsAlpha_BlendOptFlag; |
| 394 } | 394 } |
| 395 } else if (dstCoeffIsOne) { | 395 } else if (dstCoeffIsOne) { |
| 396 // the dst coeff is effectively one so blend works out to: | 396 // the dst coeff is effectively one so blend works out to: |
| 397 // cS + (c)(1)D + (1-c)D = cS + D. | 397 // cS + (c)(1)D + (1-c)D = cS + D. |
| 398 *dstCoeff = kOne_GrBlendCoeff; | 398 *dstCoeff = kOne_GrBlendCoeff; |
| 399 return kCoverageAsAlpha_BlendOptFlag; | 399 return kCoverageAsAlpha_BlendOptFlag; |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 if (kOne_GrBlendCoeff == *srcCoeff && | 402 |
| 403 kZero_GrBlendCoeff == *dstCoeff && | |
| 404 this->willEffectReadDstColor()) { | |
| 405 // In this case the shader will fully resolve the color, coverage, and d
st and we don't | |
| 406 // need blending. | |
| 407 return kDisableBlend_BlendOptFlag; | |
| 408 } | |
| 409 return kNone_BlendOpt; | 403 return kNone_BlendOpt; |
| 410 } | 404 } |
| 411 | 405 |
| 412 bool GrDrawState::canIgnoreColorAttribute() const { | 406 bool GrDrawState::canIgnoreColorAttribute() const { |
| 413 if (fBlendOptFlags & kInvalid_BlendOptFlag) { | 407 if (fBlendOptFlags & kInvalid_BlendOptFlag) { |
| 414 this->getBlendOpts(); | 408 this->getBlendOpts(); |
| 415 } | 409 } |
| 416 return SkToBool(fBlendOptFlags & (GrDrawState::kEmitTransBlack_BlendOptFlag
| | 410 return SkToBool(fBlendOptFlags & (GrDrawState::kEmitTransBlack_BlendOptFlag
| |
| 417 GrDrawState::kEmitCoverage_BlendOptFlag)); | 411 GrDrawState::kEmitCoverage_BlendOptFlag)); |
| 418 } | 412 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 491 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 498 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 492 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
| 499 } | 493 } |
| 500 | 494 |
| 501 int numCoverageStages = fDrawState->numCoverageStages(); | 495 int numCoverageStages = fDrawState->numCoverageStages(); |
| 502 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 496 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 503 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 497 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 504 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 498 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
| 505 } | 499 } |
| 506 } | 500 } |
| OLD | NEW |