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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 724 |
725 GrXferProcessor* | 725 GrXferProcessor* |
726 GrPorterDuffXPFactory::onCreateXferProcessor(const GrCaps& caps, | 726 GrPorterDuffXPFactory::onCreateXferProcessor(const GrCaps& caps, |
727 const GrProcOptInfo& colorPOI, | 727 const GrProcOptInfo& colorPOI, |
728 const GrProcOptInfo& covPOI, | 728 const GrProcOptInfo& covPOI, |
729 bool hasMixedSamples, | 729 bool hasMixedSamples, |
730 const DstTexture* dstTexture) const
{ | 730 const DstTexture* dstTexture) const
{ |
731 BlendFormula blendFormula; | 731 BlendFormula blendFormula; |
732 if (covPOI.isFourChannelOutput()) { | 732 if (covPOI.isFourChannelOutput()) { |
733 if (SkXfermode::kSrcOver_Mode == fXfermode && | 733 if (SkXfermode::kSrcOver_Mode == fXfermode && |
734 kRGBA_GrColorComponentFlags == colorPOI.validFlags()) { | 734 kRGBA_GrColorComponentFlags == colorPOI.validFlags() && |
| 735 !caps.shaderCaps()->dualSourceBlendingSupport() && |
| 736 !caps.shaderCaps()->dstReadInShaderSupport()) { |
| 737 // If we don't have dual source blending or in shader dst reads, we
fall back to this |
| 738 // trick for rendering SrcOver LCD text instead of doing a dst copy. |
735 SkASSERT(!dstTexture || !dstTexture->texture()); | 739 SkASSERT(!dstTexture || !dstTexture->texture()); |
736 return PDLCDXferProcessor::Create(fXfermode, colorPOI); | 740 return PDLCDXferProcessor::Create(fXfermode, colorPOI); |
737 } | 741 } |
738 blendFormula = get_lcd_blend_formula(covPOI, fXfermode); | 742 blendFormula = get_lcd_blend_formula(covPOI, fXfermode); |
739 } else { | 743 } else { |
740 blendFormula = get_blend_formula(colorPOI, covPOI, hasMixedSamples, fXfe
rmode); | 744 blendFormula = get_blend_formula(colorPOI, covPOI, hasMixedSamples, fXfe
rmode); |
741 } | 745 } |
742 | 746 |
743 if (blendFormula.hasSecondaryOutput() && !caps.shaderCaps()->dualSourceBlend
ingSupport()) { | 747 if (blendFormula.hasSecondaryOutput() && !caps.shaderCaps()->dualSourceBlend
ingSupport()) { |
744 return new ShaderPDXferProcessor(dstTexture, hasMixedSamples, fXfermode)
; | 748 return new ShaderPDXferProcessor(dstTexture, hasMixedSamples, fXfermode)
; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 bool hasMixedSamples) const { | 789 bool hasMixedSamples) const { |
786 if (caps.shaderCaps()->dualSourceBlendingSupport()) { | 790 if (caps.shaderCaps()->dualSourceBlendingSupport()) { |
787 return false; | 791 return false; |
788 } | 792 } |
789 | 793 |
790 // When we have four channel coverage we always need to read the dst in orde
r to correctly | 794 // When we have four channel coverage we always need to read the dst in orde
r to correctly |
791 // blend. The one exception is when we are using srcover mode and we know th
e input color into | 795 // blend. The one exception is when we are using srcover mode and we know th
e input color into |
792 // the XP. | 796 // the XP. |
793 if (covPOI.isFourChannelOutput()) { | 797 if (covPOI.isFourChannelOutput()) { |
794 if (SkXfermode::kSrcOver_Mode == fXfermode && | 798 if (SkXfermode::kSrcOver_Mode == fXfermode && |
795 kRGBA_GrColorComponentFlags == colorPOI.validFlags()) { | 799 kRGBA_GrColorComponentFlags == colorPOI.validFlags() && |
| 800 !caps.shaderCaps()->dstReadInShaderSupport()) { |
796 return false; | 801 return false; |
797 } | 802 } |
798 return get_lcd_blend_formula(covPOI, fXfermode).hasSecondaryOutput(); | 803 return get_lcd_blend_formula(covPOI, fXfermode).hasSecondaryOutput(); |
799 } | 804 } |
800 // We fallback on the shader XP when the blend formula would use dual source
blending but we | 805 // We fallback on the shader XP when the blend formula would use dual source
blending but we |
801 // don't have support for it. | 806 // don't have support for it. |
802 return get_blend_formula(colorPOI, covPOI, hasMixedSamples, fXfermode).hasSe
condaryOutput(); | 807 return get_blend_formula(colorPOI, covPOI, hasMixedSamples, fXfermode).hasSe
condaryOutput(); |
803 } | 808 } |
804 | 809 |
805 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); | 810 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
806 | 811 |
807 const GrXPFactory* GrPorterDuffXPFactory::TestCreate(GrProcessorTestData* d) { | 812 const GrXPFactory* GrPorterDuffXPFactory::TestCreate(GrProcessorTestData* d) { |
808 SkXfermode::Mode mode = SkXfermode::Mode(d->fRandom->nextULessThan(SkXfermod
e::kLastCoeffMode)); | 813 SkXfermode::Mode mode = SkXfermode::Mode(d->fRandom->nextULessThan(SkXfermod
e::kLastCoeffMode)); |
809 return GrPorterDuffXPFactory::Create(mode); | 814 return GrPorterDuffXPFactory::Create(mode); |
810 } | 815 } |
811 | 816 |
812 void GrPorterDuffXPFactory::TestGetXPOutputTypes(const GrXferProcessor* xp, | 817 void GrPorterDuffXPFactory::TestGetXPOutputTypes(const GrXferProcessor* xp, |
813 int* outPrimary, | 818 int* outPrimary, |
814 int* outSecondary) { | 819 int* outSecondary) { |
815 if (!!strcmp(xp->name(), "Porter Duff")) { | 820 if (!!strcmp(xp->name(), "Porter Duff")) { |
816 *outPrimary = *outSecondary = -1; | 821 *outPrimary = *outSecondary = -1; |
817 return; | 822 return; |
818 } | 823 } |
819 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); | 824 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); |
820 *outPrimary = blendFormula.fPrimaryOutputType; | 825 *outPrimary = blendFormula.fPrimaryOutputType; |
821 *outSecondary = blendFormula.fSecondaryOutputType; | 826 *outSecondary = blendFormula.fSecondaryOutputType; |
822 } | 827 } |
OLD | NEW |