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 kEmitCoverage_BlendOptFlag; | 342 return kDisableBlend_BlendOptFlag | |
| 343 kEmitCoverage_BlendOptFlag; |
343 } else { | 344 } else { |
344 return kSkipDraw_BlendOptFlag; | 345 return kSkipDraw_BlendOptFlag; |
345 } | 346 } |
346 } | 347 } |
347 | 348 |
348 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage | 349 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage |
349 bool hasCoverage = forceCoverage || | 350 bool hasCoverage = forceCoverage || |
350 0xffffffff != this->getCoverageColor() || | 351 0xffffffff != this->getCoverageColor() || |
351 this->hasCoverageVertexAttribute() || | 352 this->hasCoverageVertexAttribute() || |
352 fCoverageStages.count() > 0; | 353 fCoverageStages.count() > 0; |
353 | 354 |
354 // if we don't have coverage we can check whether the dst | 355 // if we don't have coverage we can check whether the dst |
355 // has to read at all. If not, we'll disable blending. | 356 // has to read at all. If not, we'll disable blending. |
356 if (!hasCoverage) { | 357 if (!hasCoverage) { |
357 if (dstCoeffIsZero) { | 358 if (dstCoeffIsZero) { |
358 if (kOne_GrBlendCoeff == *srcCoeff) { | 359 if (kOne_GrBlendCoeff == *srcCoeff) { |
359 // if there is no coverage and coeffs are (1,0) then we | 360 // if there is no coverage and coeffs are (1,0) then we |
360 // won't need to read the dst at all, it gets replaced by src | 361 // won't need to read the dst at all, it gets replaced by src |
361 *dstCoeff = kZero_GrBlendCoeff; | 362 return kDisableBlend_BlendOptFlag; |
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 kEmitTransBlack_BlendOptFlag; | 368 return kDisableBlend_BlendOptFlag | 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 | 402 if (kOne_GrBlendCoeff == *srcCoeff && |
| 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 } |
403 return kNone_BlendOpt; | 409 return kNone_BlendOpt; |
404 } | 410 } |
405 | 411 |
406 bool GrDrawState::canIgnoreColorAttribute() const { | 412 bool GrDrawState::canIgnoreColorAttribute() const { |
407 if (fBlendOptFlags & kInvalid_BlendOptFlag) { | 413 if (fBlendOptFlags & kInvalid_BlendOptFlag) { |
408 this->getBlendOpts(); | 414 this->getBlendOpts(); |
409 } | 415 } |
410 return SkToBool(fBlendOptFlags & (GrDrawState::kEmitTransBlack_BlendOptFlag
| | 416 return SkToBool(fBlendOptFlags & (GrDrawState::kEmitTransBlack_BlendOptFlag
| |
411 GrDrawState::kEmitCoverage_BlendOptFlag)); | 417 GrDrawState::kEmitCoverage_BlendOptFlag)); |
412 } | 418 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 497 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
492 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 498 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
493 } | 499 } |
494 | 500 |
495 int numCoverageStages = fDrawState->numCoverageStages(); | 501 int numCoverageStages = fDrawState->numCoverageStages(); |
496 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 502 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
497 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 503 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
498 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 504 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
499 } | 505 } |
500 } | 506 } |
OLD | NEW |