OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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/GrCustomXfermode.h" | 8 #include "effects/GrCustomXfermode.h" |
9 #include "effects/GrCustomXfermodePriv.h" | 9 #include "effects/GrCustomXfermodePriv.h" |
10 | 10 |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 return fMode == s.fMode; | 488 return fMode == s.fMode; |
489 } | 489 } |
490 | 490 |
491 void GrCustomXferFP::onComputeInvariantOutput(GrInvariantOutput* inout) const { | 491 void GrCustomXferFP::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
492 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 492 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
493 } | 493 } |
494 | 494 |
495 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCustomXferFP); | 495 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCustomXferFP); |
496 GrFragmentProcessor* GrCustomXferFP::TestCreate(SkRandom* rand, | 496 GrFragmentProcessor* GrCustomXferFP::TestCreate(SkRandom* rand, |
497 GrContext*, | 497 GrContext*, |
498 const GrDrawTargetCaps&, | 498 const GrCaps&, |
499 GrTexture* textures[]) { | 499 GrTexture* textures[]) { |
500 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); | 500 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); |
501 | 501 |
502 return SkNEW_ARGS(GrCustomXferFP, (static_cast<SkXfermode::Mode>(mode), text
ures[0])); | 502 return SkNEW_ARGS(GrCustomXferFP, (static_cast<SkXfermode::Mode>(mode), text
ures[0])); |
503 } | 503 } |
504 | 504 |
505 /////////////////////////////////////////////////////////////////////////////// | 505 /////////////////////////////////////////////////////////////////////////////// |
506 // Xfer Processor | 506 // Xfer Processor |
507 /////////////////////////////////////////////////////////////////////////////// | 507 /////////////////////////////////////////////////////////////////////////////// |
508 | 508 |
(...skipping 24 matching lines...) Expand all Loading... |
533 return fHWBlendEquation; | 533 return fHWBlendEquation; |
534 } | 534 } |
535 | 535 |
536 private: | 536 private: |
537 CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool wi
llReadDstColor); | 537 CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool wi
llReadDstColor); |
538 | 538 |
539 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 539 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
540 const GrProcOptInfo& coveragePO
I, | 540 const GrProcOptInfo& coveragePO
I, |
541 bool doesStencilWrite, | 541 bool doesStencilWrite, |
542 GrColor* overrideColor, | 542 GrColor* overrideColor, |
543 const GrDrawTargetCaps& caps) o
verride; | 543 const GrCaps& caps) override; |
544 | 544 |
545 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 545 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
546 | 546 |
547 bool onWillNeedXferBarrier(const GrRenderTarget* rt, | 547 bool onWillNeedXferBarrier(const GrRenderTarget* rt, |
548 const GrDrawTargetCaps& caps, | 548 const GrCaps& caps, |
549 GrXferBarrierType* outBarrierType) const override
; | 549 GrXferBarrierType* outBarrierType) const override
; |
550 | 550 |
551 void onGetBlendInfo(BlendInfo*) const override; | 551 void onGetBlendInfo(BlendInfo*) const override; |
552 | 552 |
553 bool onIsEqual(const GrXferProcessor& xpBase) const override; | 553 bool onIsEqual(const GrXferProcessor& xpBase) const override; |
554 | 554 |
555 SkXfermode::Mode fMode; | 555 SkXfermode::Mode fMode; |
556 GrBlendEquation fHWBlendEquation; | 556 GrBlendEquation fHWBlendEquation; |
557 | 557 |
558 typedef GrXferProcessor INHERITED; | 558 typedef GrXferProcessor INHERITED; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 645 |
646 bool CustomXP::onIsEqual(const GrXferProcessor& other) const { | 646 bool CustomXP::onIsEqual(const GrXferProcessor& other) const { |
647 const CustomXP& s = other.cast<CustomXP>(); | 647 const CustomXP& s = other.cast<CustomXP>(); |
648 return fMode == s.fMode && fHWBlendEquation == s.fHWBlendEquation; | 648 return fMode == s.fMode && fHWBlendEquation == s.fHWBlendEquation; |
649 } | 649 } |
650 | 650 |
651 GrXferProcessor::OptFlags CustomXP::onGetOptimizations(const GrProcOptInfo& colo
rPOI, | 651 GrXferProcessor::OptFlags CustomXP::onGetOptimizations(const GrProcOptInfo& colo
rPOI, |
652 const GrProcOptInfo& cove
ragePOI, | 652 const GrProcOptInfo& cove
ragePOI, |
653 bool doesStencilWrite, | 653 bool doesStencilWrite, |
654 GrColor* overrideColor, | 654 GrColor* overrideColor, |
655 const GrDrawTargetCaps& c
aps) { | 655 const GrCaps& caps) { |
656 /* | 656 /* |
657 Most the optimizations we do here are based on tweaking alpha for coverage. | 657 Most the optimizations we do here are based on tweaking alpha for coverage. |
658 | 658 |
659 The general SVG blend equation is defined in the spec as follows: | 659 The general SVG blend equation is defined in the spec as follows: |
660 | 660 |
661 Dca' = B(Sc, Dc) * Sa * Da + Y * Sca * (1-Da) + Z * Dca * (1-Sa) | 661 Dca' = B(Sc, Dc) * Sa * Da + Y * Sca * (1-Da) + Z * Dca * (1-Sa) |
662 Da' = X * Sa * Da + Y * Sa * (1-Da) + Z * Da * (1-Sa) | 662 Da' = X * Sa * Da + Y * Sa * (1-Da) + Z * Da * (1-Sa) |
663 | 663 |
664 (Note that Sca, Dca indicate RGB vectors that are premultiplied by alpha, | 664 (Note that Sca, Dca indicate RGB vectors that are premultiplied by alpha, |
665 and that B(Sc, Dc) is a mode-specific function that accepts non-multiplied | 665 and that B(Sc, Dc) is a mode-specific function that accepts non-multiplied |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 flags |= kIgnoreCoverage_OptFlag; | 757 flags |= kIgnoreCoverage_OptFlag; |
758 } | 758 } |
759 if (caps.advancedBlendEquationSupport() && !coveragePOI.isFourChannelOutput(
)) { | 759 if (caps.advancedBlendEquationSupport() && !coveragePOI.isFourChannelOutput(
)) { |
760 // This blend mode can be implemented in hardware. | 760 // This blend mode can be implemented in hardware. |
761 fHWBlendEquation = hw_blend_equation(fMode); | 761 fHWBlendEquation = hw_blend_equation(fMode); |
762 } | 762 } |
763 return flags; | 763 return flags; |
764 } | 764 } |
765 | 765 |
766 bool CustomXP::onWillNeedXferBarrier(const GrRenderTarget* rt, | 766 bool CustomXP::onWillNeedXferBarrier(const GrRenderTarget* rt, |
767 const GrDrawTargetCaps& caps, | 767 const GrCaps& caps, |
768 GrXferBarrierType* outBarrierType) const { | 768 GrXferBarrierType* outBarrierType) const { |
769 if (this->hasHWBlendEquation() && !caps.advancedCoherentBlendEquationSupport
()) { | 769 if (this->hasHWBlendEquation() && !caps.advancedCoherentBlendEquationSupport
()) { |
770 *outBarrierType = kBlend_GrXferBarrierType; | 770 *outBarrierType = kBlend_GrXferBarrierType; |
771 return true; | 771 return true; |
772 } | 772 } |
773 return false; | 773 return false; |
774 } | 774 } |
775 | 775 |
776 void CustomXP::onGetBlendInfo(BlendInfo* blendInfo) const { | 776 void CustomXP::onGetBlendInfo(BlendInfo* blendInfo) const { |
777 if (this->hasHWBlendEquation()) { | 777 if (this->hasHWBlendEquation()) { |
778 blendInfo->fEquation = this->hwBlendEquation(); | 778 blendInfo->fEquation = this->hwBlendEquation(); |
779 } | 779 } |
780 } | 780 } |
781 | 781 |
782 /////////////////////////////////////////////////////////////////////////////// | 782 /////////////////////////////////////////////////////////////////////////////// |
783 | 783 |
784 GrCustomXPFactory::GrCustomXPFactory(SkXfermode::Mode mode) | 784 GrCustomXPFactory::GrCustomXPFactory(SkXfermode::Mode mode) |
785 : fMode(mode) { | 785 : fMode(mode) { |
786 this->initClassID<GrCustomXPFactory>(); | 786 this->initClassID<GrCustomXPFactory>(); |
787 } | 787 } |
788 | 788 |
789 GrXferProcessor* | 789 GrXferProcessor* |
790 GrCustomXPFactory::onCreateXferProcessor(const GrDrawTargetCaps& caps, | 790 GrCustomXPFactory::onCreateXferProcessor(const GrCaps& caps, |
791 const GrProcOptInfo& colorPOI, | 791 const GrProcOptInfo& colorPOI, |
792 const GrProcOptInfo& coveragePOI, | 792 const GrProcOptInfo& coveragePOI, |
793 const GrDeviceCoordTexture* dstCopy) co
nst { | 793 const GrDeviceCoordTexture* dstCopy) co
nst { |
794 return CustomXP::Create(fMode, dstCopy, this->willReadDstColor(caps, colorPO
I, coveragePOI)); | 794 return CustomXP::Create(fMode, dstCopy, this->willReadDstColor(caps, colorPO
I, coveragePOI)); |
795 } | 795 } |
796 | 796 |
797 bool GrCustomXPFactory::willReadDstColor(const GrDrawTargetCaps& caps, | 797 bool GrCustomXPFactory::willReadDstColor(const GrCaps& caps, |
798 const GrProcOptInfo& colorPOI, | 798 const GrProcOptInfo& colorPOI, |
799 const GrProcOptInfo& coveragePOI) const
{ | 799 const GrProcOptInfo& coveragePOI) const
{ |
800 if (!caps.advancedBlendEquationSupport()) { | 800 if (!caps.advancedBlendEquationSupport()) { |
801 // No hardware support for advanced blend equations; we will need to do
it in the shader. | 801 // No hardware support for advanced blend equations; we will need to do
it in the shader. |
802 return true; | 802 return true; |
803 } | 803 } |
804 if (coveragePOI.isFourChannelOutput()) { | 804 if (coveragePOI.isFourChannelOutput()) { |
805 // Advanced blend equations can't tweak alpha for RGB coverage. | 805 // Advanced blend equations can't tweak alpha for RGB coverage. |
806 return true; | 806 return true; |
807 } | 807 } |
808 return false; | 808 return false; |
809 } | 809 } |
810 | 810 |
811 void GrCustomXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, | 811 void GrCustomXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, |
812 const GrProcOptInfo& coveragePOI, | 812 const GrProcOptInfo& coveragePOI, |
813 GrXPFactory::InvariantOutput* out
put) const { | 813 GrXPFactory::InvariantOutput* out
put) const { |
814 output->fWillBlendWithDst = true; | 814 output->fWillBlendWithDst = true; |
815 output->fBlendedColorFlags = 0; | 815 output->fBlendedColorFlags = 0; |
816 } | 816 } |
817 | 817 |
818 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); | 818 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); |
819 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, | 819 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, |
820 GrContext*, | 820 GrContext*, |
821 const GrDrawTargetCaps&, | 821 const GrCaps&, |
822 GrTexture*[]) { | 822 GrTexture*[]) { |
823 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); | 823 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); |
824 | 824 |
825 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); | 825 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); |
826 } | 826 } |
827 | 827 |
OLD | NEW |