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