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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 /////////////////////////////////////////////////////////////////////////////// | 517 /////////////////////////////////////////////////////////////////////////////// |
518 | 518 |
519 class CustomXP : public GrXferProcessor { | 519 class CustomXP : public GrXferProcessor { |
520 public: | 520 public: |
521 CustomXP(SkXfermode::Mode mode, GrBlendEquation hwBlendEquation) | 521 CustomXP(SkXfermode::Mode mode, GrBlendEquation hwBlendEquation) |
522 : fMode(mode), | 522 : fMode(mode), |
523 fHWBlendEquation(hwBlendEquation) { | 523 fHWBlendEquation(hwBlendEquation) { |
524 this->initClassID<CustomXP>(); | 524 this->initClassID<CustomXP>(); |
525 } | 525 } |
526 | 526 |
527 CustomXP(SkXfermode::Mode mode, const DstTexture* dstTexture) | 527 CustomXP(const DstTexture* dstTexture, bool hasMixedSamples, SkXfermode::Mod
e mode) |
528 : INHERITED(dstTexture, true), | 528 : INHERITED(dstTexture, true, hasMixedSamples), |
529 fMode(mode), | 529 fMode(mode), |
530 fHWBlendEquation(static_cast<GrBlendEquation>(-1)) { | 530 fHWBlendEquation(static_cast<GrBlendEquation>(-1)) { |
531 this->initClassID<CustomXP>(); | 531 this->initClassID<CustomXP>(); |
532 } | 532 } |
533 | 533 |
534 const char* name() const override { return "Custom Xfermode"; } | 534 const char* name() const override { return "Custom Xfermode"; } |
535 | 535 |
536 GrGLXferProcessor* createGLInstance() const override; | 536 GrGLXferProcessor* createGLInstance() const override; |
537 | 537 |
538 SkXfermode::Mode mode() const { return fMode; } | 538 SkXfermode::Mode mode() const { return fMode; } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 } | 599 } |
600 | 600 |
601 private: | 601 private: |
602 void emitOutputsForBlendState(const EmitArgs& args) override { | 602 void emitOutputsForBlendState(const EmitArgs& args) override { |
603 const CustomXP& xp = args.fXP.cast<CustomXP>(); | 603 const CustomXP& xp = args.fXP.cast<CustomXP>(); |
604 SkASSERT(xp.hasHWBlendEquation()); | 604 SkASSERT(xp.hasHWBlendEquation()); |
605 | 605 |
606 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 606 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
607 fsBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation()); | 607 fsBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation()); |
608 | 608 |
609 // Apply coverage by multiplying it into the src color before blending. | 609 // Apply coverage by multiplying it into the src color before blending.
Mixed samples will |
610 // (See onGetOptimizations()) | 610 // "just work" automatically. (See onGetOptimizations()) |
611 if (xp.readsCoverage()) { | 611 if (xp.readsCoverage()) { |
612 fsBuilder->codeAppendf("%s = %s * %s;", | 612 fsBuilder->codeAppendf("%s = %s * %s;", |
613 args.fOutputPrimary, args.fInputCoverage, arg
s.fInputColor); | 613 args.fOutputPrimary, args.fInputCoverage, arg
s.fInputColor); |
614 } else { | 614 } else { |
615 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
olor); | 615 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
olor); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 void emitBlendCodeForDstRead(GrGLXPBuilder* pb, const char* srcColor, const
char* dstColor, | 619 void emitBlendCodeForDstRead(GrGLXPBuilder* pb, const char* srcColor, const
char* dstColor, |
620 const char* outColor, const GrXferProcessor& pr
oc) override { | 620 const char* outColor, const GrXferProcessor& pr
oc) override { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 : fMode(mode), | 779 : fMode(mode), |
780 fHWBlendEquation(hw_blend_equation(mode)) { | 780 fHWBlendEquation(hw_blend_equation(mode)) { |
781 SkASSERT(GrCustomXfermode::IsSupportedMode(fMode)); | 781 SkASSERT(GrCustomXfermode::IsSupportedMode(fMode)); |
782 this->initClassID<GrCustomXPFactory>(); | 782 this->initClassID<GrCustomXPFactory>(); |
783 } | 783 } |
784 | 784 |
785 GrXferProcessor* | 785 GrXferProcessor* |
786 GrCustomXPFactory::onCreateXferProcessor(const GrCaps& caps, | 786 GrCustomXPFactory::onCreateXferProcessor(const GrCaps& caps, |
787 const GrProcOptInfo& colorPOI, | 787 const GrProcOptInfo& colorPOI, |
788 const GrProcOptInfo& coveragePOI, | 788 const GrProcOptInfo& coveragePOI, |
| 789 bool hasMixedSamples, |
789 const DstTexture* dstTexture) const { | 790 const DstTexture* dstTexture) const { |
790 if (can_use_hw_blend_equation(coveragePOI, caps)) { | 791 if (can_use_hw_blend_equation(coveragePOI, caps)) { |
791 SkASSERT(!dstTexture || !dstTexture->texture()); | 792 SkASSERT(!dstTexture || !dstTexture->texture()); |
792 return SkNEW_ARGS(CustomXP, (fMode, fHWBlendEquation)); | 793 return SkNEW_ARGS(CustomXP, (fMode, fHWBlendEquation)); |
793 } | 794 } |
794 return SkNEW_ARGS(CustomXP, (fMode, dstTexture)); | 795 return SkNEW_ARGS(CustomXP, (dstTexture, hasMixedSamples, fMode)); |
795 } | 796 } |
796 | 797 |
797 bool GrCustomXPFactory::willReadDstColor(const GrCaps& caps, | 798 bool GrCustomXPFactory::willReadDstColor(const GrCaps& caps, |
798 const GrProcOptInfo& colorPOI, | 799 const GrProcOptInfo& colorPOI, |
799 const GrProcOptInfo& coveragePOI) const
{ | 800 const GrProcOptInfo& coveragePOI, |
| 801 bool hasMixedSamples) const { |
800 return !can_use_hw_blend_equation(coveragePOI, caps); | 802 return !can_use_hw_blend_equation(coveragePOI, caps); |
801 } | 803 } |
802 | 804 |
803 void GrCustomXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorPOI, | 805 void GrCustomXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorPOI, |
804 InvariantBlendedColor* blendedC
olor) const { | 806 InvariantBlendedColor* blendedC
olor) const { |
805 blendedColor->fWillBlendWithDst = true; | 807 blendedColor->fWillBlendWithDst = true; |
806 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; | 808 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; |
807 } | 809 } |
808 | 810 |
809 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); | 811 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); |
810 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, | 812 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, |
811 GrContext*, | 813 GrContext*, |
812 const GrCaps&, | 814 const GrCaps&, |
813 GrTexture*[]) { | 815 GrTexture*[]) { |
814 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); | 816 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); |
815 | 817 |
816 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); | 818 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); |
817 } | 819 } |
818 | 820 |
OLD | NEW |