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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 GrBlendCoeff getDstBlend() const { return fDstBlend; } | 88 GrBlendCoeff getDstBlend() const { return fDstBlend; } |
89 | 89 |
90 private: | 90 private: |
91 PorterDuffXferProcessor(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, GrColo
r constant, | 91 PorterDuffXferProcessor(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, GrColo
r constant, |
92 const GrDeviceCoordTexture* dstCopy, bool willReadDs
tColor); | 92 const GrDeviceCoordTexture* dstCopy, bool willReadDs
tColor); |
93 | 93 |
94 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 94 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
95 const GrProcOptInfo& coveragePO
I, | 95 const GrProcOptInfo& coveragePO
I, |
96 bool doesStencilWrite, | 96 bool doesStencilWrite, |
97 GrColor* overrideColor, | 97 GrColor* overrideColor, |
98 const GrDrawTargetCaps& caps) o
verride; | 98 const GrCaps& caps) override; |
99 | 99 |
100 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 100 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
101 | 101 |
102 void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { | 102 void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { |
103 if (!this->willReadDstColor()) { | 103 if (!this->willReadDstColor()) { |
104 blendInfo->fSrcBlend = fSrcBlend; | 104 blendInfo->fSrcBlend = fSrcBlend; |
105 blendInfo->fDstBlend = fDstBlend; | 105 blendInfo->fDstBlend = fDstBlend; |
106 } else { | 106 } else { |
107 blendInfo->fSrcBlend = kOne_GrBlendCoeff; | 107 blendInfo->fSrcBlend = kOne_GrBlendCoeff; |
108 blendInfo->fDstBlend = kZero_GrBlendCoeff; | 108 blendInfo->fDstBlend = kZero_GrBlendCoeff; |
(...skipping 10 matching lines...) Expand all Loading... |
119 fSecondaryOutputType != xp.fSecondaryOutputType) { | 119 fSecondaryOutputType != xp.fSecondaryOutputType) { |
120 return false; | 120 return false; |
121 } | 121 } |
122 return true; | 122 return true; |
123 } | 123 } |
124 | 124 |
125 GrXferProcessor::OptFlags internalGetOptimizations(const GrProcOptInfo& colo
rPOI, | 125 GrXferProcessor::OptFlags internalGetOptimizations(const GrProcOptInfo& colo
rPOI, |
126 const GrProcOptInfo& cove
ragePOI, | 126 const GrProcOptInfo& cove
ragePOI, |
127 bool doesStencilWrite); | 127 bool doesStencilWrite); |
128 | 128 |
129 void calcOutputTypes(GrXferProcessor::OptFlags blendOpts, const GrDrawTarget
Caps& caps, | 129 void calcOutputTypes(GrXferProcessor::OptFlags blendOpts, const GrCaps& caps
, |
130 bool hasSolidCoverage); | 130 bool hasSolidCoverage); |
131 | 131 |
132 GrBlendCoeff fSrcBlend; | 132 GrBlendCoeff fSrcBlend; |
133 GrBlendCoeff fDstBlend; | 133 GrBlendCoeff fDstBlend; |
134 GrColor fBlendConstant; | 134 GrColor fBlendConstant; |
135 PrimaryOutputType fPrimaryOutputType; | 135 PrimaryOutputType fPrimaryOutputType; |
136 SecondaryOutputType fSecondaryOutputType; | 136 SecondaryOutputType fSecondaryOutputType; |
137 | 137 |
138 typedef GrXferProcessor INHERITED; | 138 typedef GrXferProcessor INHERITED; |
139 }; | 139 }; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 298 |
299 GrGLXferProcessor* PorterDuffXferProcessor::createGLInstance() const { | 299 GrGLXferProcessor* PorterDuffXferProcessor::createGLInstance() const { |
300 return SkNEW_ARGS(GLPorterDuffXferProcessor, (*this)); | 300 return SkNEW_ARGS(GLPorterDuffXferProcessor, (*this)); |
301 } | 301 } |
302 | 302 |
303 GrXferProcessor::OptFlags | 303 GrXferProcessor::OptFlags |
304 PorterDuffXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, | 304 PorterDuffXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, |
305 const GrProcOptInfo& coveragePOI, | 305 const GrProcOptInfo& coveragePOI, |
306 bool doesStencilWrite, | 306 bool doesStencilWrite, |
307 GrColor* overrideColor, | 307 GrColor* overrideColor, |
308 const GrDrawTargetCaps& caps) { | 308 const GrCaps& caps) { |
309 GrXferProcessor::OptFlags optFlags = this->internalGetOptimizations(colorPOI
, | 309 GrXferProcessor::OptFlags optFlags = this->internalGetOptimizations(colorPOI
, |
310 coverage
POI, | 310 coverage
POI, |
311 doesSten
cilWrite); | 311 doesSten
cilWrite); |
312 this->calcOutputTypes(optFlags, caps, coveragePOI.isSolidWhite()); | 312 this->calcOutputTypes(optFlags, caps, coveragePOI.isSolidWhite()); |
313 return optFlags; | 313 return optFlags; |
314 } | 314 } |
315 | 315 |
316 void PorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFlags
, | 316 void PorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFlags
, |
317 const GrDrawTargetCaps& caps, | 317 const GrCaps& caps, |
318 bool hasSolidCoverage) { | 318 bool hasSolidCoverage) { |
319 if (this->willReadDstColor()) { | 319 if (this->willReadDstColor()) { |
320 fPrimaryOutputType = kCustom_PrimaryOutputType; | 320 fPrimaryOutputType = kCustom_PrimaryOutputType; |
321 return; | 321 return; |
322 } | 322 } |
323 | 323 |
324 if (optFlags & kIgnoreColor_OptFlag) { | 324 if (optFlags & kIgnoreColor_OptFlag) { |
325 if (optFlags & kIgnoreCoverage_OptFlag) { | 325 if (optFlags & kIgnoreCoverage_OptFlag) { |
326 fPrimaryOutputType = kNone_PrimaryOutputType; | 326 fPrimaryOutputType = kNone_PrimaryOutputType; |
327 return; | 327 return; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 477 |
478 bool hasSecondaryOutput() const override { return false; } | 478 bool hasSecondaryOutput() const override { return false; } |
479 | 479 |
480 private: | 480 private: |
481 PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha); | 481 PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha); |
482 | 482 |
483 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 483 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
484 const GrProcOptInfo& coveragePO
I, | 484 const GrProcOptInfo& coveragePO
I, |
485 bool doesStencilWrite, | 485 bool doesStencilWrite, |
486 GrColor* overrideColor, | 486 GrColor* overrideColor, |
487 const GrDrawTargetCaps& caps) o
verride; | 487 const GrCaps& caps) override; |
488 | 488 |
489 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 489 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
490 | 490 |
491 void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { | 491 void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { |
492 blendInfo->fSrcBlend = kConstC_GrBlendCoeff; | 492 blendInfo->fSrcBlend = kConstC_GrBlendCoeff; |
493 blendInfo->fDstBlend = kISC_GrBlendCoeff; | 493 blendInfo->fDstBlend = kISC_GrBlendCoeff; |
494 blendInfo->fBlendConstant = fBlendConstant; | 494 blendInfo->fBlendConstant = fBlendConstant; |
495 } | 495 } |
496 | 496 |
497 bool onIsEqual(const GrXferProcessor& xpBase) const override { | 497 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 568 |
569 GrGLXferProcessor* PDLCDXferProcessor::createGLInstance() const { | 569 GrGLXferProcessor* PDLCDXferProcessor::createGLInstance() const { |
570 return SkNEW_ARGS(GLPDLCDXferProcessor, (*this)); | 570 return SkNEW_ARGS(GLPDLCDXferProcessor, (*this)); |
571 } | 571 } |
572 | 572 |
573 GrXferProcessor::OptFlags | 573 GrXferProcessor::OptFlags |
574 PDLCDXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, | 574 PDLCDXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, |
575 const GrProcOptInfo& coveragePOI, | 575 const GrProcOptInfo& coveragePOI, |
576 bool doesStencilWrite, | 576 bool doesStencilWrite, |
577 GrColor* overrideColor, | 577 GrColor* overrideColor, |
578 const GrDrawTargetCaps& caps) { | 578 const GrCaps& caps) { |
579 // We want to force our primary output to be alpha * Coverage, where alp
ha is the alpha | 579 // We want to force our primary output to be alpha * Coverage, where alp
ha is the alpha |
580 // value of the blend the constant. We should already have valid blend c
oeff's if we are at | 580 // value of the blend the constant. We should already have valid blend c
oeff's if we are at |
581 // a point where we have RGB coverage. We don't need any color stages si
nce the known color | 581 // a point where we have RGB coverage. We don't need any color stages si
nce the known color |
582 // output is already baked into the blendConstant. | 582 // output is already baked into the blendConstant. |
583 *overrideColor = GrColorPackRGBA(fAlpha, fAlpha, fAlpha, fAlpha); | 583 *overrideColor = GrColorPackRGBA(fAlpha, fAlpha, fAlpha, fAlpha); |
584 return GrXferProcessor::kOverrideColor_OptFlag; | 584 return GrXferProcessor::kOverrideColor_OptFlag; |
585 } | 585 } |
586 | 586 |
587 /////////////////////////////////////////////////////////////////////////////// | 587 /////////////////////////////////////////////////////////////////////////////// |
588 GrPorterDuffXPFactory::GrPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) | 588 GrPorterDuffXPFactory::GrPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 static GrPorterDuffXPFactory gScreenPDXPF(kOne_GrBlendCoeff, kISC_Gr
BlendCoeff); | 666 static GrPorterDuffXPFactory gScreenPDXPF(kOne_GrBlendCoeff, kISC_Gr
BlendCoeff); |
667 return SkRef(&gScreenPDXPF); | 667 return SkRef(&gScreenPDXPF); |
668 break; | 668 break; |
669 } | 669 } |
670 default: | 670 default: |
671 return NULL; | 671 return NULL; |
672 } | 672 } |
673 } | 673 } |
674 | 674 |
675 GrXferProcessor* | 675 GrXferProcessor* |
676 GrPorterDuffXPFactory::onCreateXferProcessor(const GrDrawTargetCaps& caps, | 676 GrPorterDuffXPFactory::onCreateXferProcessor(const GrCaps& caps, |
677 const GrProcOptInfo& colorPOI, | 677 const GrProcOptInfo& colorPOI, |
678 const GrProcOptInfo& covPOI, | 678 const GrProcOptInfo& covPOI, |
679 const GrDeviceCoordTexture* dstCopy
) const { | 679 const GrDeviceCoordTexture* dstCopy
) const { |
680 if (covPOI.isFourChannelOutput()) { | 680 if (covPOI.isFourChannelOutput()) { |
681 return PDLCDXferProcessor::Create(fSrcCoeff, fDstCoeff, colorPOI); | 681 return PDLCDXferProcessor::Create(fSrcCoeff, fDstCoeff, colorPOI); |
682 } else { | 682 } else { |
683 return PorterDuffXferProcessor::Create(fSrcCoeff, fDstCoeff, 0, dstCopy, | 683 return PorterDuffXferProcessor::Create(fSrcCoeff, fDstCoeff, 0, dstCopy, |
684 this->willReadDstColor(caps, colo
rPOI, covPOI)); | 684 this->willReadDstColor(caps, colo
rPOI, covPOI)); |
685 } | 685 } |
686 } | 686 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 case kIConstC_GrBlendCoeff: | 756 case kIConstC_GrBlendCoeff: |
757 case kConstA_GrBlendCoeff: | 757 case kConstA_GrBlendCoeff: |
758 case kIConstA_GrBlendCoeff: | 758 case kIConstA_GrBlendCoeff: |
759 output->fBlendedColorFlags = 0; | 759 output->fBlendedColorFlags = 0; |
760 break; | 760 break; |
761 } | 761 } |
762 | 762 |
763 output->fWillBlendWithDst = false; | 763 output->fWillBlendWithDst = false; |
764 } | 764 } |
765 | 765 |
766 bool GrPorterDuffXPFactory::willReadDstColor(const GrDrawTargetCaps& caps, | 766 bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps, |
767 const GrProcOptInfo& colorPOI, | 767 const GrProcOptInfo& colorPOI, |
768 const GrProcOptInfo& coveragePOI) c
onst { | 768 const GrProcOptInfo& coveragePOI) c
onst { |
769 // We can always blend correctly if we have dual source blending. | 769 // We can always blend correctly if we have dual source blending. |
770 if (caps.shaderCaps()->dualSourceBlendingSupport()) { | 770 if (caps.shaderCaps()->dualSourceBlendingSupport()) { |
771 return false; | 771 return false; |
772 } | 772 } |
773 | 773 |
774 if (can_tweak_alpha_for_coverage(fDstCoeff)) { | 774 if (can_tweak_alpha_for_coverage(fDstCoeff)) { |
775 return false; | 775 return false; |
776 } | 776 } |
(...skipping 16 matching lines...) Expand all Loading... |
793 return false; | 793 return false; |
794 } | 794 } |
795 | 795 |
796 return true; | 796 return true; |
797 } | 797 } |
798 | 798 |
799 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); | 799 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
800 | 800 |
801 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, | 801 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, |
802 GrContext*, | 802 GrContext*, |
803 const GrDrawTargetCaps&, | 803 const GrCaps&, |
804 GrTexture*[]) { | 804 GrTexture*[]) { |
805 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k
LastCoeffMode)); | 805 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k
LastCoeffMode)); |
806 return GrPorterDuffXPFactory::Create(mode); | 806 return GrPorterDuffXPFactory::Create(mode); |
807 } | 807 } |
808 | 808 |
OLD | NEW |