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 |
11 #include "GrCoordTransform.h" | 11 #include "GrCoordTransform.h" |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrFragmentProcessor.h" | 13 #include "GrFragmentProcessor.h" |
14 #include "GrInvariantOutput.h" | 14 #include "GrInvariantOutput.h" |
15 #include "GrProcessor.h" | 15 #include "GrProcessor.h" |
16 #include "GrTexture.h" | 16 #include "GrTexture.h" |
17 #include "GrTextureAccess.h" | 17 #include "GrTextureAccess.h" |
18 #include "SkXfermode.h" | 18 #include "SkXfermode.h" |
19 #include "gl/GrGLCaps.h" | 19 #include "gl/GrGLCaps.h" |
20 #include "gl/GrGLGpu.h" | |
20 #include "gl/GrGLProcessor.h" | 21 #include "gl/GrGLProcessor.h" |
21 #include "gl/GrGLProgramDataManager.h" | 22 #include "gl/GrGLProgramDataManager.h" |
22 #include "gl/builders/GrGLProgramBuilder.h" | 23 #include "gl/builders/GrGLProgramBuilder.h" |
23 | 24 |
24 bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) { | 25 bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) { |
25 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMode; | 26 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMode; |
26 } | 27 } |
27 | 28 |
28 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
29 // Static helpers | 30 // Static helpers |
30 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
31 | 32 |
33 static GrBlendEquation hw_blend_equation(SkXfermode::Mode mode) { | |
34 enum { kOffset = kOverlay_GrBlendEquation - SkXfermode::kOverlay_Mode }; | |
35 return static_cast<GrBlendEquation>(mode + kOffset); | |
36 | |
37 GR_STATIC_ASSERT(kOverlay_GrBlendEquation == SkXfermode::kOverlay_Mode + kOf fset); | |
38 GR_STATIC_ASSERT(kDarken_GrBlendEquation == SkXfermode::kDarken_Mode + kOffs et); | |
39 GR_STATIC_ASSERT(kLighten_GrBlendEquation == SkXfermode::kLighten_Mode + kOf fset); | |
40 GR_STATIC_ASSERT(kColorDodge_GrBlendEquation == SkXfermode::kColorDodge_Mode + kOffset); | |
41 GR_STATIC_ASSERT(kColorBurn_GrBlendEquation == SkXfermode::kColorBurn_Mode + kOffset); | |
42 GR_STATIC_ASSERT(kHardLight_GrBlendEquation == SkXfermode::kHardLight_Mode + kOffset); | |
43 GR_STATIC_ASSERT(kSoftLight_GrBlendEquation == SkXfermode::kSoftLight_Mode + kOffset); | |
44 GR_STATIC_ASSERT(kDifference_GrBlendEquation == SkXfermode::kDifference_Mode + kOffset); | |
45 GR_STATIC_ASSERT(kExclusion_GrBlendEquation == SkXfermode::kExclusion_Mode + kOffset); | |
46 GR_STATIC_ASSERT(kMultiply_GrBlendEquation == SkXfermode::kMultiply_Mode + k Offset); | |
47 GR_STATIC_ASSERT(kHSLHue_GrBlendEquation == SkXfermode::kHue_Mode + kOffset) ; | |
48 GR_STATIC_ASSERT(kHSLSaturation_GrBlendEquation == SkXfermode::kSaturation_M ode + kOffset); | |
49 GR_STATIC_ASSERT(kHSLColor_GrBlendEquation == SkXfermode::kColor_Mode + kOff set); | |
50 GR_STATIC_ASSERT(kHSLLuminosity_GrBlendEquation == SkXfermode::kLuminosity_M ode + kOffset); | |
51 GR_STATIC_ASSERT(kTotalGrBlendEquationCount == SkXfermode::kLastMode + 1 + k Offset); | |
52 } | |
53 | |
32 static void hard_light(GrGLFragmentBuilder* fsBuilder, | 54 static void hard_light(GrGLFragmentBuilder* fsBuilder, |
33 const char* final, | 55 const char* final, |
34 const char* src, | 56 const char* src, |
35 const char* dst) { | 57 const char* dst) { |
36 static const char kComponents[] = {'r', 'g', 'b'}; | 58 static const char kComponents[] = {'r', 'g', 'b'}; |
37 for (size_t i = 0; i < SK_ARRAY_COUNT(kComponents); ++i) { | 59 for (size_t i = 0; i < SK_ARRAY_COUNT(kComponents); ++i) { |
38 char component = kComponents[i]; | 60 char component = kComponents[i]; |
39 fsBuilder->codeAppendf("if (2.0 * %s.%c <= %s.a) {", src, component, src ); | 61 fsBuilder->codeAppendf("if (2.0 * %s.%c <= %s.a) {", src, component, src ); |
40 fsBuilder->codeAppendf("%s.%c = 2.0 * %s.%c * %s.%c;", | 62 fsBuilder->codeAppendf("%s.%c = 2.0 * %s.%c * %s.%c;", |
41 final, component, src, component, dst, component) ; | 63 final, component, src, component, dst, component) ; |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 | 525 |
504 bool hasSecondaryOutput() const override { return false; } | 526 bool hasSecondaryOutput() const override { return false; } |
505 | 527 |
506 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, | 528 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, |
507 const GrProcOptInfo& coveragePOI, | 529 const GrProcOptInfo& coveragePOI, |
508 bool doesStencilWrite, | 530 bool doesStencilWrite, |
509 GrColor* overrideColor, | 531 GrColor* overrideColor, |
510 const GrDrawTargetCaps& caps) ove rride; | 532 const GrDrawTargetCaps& caps) ove rride; |
511 | 533 |
512 SkXfermode::Mode mode() const { return fMode; } | 534 SkXfermode::Mode mode() const { return fMode; } |
535 bool hasCoverage() const { return fHasCoverage; } | |
536 bool hasHWBlendEquation() const { return kInvalid_GrBlendEquation != fHWBlen dEquation; } | |
537 | |
538 GrBlendEquation hwBlendEquation() const { | |
539 SkASSERT(this->hasHWBlendEquation()); | |
540 return fHWBlendEquation; | |
541 } | |
513 | 542 |
514 private: | 543 private: |
515 CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool wi llReadDstColor); | 544 CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool wi llReadDstColor); |
516 | 545 |
517 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override; | 546 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override; |
518 | 547 |
548 bool onWillNeedXferBarrier(const GrRenderTarget* rt, | |
549 const GrDrawTargetCaps& caps, | |
550 GrXferBarrierType* outBarrierType) const override ; | |
551 | |
552 void onGetBlendInfo(BlendInfo*) const override; | |
553 | |
519 bool onIsEqual(const GrXferProcessor& xpBase) const override; | 554 bool onIsEqual(const GrXferProcessor& xpBase) const override; |
520 | 555 |
521 SkXfermode::Mode fMode; | 556 SkXfermode::Mode fMode; |
557 bool fHasCoverage; | |
558 GrBlendEquation fHWBlendEquation; | |
522 | 559 |
523 typedef GrXferProcessor INHERITED; | 560 typedef GrXferProcessor INHERITED; |
524 }; | 561 }; |
525 | 562 |
526 /////////////////////////////////////////////////////////////////////////////// | 563 /////////////////////////////////////////////////////////////////////////////// |
527 | 564 |
528 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { | 565 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { |
529 if (!GrCustomXfermode::IsSupportedMode(mode)) { | 566 if (!GrCustomXfermode::IsSupportedMode(mode)) { |
530 return NULL; | 567 return NULL; |
531 } else { | 568 } else { |
532 return SkNEW_ARGS(GrCustomXPFactory, (mode)); | 569 return SkNEW_ARGS(GrCustomXPFactory, (mode)); |
533 } | 570 } |
534 } | 571 } |
535 | 572 |
536 /////////////////////////////////////////////////////////////////////////////// | 573 /////////////////////////////////////////////////////////////////////////////// |
537 | 574 |
538 class GLCustomXP : public GrGLXferProcessor { | 575 class GLCustomXP : public GrGLXferProcessor { |
539 public: | 576 public: |
540 GLCustomXP(const GrXferProcessor&) {} | 577 GLCustomXP(const GrXferProcessor&) {} |
541 ~GLCustomXP() override {} | 578 ~GLCustomXP() override {} |
542 | 579 |
543 static void GenKey(const GrXferProcessor& proc, const GrGLSLCaps&, GrProcess orKeyBuilder* b) { | 580 static void GenKey(const GrXferProcessor& p, const GrGLSLCaps& caps, GrProce ssorKeyBuilder* b) { |
544 uint32_t key = proc.numTextures(); | 581 const CustomXP& xp = p.cast<CustomXP>(); |
582 uint32_t key = xp.numTextures(); | |
545 SkASSERT(key <= 1); | 583 SkASSERT(key <= 1); |
546 key |= proc.cast<CustomXP>().mode() << 1; | 584 key |= xp.hasCoverage() << 1; |
585 key |= xp.hasHWBlendEquation() << 2; | |
egdaniel
2015/05/05 21:20:01
I'm trying to think if we can simplify this logic
Chris Dalton
2015/05/06 16:06:27
Good idea. I like it a lot better now.
| |
586 if (xp.hasHWBlendEquation()) { | |
587 key |= caps.advancedBlendEqnInteraction() << 3; | |
588 if (GrGLSLCaps::kMustEnableSeparately_AdvancedBlendEqnInteraction == | |
589 caps.advancedBlendEqnInteraction()) { | |
590 GR_STATIC_ASSERT(GrGLSLCaps::kLast_AdvancedBlendEqnInteraction < = 3); | |
591 key |= xp.hwBlendEquation() << 5; | |
592 } | |
593 } else { | |
594 key |= xp.mode() << 3; | |
595 } | |
547 b->add32(key); | 596 b->add32(key); |
548 } | 597 } |
549 | 598 |
550 private: | 599 private: |
551 void onEmitCode(const EmitArgs& args) override { | 600 void onEmitCode(const EmitArgs& args) override { |
552 SkXfermode::Mode mode = args.fXP.cast<CustomXP>().mode(); | 601 const CustomXP& xp = args.fXP.cast<CustomXP>(); |
553 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 602 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
554 const char* dstColor = fsBuilder->dstColor(); | |
555 | 603 |
556 emit_custom_xfermode_code(mode, fsBuilder, args.fOutputPrimary, args.fIn putColor, dstColor); | 604 if (xp.hasHWBlendEquation()) { |
557 | 605 // The blend mode will be implemented in hardware; only output the s rc color. |
558 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", | 606 fsBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation()) ; |
559 args.fOutputPrimary, args.fOutputPrimary, args.fI nputCoverage, | 607 if (xp.hasCoverage()) { |
560 args.fInputCoverage, dstColor); | 608 // Do coverage modulation by multiplying it into the src color b efore blending. |
609 // (See getOptimizations()) | |
610 fsBuilder->codeAppendf("%s = %s * %s;", | |
611 args.fOutputPrimary, args.fInputCoverage, args.fInputColor); | |
612 } else { | |
613 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fIn putColor); | |
614 } | |
615 } else { | |
616 const char* dstColor = fsBuilder->dstColor(); | |
617 emit_custom_xfermode_code(xp.mode(), fsBuilder, args.fOutputPrimary, args.fInputColor, | |
618 dstColor); | |
619 if (xp.hasCoverage()) { | |
620 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", | |
621 args.fOutputPrimary, args.fOutputPrimary, | |
622 args.fInputCoverage, args.fInputCoverage, dstColor); | |
623 } | |
624 } | |
561 } | 625 } |
562 | 626 |
563 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri de {} | 627 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri de {} |
564 | 628 |
565 typedef GrGLFragmentProcessor INHERITED; | 629 typedef GrGLFragmentProcessor INHERITED; |
566 }; | 630 }; |
567 | 631 |
568 /////////////////////////////////////////////////////////////////////////////// | 632 /////////////////////////////////////////////////////////////////////////////// |
569 | 633 |
570 CustomXP::CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, | 634 CustomXP::CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, |
571 bool willReadDstColor) | 635 bool willReadDstColor) |
572 : INHERITED(dstCopy, willReadDstColor), fMode(mode) { | 636 : INHERITED(dstCopy, willReadDstColor), |
637 fMode(mode), | |
638 fHasCoverage(true), | |
639 fHWBlendEquation(kInvalid_GrBlendEquation) { | |
573 this->initClassID<CustomXP>(); | 640 this->initClassID<CustomXP>(); |
574 } | 641 } |
575 | 642 |
576 void CustomXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder * b) const { | 643 void CustomXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder * b) const { |
577 GLCustomXP::GenKey(*this, caps, b); | 644 GLCustomXP::GenKey(*this, caps, b); |
578 } | 645 } |
579 | 646 |
580 GrGLXferProcessor* CustomXP::createGLInstance() const { | 647 GrGLXferProcessor* CustomXP::createGLInstance() const { |
648 SkASSERT(this->willReadDstColor() != this->hasHWBlendEquation()); | |
581 return SkNEW_ARGS(GLCustomXP, (*this)); | 649 return SkNEW_ARGS(GLCustomXP, (*this)); |
582 } | 650 } |
583 | 651 |
584 bool CustomXP::onIsEqual(const GrXferProcessor& other) const { | 652 bool CustomXP::onIsEqual(const GrXferProcessor& other) const { |
585 const CustomXP& s = other.cast<CustomXP>(); | 653 const CustomXP& s = other.cast<CustomXP>(); |
586 return fMode == s.fMode; | 654 return fMode == s.fMode && |
655 fHasCoverage == s.fHasCoverage && | |
656 fHWBlendEquation == s.fHWBlendEquation; | |
587 } | 657 } |
588 | 658 |
589 GrXferProcessor::OptFlags CustomXP::getOptimizations(const GrProcOptInfo& colorP OI, | 659 GrXferProcessor::OptFlags CustomXP::getOptimizations(const GrProcOptInfo& colorP OI, |
590 const GrProcOptInfo& cove ragePOI, | 660 const GrProcOptInfo& cove ragePOI, |
591 bool doesStencilWrite, | 661 bool doesStencilWrite, |
592 GrColor* overrideColor, | 662 GrColor* overrideColor, |
593 const GrDrawTargetCaps& c aps) { | 663 const GrDrawTargetCaps& c aps) { |
594 return GrXferProcessor::kNone_Opt; | 664 /* |
665 Most the optimizations we do here are based on tweaking alpha for coverage. | |
666 | |
667 The general SVG blend equation is defined in the spec as follows: | |
668 | |
669 Dca' = B(Sc, Dc) * Sa * Da + Y * Sca * (1-Da) + Z * Dca * (1-Sa) | |
670 Da' = X * Sa * Da + Y * Sa * (1-Da) + Z * Da * (1-Sa) | |
671 | |
672 (Note that Sca, Dca indicate RGB vectors that are premultiplied by alpha, | |
673 and that B(Sc, Dc) is a mode-specific function that accepts non-multiplied | |
674 RGB colors.) | |
675 | |
676 For every blend mode supported by this class, i.e. the "advanced" blend | |
677 modes, X=Y=Z=1 and this equation reduces to the PDF blend equation. | |
678 | |
679 It can be shown that when X=Y=Z=1, these equations can modulate alpha for | |
680 coverage. | |
681 | |
682 | |
683 == Color == | |
684 | |
685 We substitute Y=Z=1 and define a blend() function that calculates Dca' in | |
686 terms of premultiplied alpha only: | |
687 | |
688 blend(Sca, Dca, Sa, Da) = {Dca : if Sa == 0, | |
689 Sca : if Da == 0, | |
690 B(Sca/Sa, Dca/Da) * Sa * Da + Sca * (1-Da) + Dc a * (1-Sa) : if Sa,Da != 0} | |
691 | |
692 And for coverage modulation, we use a post blend src-over model: | |
693 | |
694 Dca'' = f * blend(Sca, Dca, Sa, Da) + (1-f) * Dca | |
695 | |
696 (Where f is the fractional coverage.) | |
697 | |
698 Next we show that canTweakAlphaForCoverage() is true by proving the | |
699 following relationship: | |
700 | |
701 blend(f*Sca, Dca, f*Sa, Da) == f * blend(Sca, Dca, Sa, Da) + (1-f) * Dca | |
702 | |
703 General case (f,Sa,Da != 0): | |
704 | |
705 f * blend(Sca, Dca, Sa, Da) + (1-f) * Dca | |
706 = f * (B(Sca/Sa, Dca/Da) * Sa * Da + Sca * (1-Da) + Dca * (1-Sa)) + (1-f ) * Dca [Sa,Da != 0, definition of blend()] | |
707 = B(Sca/Sa, Dca/Da) * f*Sa * Da + f*Sca * (1-Da) + f*Dca * (1-Sa) + Dca - f*Dca | |
708 = B(Sca/Sa, Dca/Da) * f*Sa * Da + f*Sca - f*Sca * Da + f*Dca - f*Dca * S a + Dca - f*Dca | |
709 = B(Sca/Sa, Dca/Da) * f*Sa * Da + f*Sca - f*Sca * Da - f*Dca * Sa + Dca | |
710 = B(Sca/Sa, Dca/Da) * f*Sa * Da + f*Sca * (1-Da) - f*Dca * Sa + Dca | |
711 = B(Sca/Sa, Dca/Da) * f*Sa * Da + f*Sca * (1-Da) + Dca * (1 - f*Sa) | |
712 = B(f*Sca/f*Sa, Dca/Da) * f*Sa * Da + f*Sca * (1-Da) + Dca * (1 - f*Sa) [f!=0] | |
713 = blend(f*Sca, Dca, f*Sa, Da) [definition of blend()] | |
714 | |
715 Corner cases (Sa=0, Da=0, and f=0): | |
716 | |
717 Sa=0: f * blend(Sca, Dca, Sa, Da) + (1-f) * Dca | |
718 = f * Dca + (1-f) * Dca [Sa=0, definition of blend()] | |
719 = Dca | |
720 = blend(0, Dca, 0, Da) [definition of blend()] | |
721 = blend(f*Sca, Dca, f*Sa, Da) [Sa=0] | |
722 | |
723 Da=0: f * blend(Sca, Dca, Sa, Da) + (1-f) * Dca | |
724 = f * Sca + (1-f) * Dca [Da=0, definition of blend()] | |
725 = f * Sca [Da=0] | |
726 = blend(f*Sca, 0, f*Sa, 0) [definition of blend()] | |
727 = blend(f*Sca, Dca, f*Sa, Da) [Da=0] | |
728 | |
729 f=0: f * blend(Sca, Dca, Sa, Da) + (1-f) * Dca | |
730 = Dca [f=0] | |
731 = blend(0, Dca, 0, Da) [definition of blend()] | |
732 = blend(f*Sca, Dca, f*Sa, Da) [f=0] | |
733 | |
734 == Alpha == | |
735 | |
736 We substitute X=Y=Z=1 and define a blend() function that calculates Da': | |
737 | |
738 blend(Sa, Da) = Sa * Da + Sa * (1-Da) + Da * (1-Sa) | |
739 = Sa * Da + Sa - Sa * Da + Da - Da * Sa | |
740 = Sa + Da - Sa * Da | |
741 | |
742 We use the same model for coverage modulation as we did with color: | |
743 | |
744 Da'' = f * blend(Sa, Da) + (1-f) * Da | |
745 | |
746 And show that canTweakAlphaForCoverage() is true by proving the following | |
747 relationship: | |
748 | |
749 blend(f*Sa, Da) == f * blend(Sa, Da) + (1-f) * Da | |
750 | |
751 | |
752 f * blend(Sa, Da) + (1-f) * Da | |
753 = f * (Sa + Da - Sa * Da) + (1-f) * Da | |
754 = f*Sa + f*Da - f*Sa * Da + Da - f*Da | |
755 = f*Sa - f*Sa * Da + Da | |
756 = f*Sa + Da - f*Sa * Da | |
757 = blend(f*Sa, Da) | |
758 */ | |
759 | |
760 OptFlags flags = kNone_Opt; | |
761 if (colorPOI.allStagesMultiplyInput()) { | |
762 flags = flags | kCanTweakAlphaForCoverage_OptFlag; | |
763 } | |
764 if (coveragePOI.isSolidWhite()) { | |
765 flags = flags | kIgnoreCoverage_OptFlag; | |
766 fHasCoverage = false; | |
767 } | |
768 if (caps.advancedBlendEquationSupport() && !coveragePOI.isFourChannelOutput( )) { | |
769 // This blend mode can be implemented in hardware. | |
770 fHWBlendEquation = hw_blend_equation(fMode); | |
771 } | |
772 return flags; | |
773 } | |
774 | |
775 bool CustomXP::onWillNeedXferBarrier(const GrRenderTarget* rt, | |
776 const GrDrawTargetCaps& caps, | |
777 GrXferBarrierType* outBarrierType) const { | |
778 if (this->hasHWBlendEquation() && | |
779 GrDrawTargetCaps::kAdvancedCoherent_BlendEquationSupport != caps.blendEq uationSupport()) { | |
780 *outBarrierType = kBlend_GrXferBarrierType; | |
781 return true; | |
782 } | |
783 return false; | |
784 } | |
785 | |
786 void CustomXP::onGetBlendInfo(BlendInfo* blendInfo) const { | |
787 if (this->hasHWBlendEquation()) { | |
788 blendInfo->fEquation = this->hwBlendEquation(); | |
789 } | |
595 } | 790 } |
596 | 791 |
597 /////////////////////////////////////////////////////////////////////////////// | 792 /////////////////////////////////////////////////////////////////////////////// |
598 | 793 |
599 GrCustomXPFactory::GrCustomXPFactory(SkXfermode::Mode mode) | 794 GrCustomXPFactory::GrCustomXPFactory(SkXfermode::Mode mode) |
600 : fMode(mode) { | 795 : fMode(mode) { |
601 this->initClassID<GrCustomXPFactory>(); | 796 this->initClassID<GrCustomXPFactory>(); |
602 } | 797 } |
603 | 798 |
604 GrXferProcessor* | 799 GrXferProcessor* |
605 GrCustomXPFactory::onCreateXferProcessor(const GrDrawTargetCaps& caps, | 800 GrCustomXPFactory::onCreateXferProcessor(const GrDrawTargetCaps& caps, |
606 const GrProcOptInfo& colorPOI, | 801 const GrProcOptInfo& colorPOI, |
607 const GrProcOptInfo& coveragePOI, | 802 const GrProcOptInfo& coveragePOI, |
608 const GrDeviceCoordTexture* dstCopy) co nst { | 803 const GrDeviceCoordTexture* dstCopy) co nst { |
609 return CustomXP::Create(fMode, dstCopy, this->willReadDstColor(caps, colorPO I, coveragePOI)); | 804 return CustomXP::Create(fMode, dstCopy, this->willReadDstColor(caps, colorPO I, coveragePOI)); |
610 } | 805 } |
611 | 806 |
807 bool GrCustomXPFactory::willReadDstColor(const GrDrawTargetCaps& caps, | |
808 const GrProcOptInfo& colorPOI, | |
809 const GrProcOptInfo& coveragePOI) const { | |
810 if (!caps.advancedBlendEquationSupport()) { | |
811 // No hardware support for advanced blend equations; we will need to do it in the shader. | |
812 return true; | |
813 } | |
814 if (coveragePOI.isFourChannelOutput()) { | |
815 // Advanced blend equations can't tweak alpha for RGB coverage. | |
816 return true; | |
817 } | |
818 return false; | |
819 } | |
612 | 820 |
613 void GrCustomXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, | 821 void GrCustomXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, |
614 const GrProcOptInfo& coveragePOI, | 822 const GrProcOptInfo& coveragePOI, |
615 GrXPFactory::InvariantOutput* out put) const { | 823 GrXPFactory::InvariantOutput* out put) const { |
616 output->fWillBlendWithDst = true; | 824 output->fWillBlendWithDst = true; |
617 output->fBlendedColorFlags = 0; | 825 output->fBlendedColorFlags = 0; |
618 } | 826 } |
619 | 827 |
620 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); | 828 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); |
621 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, | 829 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, |
622 GrContext*, | 830 GrContext*, |
623 const GrDrawTargetCaps&, | 831 const GrDrawTargetCaps&, |
624 GrTexture*[]) { | 832 GrTexture*[]) { |
625 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas tSeparableMode); | 833 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas tSeparableMode); |
626 | 834 |
627 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); | 835 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); |
628 } | 836 } |
629 | 837 |
OLD | NEW |