| 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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 if (SkXfermode::kSrcOver_Mode == fXfermode && | 737 if (SkXfermode::kSrcOver_Mode == fXfermode && |
| 738 kRGBA_GrColorComponentFlags == knownColorFlags) { | 738 kRGBA_GrColorComponentFlags == knownColorFlags) { |
| 739 return true; | 739 return true; |
| 740 } | 740 } |
| 741 return false; | 741 return false; |
| 742 } | 742 } |
| 743 | 743 |
| 744 void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, | 744 void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, |
| 745 const GrProcOptInfo& coveragePOI, | 745 const GrProcOptInfo& coveragePOI, |
| 746 GrXPFactory::InvariantOutput* out
put) const { | 746 GrXPFactory::InvariantOutput* out
put) const { |
| 747 output->fWillBlendWithDst = true; | 747 const BlendFormula& blendFormula = get_blend_formula(fXfermode, colorPOI, co
veragePOI); |
| 748 output->fBlendedColorFlags = kNone_GrColorComponentFlags; | |
| 749 | 748 |
| 750 // The LCD coverage XP doesn't use the blend table, and has no invariant out
put. | 749 if (blendFormula.usesDstColor()) { |
| 751 if (coveragePOI.isFourChannelOutput()) { | 750 output->fWillBlendWithDst = true; |
| 751 output->fBlendedColorFlags = kNone_GrColorComponentFlags; |
| 752 return; | 752 return; |
| 753 } | 753 } |
| 754 | 754 |
| 755 const BlendFormula& blendFormula = get_blend_formula(fXfermode, colorPOI, co
veragePOI); | |
| 756 if (blendFormula.usesDstColor()) { | |
| 757 return; | |
| 758 } | |
| 759 | |
| 760 SkASSERT(coveragePOI.isSolidWhite()); | 755 SkASSERT(coveragePOI.isSolidWhite()); |
| 761 SkASSERT(kAdd_GrBlendEquation == blendFormula.fBlendEquation); | 756 SkASSERT(kAdd_GrBlendEquation == blendFormula.fBlendEquation); |
| 762 | 757 |
| 763 output->fWillBlendWithDst = false; | 758 output->fWillBlendWithDst = false; |
| 764 | 759 |
| 765 switch (blendFormula.fSrcCoeff) { | 760 switch (blendFormula.fSrcCoeff) { |
| 766 case kZero_GrBlendCoeff: | 761 case kZero_GrBlendCoeff: |
| 767 output->fBlendedColor = 0; | 762 output->fBlendedColor = 0; |
| 768 output->fBlendedColorFlags = kRGBA_GrColorComponentFlags; | 763 output->fBlendedColorFlags = kRGBA_GrColorComponentFlags; |
| 769 return; | 764 return; |
| 770 | 765 |
| 771 case kOne_GrBlendCoeff: | 766 case kOne_GrBlendCoeff: |
| 772 output->fBlendedColor = colorPOI.color(); | 767 output->fBlendedColor = colorPOI.color(); |
| 773 output->fBlendedColorFlags = colorPOI.validFlags(); | 768 output->fBlendedColorFlags = colorPOI.validFlags(); |
| 774 return; | 769 return; |
| 775 | 770 |
| 776 default: return; | 771 // TODO: update if we ever use const color. |
| 772 default: |
| 773 output->fBlendedColorFlags = kNone_GrColorComponentFlags; |
| 774 return; |
| 777 } | 775 } |
| 778 } | 776 } |
| 779 | 777 |
| 780 bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps, | 778 bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps, |
| 781 const GrProcOptInfo& colorPOI, | 779 const GrProcOptInfo& colorPOI, |
| 782 const GrProcOptInfo& coveragePOI) c
onst { | 780 const GrProcOptInfo& coveragePOI) c
onst { |
| 783 // The LCD coverage XP doesn't use the blend table, and never requires a dst
read. | |
| 784 if (coveragePOI.isFourChannelOutput()) { | |
| 785 return false; | |
| 786 } | |
| 787 | |
| 788 // Some formulas use dual source blending, so we fall back if it is required
but not supported. | 781 // Some formulas use dual source blending, so we fall back if it is required
but not supported. |
| 789 return !caps.shaderCaps()->dualSourceBlendingSupport() && | 782 return !caps.shaderCaps()->dualSourceBlendingSupport() && |
| 790 get_blend_formula(fXfermode, colorPOI, coveragePOI).hasSecondaryOutpu
t(); | 783 get_blend_formula(fXfermode, colorPOI, coveragePOI).hasSecondaryOutpu
t(); |
| 791 } | 784 } |
| 792 | 785 |
| 793 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); | 786 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
| 794 | 787 |
| 795 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, | 788 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, |
| 796 GrContext*, | 789 GrContext*, |
| 797 const GrCaps&, | 790 const GrCaps&, |
| 798 GrTexture*[]) { | 791 GrTexture*[]) { |
| 799 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k
LastCoeffMode)); | 792 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k
LastCoeffMode)); |
| 800 return GrPorterDuffXPFactory::Create(mode); | 793 return GrPorterDuffXPFactory::Create(mode); |
| 801 } | 794 } |
| 802 | 795 |
| 803 void GrPorterDuffXPFactory::TestGetXPOutputTypes(const GrXferProcessor* xp, | 796 void GrPorterDuffXPFactory::TestGetXPOutputTypes(const GrXferProcessor* xp, |
| 804 int* outPrimary, | 797 int* outPrimary, |
| 805 int* outSecondary) { | 798 int* outSecondary) { |
| 806 if (!!strcmp(xp->name(), "Porter Duff")) { | 799 if (!!strcmp(xp->name(), "Porter Duff")) { |
| 807 *outPrimary = *outSecondary = -1; | 800 *outPrimary = *outSecondary = -1; |
| 808 return; | 801 return; |
| 809 } | 802 } |
| 810 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); | 803 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); |
| 811 *outPrimary = blendFormula.fPrimaryOutputType; | 804 *outPrimary = blendFormula.fPrimaryOutputType; |
| 812 *outSecondary = blendFormula.fSecondaryOutputType; | 805 *outSecondary = blendFormula.fSecondaryOutputType; |
| 813 } | 806 } |
| 814 | 807 |
| OLD | NEW |