| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 case GrPorterDuffXferProcessor::kNone_PrimaryOutputType: | 65 case GrPorterDuffXferProcessor::kNone_PrimaryOutputType: |
| 66 fsBuilder->codeAppendf("%s = vec4(0);", args.fOutputPrimary); | 66 fsBuilder->codeAppendf("%s = vec4(0);", args.fOutputPrimary); |
| 67 break; | 67 break; |
| 68 case GrPorterDuffXferProcessor::kColor_PrimaryOutputType: | 68 case GrPorterDuffXferProcessor::kColor_PrimaryOutputType: |
| 69 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fIn
putColor); | 69 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fIn
putColor); |
| 70 break; | 70 break; |
| 71 case GrPorterDuffXferProcessor::kCoverage_PrimaryOutputType: | 71 case GrPorterDuffXferProcessor::kCoverage_PrimaryOutputType: |
| 72 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fIn
putCoverage); | 72 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fIn
putCoverage); |
| 73 break; | 73 break; |
| 74 case GrPorterDuffXferProcessor::kModulate_PrimaryOutputType: | 74 case GrPorterDuffXferProcessor::kModulate_PrimaryOutputType: |
| 75 case GrPorterDuffXferProcessor::kCombineWithDst_PrimaryOutputType: | |
| 76 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, arg
s.fInputColor, | 75 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, arg
s.fInputColor, |
| 77 args.fInputCoverage); | 76 args.fInputCoverage); |
| 78 if (GrPorterDuffXferProcessor::kCombineWithDst_PrimaryOutputType
== | |
| 79 xp.primaryOutputType()){ | |
| 80 fsBuilder->codeAppendf("%s += (vec4(1.0) - %s) * %s;", args.
fOutputPrimary, | |
| 81 args.fInputCoverage, fsBuilder->dstCo
lor()); | |
| 82 } | |
| 83 break; | 77 break; |
| 84 default: | 78 default: |
| 85 SkFAIL("Unexpected Primary Output"); | 79 SkFAIL("Unexpected Primary Output"); |
| 86 } | 80 } |
| 87 } | 81 } |
| 88 | 82 |
| 89 void setData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVERR
IDE {}; | 83 void setData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVERR
IDE {}; |
| 90 | 84 |
| 91 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, | 85 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, |
| 92 GrProcessorKeyBuilder* b) { | 86 GrProcessorKeyBuilder* b) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // a point where we have RGB coverage. We don't need any color stages si
nce the known color | 131 // a point where we have RGB coverage. We don't need any color stages si
nce the known color |
| 138 // output is already baked into the blendConstant. | 132 // output is already baked into the blendConstant. |
| 139 uint8_t alpha = GrColorUnpackA(fBlendConstant); | 133 uint8_t alpha = GrColorUnpackA(fBlendConstant); |
| 140 *overrideColor = GrColorPackRGBA(alpha, alpha, alpha, alpha); | 134 *overrideColor = GrColorPackRGBA(alpha, alpha, alpha, alpha); |
| 141 optFlags = GrXferProcessor::kOverrideColor_OptFlag; | 135 optFlags = GrXferProcessor::kOverrideColor_OptFlag; |
| 142 } else { | 136 } else { |
| 143 optFlags = this->internalGetOptimizations(colorPOI, | 137 optFlags = this->internalGetOptimizations(colorPOI, |
| 144 coveragePOI, | 138 coveragePOI, |
| 145 doesStencilWrite); | 139 doesStencilWrite); |
| 146 } | 140 } |
| 147 this->calcOutputTypes(optFlags, caps, coveragePOI.isSolidWhite(), | 141 this->calcOutputTypes(optFlags, caps, coveragePOI.isSolidWhite()); |
| 148 colorPOI.readsDst() || coveragePOI.readsDst()); | |
| 149 return optFlags; | 142 return optFlags; |
| 150 } | 143 } |
| 151 | 144 |
| 152 void GrPorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFla
gs, | 145 void GrPorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFla
gs, |
| 153 const GrDrawTargetCaps& caps, | 146 const GrDrawTargetCaps& caps, |
| 154 bool hasSolidCoverage, bool read
sDst) { | 147 bool hasSolidCoverage) { |
| 155 if (optFlags & kIgnoreColor_OptFlag) { | 148 if (optFlags & kIgnoreColor_OptFlag) { |
| 156 if (optFlags & kIgnoreCoverage_OptFlag) { | 149 if (optFlags & kIgnoreCoverage_OptFlag) { |
| 157 fPrimaryOutputType = kNone_PrimaryOutputType; | 150 fPrimaryOutputType = kNone_PrimaryOutputType; |
| 158 return; | 151 return; |
| 159 } else { | 152 } else { |
| 160 fPrimaryOutputType = kCoverage_PrimaryOutputType; | 153 fPrimaryOutputType = kCoverage_PrimaryOutputType; |
| 161 return; | 154 return; |
| 162 } | 155 } |
| 163 } else if (optFlags & kIgnoreCoverage_OptFlag) { | 156 } else if (optFlags & kIgnoreCoverage_OptFlag) { |
| 164 fPrimaryOutputType = kColor_PrimaryOutputType; | 157 fPrimaryOutputType = kColor_PrimaryOutputType; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 177 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 170 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 178 } else if (kSA_GrBlendCoeff == fDstBlend) { | 171 } else if (kSA_GrBlendCoeff == fDstBlend) { |
| 179 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 172 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
| 180 fSecondaryOutputType = kCoverageISA_SecondaryOutputType; | 173 fSecondaryOutputType = kCoverageISA_SecondaryOutputType; |
| 181 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 174 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 182 } else if (kSC_GrBlendCoeff == fDstBlend) { | 175 } else if (kSC_GrBlendCoeff == fDstBlend) { |
| 183 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 176 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
| 184 fSecondaryOutputType = kCoverageISC_SecondaryOutputType; | 177 fSecondaryOutputType = kCoverageISC_SecondaryOutputType; |
| 185 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 178 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 186 } | 179 } |
| 187 } else if (readsDst && | |
| 188 kOne_GrBlendCoeff == fSrcBlend && | |
| 189 kZero_GrBlendCoeff == fDstBlend) { | |
| 190 fPrimaryOutputType = kCombineWithDst_PrimaryOutputType; | |
| 191 } | 180 } |
| 192 } | 181 } |
| 193 } | 182 } |
| 194 | 183 |
| 195 GrXferProcessor::OptFlags | 184 GrXferProcessor::OptFlags |
| 196 GrPorterDuffXferProcessor::internalGetOptimizations(const GrProcOptInfo& colorPO
I, | 185 GrPorterDuffXferProcessor::internalGetOptimizations(const GrProcOptInfo& colorPO
I, |
| 197 const GrProcOptInfo& coverag
ePOI, | 186 const GrProcOptInfo& coverag
ePOI, |
| 198 bool doesStencilWrite) { | 187 bool doesStencilWrite) { |
| 199 bool srcAIsOne; | 188 bool srcAIsOne; |
| 200 bool hasCoverage; | 189 bool hasCoverage; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 if (dstCoeffIsZero) { | 401 if (dstCoeffIsZero) { |
| 413 if (kZero_GrBlendCoeff == fSrcCoeff) { | 402 if (kZero_GrBlendCoeff == fSrcCoeff) { |
| 414 return true; | 403 return true; |
| 415 } else if (srcAIsOne) { | 404 } else if (srcAIsOne) { |
| 416 return true; | 405 return true; |
| 417 } | 406 } |
| 418 } else if (dstCoeffIsOne) { | 407 } else if (dstCoeffIsOne) { |
| 419 return true; | 408 return true; |
| 420 } | 409 } |
| 421 | 410 |
| 422 // TODO: once all SkXferEffects are XP's then we will never reads dst here s
ince only XP's | |
| 423 // will readDst and PD XP's don't read dst. | |
| 424 if ((colorPOI.readsDst() || coveragePOI.readsDst()) && | |
| 425 kOne_GrBlendCoeff == fSrcCoeff && kZero_GrBlendCoeff == fDstCoeff) { | |
| 426 return true; | |
| 427 } | |
| 428 | |
| 429 return false; | 411 return false; |
| 430 } | 412 } |
| 431 | 413 |
| 432 bool GrPorterDuffXPFactory::canTweakAlphaForCoverage() const { | 414 bool GrPorterDuffXPFactory::canTweakAlphaForCoverage() const { |
| 433 return can_tweak_alpha_for_coverage(fDstCoeff); | 415 return can_tweak_alpha_for_coverage(fDstCoeff); |
| 434 } | 416 } |
| 435 | 417 |
| 436 void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, | 418 void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, |
| 437 const GrProcOptInfo& coveragePOI, | 419 const GrProcOptInfo& coveragePOI, |
| 438 GrXPFactory::InvariantOutput* out
put) const { | 420 GrXPFactory::InvariantOutput* out
put) const { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 474 |
| 493 // TODO: update this once GrPaint actually has a const color. | 475 // TODO: update this once GrPaint actually has a const color. |
| 494 case kConstC_GrBlendCoeff: | 476 case kConstC_GrBlendCoeff: |
| 495 case kIConstC_GrBlendCoeff: | 477 case kIConstC_GrBlendCoeff: |
| 496 case kConstA_GrBlendCoeff: | 478 case kConstA_GrBlendCoeff: |
| 497 case kIConstA_GrBlendCoeff: | 479 case kIConstA_GrBlendCoeff: |
| 498 output->fBlendedColorFlags = 0; | 480 output->fBlendedColorFlags = 0; |
| 499 break; | 481 break; |
| 500 } | 482 } |
| 501 | 483 |
| 502 // TODO: once all SkXferEffects are XP's then we will never reads dst here s
ince only XP's | |
| 503 // will readDst and PD XP's don't read dst. | |
| 504 if (colorPOI.readsDst() || coveragePOI.readsDst()) { | |
| 505 output->fWillBlendWithDst = true; | |
| 506 return; | |
| 507 } | |
| 508 output->fWillBlendWithDst = false; | 484 output->fWillBlendWithDst = false; |
| 509 } | 485 } |
| 510 | 486 |
| 511 bool GrPorterDuffXPFactory::willReadDst(const GrProcOptInfo& colorPOI, | |
| 512 const GrProcOptInfo& coveragePOI) const
{ | |
| 513 return colorPOI.readsDst() || coveragePOI.readsDst(); | |
| 514 } | |
| 515 | |
| 516 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); | 487 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
| 517 | 488 |
| 518 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, | 489 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, |
| 519 GrContext*, | 490 GrContext*, |
| 520 const GrDrawTargetCaps&, | 491 const GrDrawTargetCaps&, |
| 521 GrTexture*[]) { | 492 GrTexture*[]) { |
| 522 GrBlendCoeff src; | 493 GrBlendCoeff src; |
| 523 do { | 494 do { |
| 524 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); | 495 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); |
| 525 } while (GrBlendCoeffRefsSrc(src)); | 496 } while (GrBlendCoeffRefsSrc(src)); |
| 526 | 497 |
| 527 GrBlendCoeff dst; | 498 GrBlendCoeff dst; |
| 528 do { | 499 do { |
| 529 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); | 500 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); |
| 530 } while (GrBlendCoeffRefsDst(dst)); | 501 } while (GrBlendCoeffRefsDst(dst)); |
| 531 | 502 |
| 532 return GrPorterDuffXPFactory::Create(src, dst); | 503 return GrPorterDuffXPFactory::Create(src, dst); |
| 533 } | 504 } |
| 534 | 505 |
| OLD | NEW |