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" |
11 #include "GrCaps.h" | 11 #include "GrCaps.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
14 #include "GrTypes.h" | 14 #include "GrTypes.h" |
15 #include "GrXferProcessor.h" | 15 #include "GrXferProcessor.h" |
16 #include "gl/GrGLXferProcessor.h" | |
17 #include "glsl/GrGLSLBlend.h" | 16 #include "glsl/GrGLSLBlend.h" |
18 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 17 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
19 #include "glsl/GrGLSLProgramBuilder.h" | 18 #include "glsl/GrGLSLProgramBuilder.h" |
20 #include "glsl/GrGLSLProgramDataManager.h" | 19 #include "glsl/GrGLSLProgramDataManager.h" |
| 20 #include "glsl/GrGLSLXferProcessor.h" |
21 | 21 |
22 /** | 22 /** |
23 * Wraps the shader outputs and HW blend state that comprise a Porter Duff blend
mode with coverage. | 23 * Wraps the shader outputs and HW blend state that comprise a Porter Duff blend
mode with coverage. |
24 */ | 24 */ |
25 struct BlendFormula { | 25 struct BlendFormula { |
26 public: | 26 public: |
27 /** | 27 /** |
28 * Values the shader can write to primary and secondary outputs. These must
all be modulated by | 28 * Values the shader can write to primary and secondary outputs. These must
all be modulated by |
29 * coverage to support mixed samples. The XP will ignore the multiplies when
not using coverage. | 29 * coverage to support mixed samples. The XP will ignore the multiplies when
not using coverage. |
30 */ | 30 */ |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 /////////////////////////////////////////////////////////////////////////////// | 340 /////////////////////////////////////////////////////////////////////////////// |
341 | 341 |
342 class PorterDuffXferProcessor : public GrXferProcessor { | 342 class PorterDuffXferProcessor : public GrXferProcessor { |
343 public: | 343 public: |
344 PorterDuffXferProcessor(BlendFormula blendFormula) : fBlendFormula(blendForm
ula) { | 344 PorterDuffXferProcessor(BlendFormula blendFormula) : fBlendFormula(blendForm
ula) { |
345 this->initClassID<PorterDuffXferProcessor>(); | 345 this->initClassID<PorterDuffXferProcessor>(); |
346 } | 346 } |
347 | 347 |
348 const char* name() const override { return "Porter Duff"; } | 348 const char* name() const override { return "Porter Duff"; } |
349 | 349 |
350 GrGLXferProcessor* createGLInstance() const override; | 350 GrGLSLXferProcessor* createGLInstance() const override; |
351 | 351 |
352 BlendFormula getBlendFormula() const { return fBlendFormula; } | 352 BlendFormula getBlendFormula() const { return fBlendFormula; } |
353 | 353 |
354 private: | 354 private: |
355 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 355 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
356 const GrProcOptInfo& coveragePO
I, | 356 const GrProcOptInfo& coveragePO
I, |
357 bool doesStencilWrite, | 357 bool doesStencilWrite, |
358 GrColor* overrideColor, | 358 GrColor* overrideColor, |
359 const GrCaps& caps) override; | 359 const GrCaps& caps) override; |
360 | 360 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } else { | 421 } else { |
422 fsBuilder->codeAppendf("%s = vec4(1.0) - %s;", output, inColor); | 422 fsBuilder->codeAppendf("%s = vec4(1.0) - %s;", output, inColor); |
423 } | 423 } |
424 break; | 424 break; |
425 default: | 425 default: |
426 SkFAIL("Unsupported output type."); | 426 SkFAIL("Unsupported output type."); |
427 break; | 427 break; |
428 } | 428 } |
429 } | 429 } |
430 | 430 |
431 class GLPorterDuffXferProcessor : public GrGLXferProcessor { | 431 class GLPorterDuffXferProcessor : public GrGLSLXferProcessor { |
432 public: | 432 public: |
433 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { | 433 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { |
434 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); | 434 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); |
435 b->add32(SkToInt(xp.readsCoverage()) | | 435 b->add32(SkToInt(xp.readsCoverage()) | |
436 (xp.getBlendFormula().fPrimaryOutputType << 1) | | 436 (xp.getBlendFormula().fPrimaryOutputType << 1) | |
437 (xp.getBlendFormula().fSecondaryOutputType << 4)); | 437 (xp.getBlendFormula().fSecondaryOutputType << 4)); |
438 GR_STATIC_ASSERT(BlendFormula::kLast_OutputType < 8); | 438 GR_STATIC_ASSERT(BlendFormula::kLast_OutputType < 8); |
439 }; | 439 }; |
440 | 440 |
441 private: | 441 private: |
442 void emitOutputsForBlendState(const EmitArgs& args) override { | 442 void emitOutputsForBlendState(const EmitArgs& args) override { |
443 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); | 443 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); |
444 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 444 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
445 | 445 |
446 BlendFormula blendFormula = xp.getBlendFormula(); | 446 BlendFormula blendFormula = xp.getBlendFormula(); |
447 if (blendFormula.hasSecondaryOutput()) { | 447 if (blendFormula.hasSecondaryOutput()) { |
448 append_color_output(xp, fsBuilder, blendFormula.fSecondaryOutputType
, | 448 append_color_output(xp, fsBuilder, blendFormula.fSecondaryOutputType
, |
449 args.fOutputSecondary, args.fInputColor, args.fI
nputCoverage); | 449 args.fOutputSecondary, args.fInputColor, args.fI
nputCoverage); |
450 } | 450 } |
451 append_color_output(xp, fsBuilder, blendFormula.fPrimaryOutputType, | 451 append_color_output(xp, fsBuilder, blendFormula.fPrimaryOutputType, |
452 args.fOutputPrimary, args.fInputColor, args.fInputCo
verage); | 452 args.fOutputPrimary, args.fInputColor, args.fInputCo
verage); |
453 } | 453 } |
454 | 454 |
455 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} | 455 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} |
456 | 456 |
457 typedef GrGLXferProcessor INHERITED; | 457 typedef GrGLSLXferProcessor INHERITED; |
458 }; | 458 }; |
459 | 459 |
460 /////////////////////////////////////////////////////////////////////////////// | 460 /////////////////////////////////////////////////////////////////////////////// |
461 | 461 |
462 void PorterDuffXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, | 462 void PorterDuffXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, |
463 GrProcessorKeyBuilder* b) cons
t { | 463 GrProcessorKeyBuilder* b) cons
t { |
464 GLPorterDuffXferProcessor::GenKey(*this, b); | 464 GLPorterDuffXferProcessor::GenKey(*this, b); |
465 } | 465 } |
466 | 466 |
467 GrGLXferProcessor* PorterDuffXferProcessor::createGLInstance() const { | 467 GrGLSLXferProcessor* PorterDuffXferProcessor::createGLInstance() const { |
468 return new GLPorterDuffXferProcessor; | 468 return new GLPorterDuffXferProcessor; |
469 } | 469 } |
470 | 470 |
471 GrXferProcessor::OptFlags | 471 GrXferProcessor::OptFlags |
472 PorterDuffXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, | 472 PorterDuffXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, |
473 const GrProcOptInfo& coveragePOI, | 473 const GrProcOptInfo& coveragePOI, |
474 bool doesStencilWrite, | 474 bool doesStencilWrite, |
475 GrColor* overrideColor, | 475 GrColor* overrideColor, |
476 const GrCaps& caps) { | 476 const GrCaps& caps) { |
477 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; | 477 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; |
(...skipping 27 matching lines...) Expand all Loading... |
505 ShaderPDXferProcessor(const DstTexture* dstTexture, | 505 ShaderPDXferProcessor(const DstTexture* dstTexture, |
506 bool hasMixedSamples, | 506 bool hasMixedSamples, |
507 SkXfermode::Mode xfermode) | 507 SkXfermode::Mode xfermode) |
508 : INHERITED(dstTexture, true, hasMixedSamples) | 508 : INHERITED(dstTexture, true, hasMixedSamples) |
509 , fXfermode(xfermode) { | 509 , fXfermode(xfermode) { |
510 this->initClassID<ShaderPDXferProcessor>(); | 510 this->initClassID<ShaderPDXferProcessor>(); |
511 } | 511 } |
512 | 512 |
513 const char* name() const override { return "Porter Duff Shader"; } | 513 const char* name() const override { return "Porter Duff Shader"; } |
514 | 514 |
515 GrGLXferProcessor* createGLInstance() const override; | 515 GrGLSLXferProcessor* createGLInstance() const override; |
516 | 516 |
517 SkXfermode::Mode getXfermode() const { return fXfermode; } | 517 SkXfermode::Mode getXfermode() const { return fXfermode; } |
518 | 518 |
519 private: | 519 private: |
520 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo&, const GrP
rocOptInfo&, | 520 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo&, const GrP
rocOptInfo&, |
521 bool, GrColor*, const GrCaps&)
override { | 521 bool, GrColor*, const GrCaps&)
override { |
522 return kNone_OptFlags; | 522 return kNone_OptFlags; |
523 } | 523 } |
524 | 524 |
525 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 525 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
526 | 526 |
527 bool onIsEqual(const GrXferProcessor& xpBase) const override { | 527 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
528 const ShaderPDXferProcessor& xp = xpBase.cast<ShaderPDXferProcessor>(); | 528 const ShaderPDXferProcessor& xp = xpBase.cast<ShaderPDXferProcessor>(); |
529 return fXfermode == xp.fXfermode; | 529 return fXfermode == xp.fXfermode; |
530 } | 530 } |
531 | 531 |
532 const SkXfermode::Mode fXfermode; | 532 const SkXfermode::Mode fXfermode; |
533 | 533 |
534 typedef GrXferProcessor INHERITED; | 534 typedef GrXferProcessor INHERITED; |
535 }; | 535 }; |
536 | 536 |
537 /////////////////////////////////////////////////////////////////////////////// | 537 /////////////////////////////////////////////////////////////////////////////// |
538 | 538 |
539 class GLShaderPDXferProcessor : public GrGLXferProcessor { | 539 class GLShaderPDXferProcessor : public GrGLSLXferProcessor { |
540 public: | 540 public: |
541 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { | 541 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { |
542 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>(
); | 542 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>(
); |
543 b->add32(xp.getXfermode()); | 543 b->add32(xp.getXfermode()); |
544 } | 544 } |
545 | 545 |
546 private: | 546 private: |
547 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, cons
t char* dstColor, | 547 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, cons
t char* dstColor, |
548 const char* outColor, const GrXferProcessor& pr
oc) override { | 548 const char* outColor, const GrXferProcessor& pr
oc) override { |
549 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); | 549 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); |
550 GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 550 GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
551 | 551 |
552 GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.getX
fermode()); | 552 GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.getX
fermode()); |
553 } | 553 } |
554 | 554 |
555 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} | 555 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} |
556 | 556 |
557 typedef GrGLXferProcessor INHERITED; | 557 typedef GrGLSLXferProcessor INHERITED; |
558 }; | 558 }; |
559 | 559 |
560 /////////////////////////////////////////////////////////////////////////////// | 560 /////////////////////////////////////////////////////////////////////////////// |
561 | 561 |
562 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, | 562 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, |
563 GrProcessorKeyBuilder* b) const
{ | 563 GrProcessorKeyBuilder* b) const
{ |
564 GLShaderPDXferProcessor::GenKey(*this, b); | 564 GLShaderPDXferProcessor::GenKey(*this, b); |
565 } | 565 } |
566 | 566 |
567 GrGLXferProcessor* ShaderPDXferProcessor::createGLInstance() const { | 567 GrGLSLXferProcessor* ShaderPDXferProcessor::createGLInstance() const { |
568 return new GLShaderPDXferProcessor; | 568 return new GLShaderPDXferProcessor; |
569 } | 569 } |
570 | 570 |
571 /////////////////////////////////////////////////////////////////////////////// | 571 /////////////////////////////////////////////////////////////////////////////// |
572 | 572 |
573 class PDLCDXferProcessor : public GrXferProcessor { | 573 class PDLCDXferProcessor : public GrXferProcessor { |
574 public: | 574 public: |
575 static GrXferProcessor* Create(SkXfermode::Mode xfermode, const GrProcOptInf
o& colorPOI); | 575 static GrXferProcessor* Create(SkXfermode::Mode xfermode, const GrProcOptInf
o& colorPOI); |
576 | 576 |
577 ~PDLCDXferProcessor() override; | 577 ~PDLCDXferProcessor() override; |
578 | 578 |
579 const char* name() const override { return "Porter Duff LCD"; } | 579 const char* name() const override { return "Porter Duff LCD"; } |
580 | 580 |
581 GrGLXferProcessor* createGLInstance() const override; | 581 GrGLSLXferProcessor* createGLInstance() const override; |
582 | 582 |
583 private: | 583 private: |
584 PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha); | 584 PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha); |
585 | 585 |
586 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 586 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
587 const GrProcOptInfo& coveragePO
I, | 587 const GrProcOptInfo& coveragePO
I, |
588 bool doesStencilWrite, | 588 bool doesStencilWrite, |
589 GrColor* overrideColor, | 589 GrColor* overrideColor, |
590 const GrCaps& caps) override; | 590 const GrCaps& caps) override; |
591 | 591 |
(...skipping 15 matching lines...) Expand all Loading... |
607 } | 607 } |
608 | 608 |
609 GrColor fBlendConstant; | 609 GrColor fBlendConstant; |
610 uint8_t fAlpha; | 610 uint8_t fAlpha; |
611 | 611 |
612 typedef GrXferProcessor INHERITED; | 612 typedef GrXferProcessor INHERITED; |
613 }; | 613 }; |
614 | 614 |
615 /////////////////////////////////////////////////////////////////////////////// | 615 /////////////////////////////////////////////////////////////////////////////// |
616 | 616 |
617 class GLPDLCDXferProcessor : public GrGLXferProcessor { | 617 class GLPDLCDXferProcessor : public GrGLSLXferProcessor { |
618 public: | 618 public: |
619 GLPDLCDXferProcessor(const GrProcessor&) {} | 619 GLPDLCDXferProcessor(const GrProcessor&) {} |
620 | 620 |
621 virtual ~GLPDLCDXferProcessor() {} | 621 virtual ~GLPDLCDXferProcessor() {} |
622 | 622 |
623 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, | 623 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
624 GrProcessorKeyBuilder* b) {} | 624 GrProcessorKeyBuilder* b) {} |
625 | 625 |
626 private: | 626 private: |
627 void emitOutputsForBlendState(const EmitArgs& args) override { | 627 void emitOutputsForBlendState(const EmitArgs& args) override { |
628 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 628 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
629 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, | 629 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, |
630 args.fInputCoverage); | 630 args.fInputCoverage); |
631 } | 631 } |
632 | 632 |
633 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {}; | 633 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {}; |
634 | 634 |
635 typedef GrGLXferProcessor INHERITED; | 635 typedef GrGLSLXferProcessor INHERITED; |
636 }; | 636 }; |
637 | 637 |
638 /////////////////////////////////////////////////////////////////////////////// | 638 /////////////////////////////////////////////////////////////////////////////// |
639 | 639 |
640 PDLCDXferProcessor::PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha) | 640 PDLCDXferProcessor::PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha) |
641 : fBlendConstant(blendConstant) | 641 : fBlendConstant(blendConstant) |
642 , fAlpha(alpha) { | 642 , fAlpha(alpha) { |
643 this->initClassID<PDLCDXferProcessor>(); | 643 this->initClassID<PDLCDXferProcessor>(); |
644 } | 644 } |
645 | 645 |
(...skipping 15 matching lines...) Expand all Loading... |
661 } | 661 } |
662 | 662 |
663 PDLCDXferProcessor::~PDLCDXferProcessor() { | 663 PDLCDXferProcessor::~PDLCDXferProcessor() { |
664 } | 664 } |
665 | 665 |
666 void PDLCDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps& caps, | 666 void PDLCDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps& caps, |
667 GrProcessorKeyBuilder* b) const { | 667 GrProcessorKeyBuilder* b) const { |
668 GLPDLCDXferProcessor::GenKey(*this, caps, b); | 668 GLPDLCDXferProcessor::GenKey(*this, caps, b); |
669 } | 669 } |
670 | 670 |
671 GrGLXferProcessor* PDLCDXferProcessor::createGLInstance() const { | 671 GrGLSLXferProcessor* PDLCDXferProcessor::createGLInstance() const { |
672 return new GLPDLCDXferProcessor(*this); | 672 return new GLPDLCDXferProcessor(*this); |
673 } | 673 } |
674 | 674 |
675 GrXferProcessor::OptFlags | 675 GrXferProcessor::OptFlags |
676 PDLCDXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, | 676 PDLCDXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, |
677 const GrProcOptInfo& coveragePOI, | 677 const GrProcOptInfo& coveragePOI, |
678 bool doesStencilWrite, | 678 bool doesStencilWrite, |
679 GrColor* overrideColor, | 679 GrColor* overrideColor, |
680 const GrCaps& caps) { | 680 const GrCaps& caps) { |
681 // We want to force our primary output to be alpha * Coverage, where alp
ha is the alpha | 681 // We want to force our primary output to be alpha * Coverage, where alp
ha is the alpha |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 int* outPrimary, | 820 int* outPrimary, |
821 int* outSecondary) { | 821 int* outSecondary) { |
822 if (!!strcmp(xp->name(), "Porter Duff")) { | 822 if (!!strcmp(xp->name(), "Porter Duff")) { |
823 *outPrimary = *outSecondary = -1; | 823 *outPrimary = *outSecondary = -1; |
824 return; | 824 return; |
825 } | 825 } |
826 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); | 826 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); |
827 *outPrimary = blendFormula.fPrimaryOutputType; | 827 *outPrimary = blendFormula.fPrimaryOutputType; |
828 *outSecondary = blendFormula.fSecondaryOutputType; | 828 *outSecondary = blendFormula.fSecondaryOutputType; |
829 } | 829 } |
OLD | NEW |