Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "effects/GrPorterDuffXferProcessor.h" | 8 #include "effects/GrPorterDuffXferProcessor.h" |
| 9 | 9 |
| 10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 // TODO: once all SkXferEffects are XP's then we will never reads dst here s ince only XP's | 436 // TODO: once all SkXferEffects are XP's then we will never reads dst here s ince only XP's |
| 437 // will readDst and PD XP's don't read dst. | 437 // will readDst and PD XP's don't read dst. |
| 438 if ((colorPOI.readsDst() || coveragePOI.readsDst()) && | 438 if ((colorPOI.readsDst() || coveragePOI.readsDst()) && |
| 439 kOne_GrBlendCoeff == fSrcCoeff && kZero_GrBlendCoeff == fDstCoeff) { | 439 kOne_GrBlendCoeff == fSrcCoeff && kZero_GrBlendCoeff == fDstCoeff) { |
| 440 return true; | 440 return true; |
| 441 } | 441 } |
| 442 | 442 |
| 443 return false; | 443 return false; |
| 444 } | 444 } |
| 445 | 445 |
| 446 bool GrPorterDuffXPFactory::willBlendWithDst(const GrProcOptInfo& colorPOI, | |
| 447 const GrProcOptInfo& coveragePOI, | |
| 448 bool colorWriteDisabled) const { | |
| 449 if (!coveragePOI.isSolidWhite()) { | |
| 450 return true; | |
| 451 } | |
| 452 | |
| 453 // TODO: once all SkXferEffects are XP's then we will never reads dst here s ince only XP's | |
| 454 // will readDst and PD XP's don't read dst. | |
| 455 if ((!colorWriteDisabled && colorPOI.readsDst()) || coveragePOI.readsDst()) { | |
| 456 return true; | |
| 457 } | |
| 458 | |
| 459 if (GrBlendCoeffRefsDst(fSrcCoeff)) { | |
| 460 return true; | |
| 461 } | |
| 462 | |
| 463 bool srcAIsOne = colorPOI.isOpaque(); | |
| 464 | |
| 465 if (!(kZero_GrBlendCoeff == fDstCoeff || | |
| 466 (kISA_GrBlendCoeff == fDstCoeff && srcAIsOne))) { | |
| 467 return true; | |
| 468 } | |
| 469 | |
| 470 return false; | |
| 471 } | |
| 472 | |
| 473 bool GrPorterDuffXPFactory::canTweakAlphaForCoverage() const { | 446 bool GrPorterDuffXPFactory::canTweakAlphaForCoverage() const { |
| 474 return can_tweak_alpha_for_coverage(fDstCoeff); | 447 return can_tweak_alpha_for_coverage(fDstCoeff); |
| 475 } | 448 } |
| 476 | 449 |
| 477 bool GrPorterDuffXPFactory::getOpaqueAndKnownColor(const GrProcOptInfo& colorPOI , | 450 void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, |
| 478 const GrProcOptInfo& coverage POI, | 451 const GrProcOptInfo& coveragePOI, |
| 479 GrColor* solidColor, | 452 bool colorWriteDisabled, |
| 480 uint32_t* solidColorKnownComp onents) const { | 453 GrXPFactory::InvariantOutput* out put) const { |
| 481 if (!coveragePOI.isSolidWhite()) { | 454 if (!coveragePOI.isSolidWhite()) { |
| 482 return false; | 455 output->fWillBlendWithDst = true; |
| 456 output->fBlendedColorFlags = 0; | |
| 457 return; | |
| 483 } | 458 } |
| 484 | 459 |
| 485 SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents)); | |
| 486 | |
| 487 GrBlendCoeff srcCoeff = fSrcCoeff; | 460 GrBlendCoeff srcCoeff = fSrcCoeff; |
| 488 GrBlendCoeff dstCoeff = fDstCoeff; | 461 GrBlendCoeff dstCoeff = fDstCoeff; |
| 489 | 462 |
| 490 // TODO: figure out to merge this simplify with other current optimization c ode paths and | 463 // TODO: figure out to merge this simplify with other current optimization c ode paths and |
| 491 // eventually remove from GrBlend | 464 // eventually remove from GrBlend |
| 492 GrSimplifyBlend(&srcCoeff, &dstCoeff, colorPOI.color(), colorPOI.validFlags( ), | 465 GrSimplifyBlend(&srcCoeff, &dstCoeff, colorPOI.color(), colorPOI.validFlags( ), |
| 493 0, 0, 0); | 466 0, 0, 0); |
| 494 | 467 |
| 495 bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoef f); | 468 if (GrBlendCoeffRefsDst(srcCoeff)) { |
| 496 if (solidColor) { | 469 output->fWillBlendWithDst = true; |
| 497 if (opaque) { | 470 output->fBlendedColorFlags = 0; |
| 498 switch (srcCoeff) { | 471 return; |
| 499 case kZero_GrBlendCoeff: | 472 } |
| 500 *solidColor = 0; | |
| 501 *solidColorKnownComponents = kRGBA_GrColorComponentFlags; | |
| 502 break; | |
| 503 | 473 |
| 504 case kOne_GrBlendCoeff: | 474 if (kZero_GrBlendCoeff != dstCoeff) { |
| 505 *solidColor = colorPOI.color(); | 475 bool srcAIsOne = colorPOI.isOpaque(); |
| 506 *solidColorKnownComponents = colorPOI.validFlags(); | 476 if (kISA_GrBlendCoeff != dstCoeff || !srcAIsOne) { |
| 507 break; | 477 output->fWillBlendWithDst = true; |
| 478 } | |
| 479 output->fBlendedColorFlags = 0; | |
| 480 return; | |
| 481 } | |
| 508 | 482 |
| 509 // The src coeff should never refer to the src and if it refers to dst then opaque | 483 switch (srcCoeff) { |
| 510 // should have been false. | 484 case kZero_GrBlendCoeff: |
| 511 case kSC_GrBlendCoeff: | 485 output->fBlendedColor = 0; |
| 512 case kISC_GrBlendCoeff: | 486 output->fBlendedColorFlags = kRGBA_GrColorComponentFlags; |
| 513 case kDC_GrBlendCoeff: | 487 break; |
| 514 case kIDC_GrBlendCoeff: | |
| 515 case kSA_GrBlendCoeff: | |
| 516 case kISA_GrBlendCoeff: | |
| 517 case kDA_GrBlendCoeff: | |
| 518 case kIDA_GrBlendCoeff: | |
| 519 default: | |
| 520 SkFAIL("srcCoeff should not refer to src or dst."); | |
| 521 break; | |
| 522 | 488 |
| 523 // TODO: update this once GrPaint actually has a const color. | 489 case kOne_GrBlendCoeff: |
| 524 case kConstC_GrBlendCoeff: | 490 output->fBlendedColor = colorPOI.color(); |
| 525 case kIConstC_GrBlendCoeff: | 491 output->fBlendedColorFlags = colorPOI.validFlags(); |
| 526 case kConstA_GrBlendCoeff: | 492 break; |
| 527 case kIConstA_GrBlendCoeff: | 493 |
| 528 *solidColorKnownComponents = 0; | 494 // The src coeff should never refer to the src and if it refers to d st then opaque |
| 529 break; | 495 // should have been false. |
| 530 } | 496 case kSC_GrBlendCoeff: |
| 531 } else { | 497 case kISC_GrBlendCoeff: |
| 532 solidColorKnownComponents = 0; | 498 case kDC_GrBlendCoeff: |
| 533 } | 499 case kIDC_GrBlendCoeff: |
| 500 case kSA_GrBlendCoeff: | |
| 501 case kISA_GrBlendCoeff: | |
| 502 case kDA_GrBlendCoeff: | |
| 503 case kIDA_GrBlendCoeff: | |
| 504 default: | |
| 505 SkFAIL("srcCoeff should not refer to src or dst."); | |
| 506 break; | |
| 507 | |
| 508 // TODO: update this once GrPaint actually has a const color. | |
| 509 case kConstC_GrBlendCoeff: | |
| 510 case kIConstC_GrBlendCoeff: | |
| 511 case kConstA_GrBlendCoeff: | |
| 512 case kIConstA_GrBlendCoeff: | |
| 513 output->fBlendedColorFlags = 0; | |
| 514 break; | |
| 534 } | 515 } |
| 535 return opaque; | 516 |
| 517 // TODO: once all SkXferEffects are XP's then we will never reads dst here s ince only XP's | |
| 518 // will readDst and PD XP's don't read dst. | |
| 519 if ((!colorWriteDisabled && colorPOI.readsDst()) || coveragePOI.readsDst()) { | |
|
bsalomon
2014/12/18 20:29:48
output->fWillBlendWithDst = (!colorWriteDisabled &
| |
| 520 output->fWillBlendWithDst = true; | |
| 521 return; | |
| 522 } | |
| 523 output->fWillBlendWithDst = false; | |
| 536 } | 524 } |
| 537 | 525 |
| 538 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); | 526 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
| 539 | 527 |
| 540 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, | 528 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, |
| 541 GrContext*, | 529 GrContext*, |
| 542 const GrDrawTargetCaps&, | 530 const GrDrawTargetCaps&, |
| 543 GrTexture*[]) { | 531 GrTexture*[]) { |
| 544 GrBlendCoeff src; | 532 GrBlendCoeff src; |
| 545 do { | 533 do { |
| 546 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff)); | 534 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff)); |
| 547 } while (GrBlendCoeffRefsSrc(src)); | 535 } while (GrBlendCoeffRefsSrc(src)); |
| 548 | 536 |
| 549 GrBlendCoeff dst; | 537 GrBlendCoeff dst; |
| 550 do { | 538 do { |
| 551 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff)); | 539 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff)); |
| 552 } while (GrBlendCoeffRefsDst(dst)); | 540 } while (GrBlendCoeffRefsDst(dst)); |
| 553 | 541 |
| 554 return GrPorterDuffXPFactory::Create(src, dst); | 542 return GrPorterDuffXPFactory::Create(src, dst); |
| 555 } | 543 } |
| 556 | 544 |
| OLD | NEW |