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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 299 |
300 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// |
301 | 301 |
302 class PorterDuffXferProcessor : public GrXferProcessor { | 302 class PorterDuffXferProcessor : public GrXferProcessor { |
303 public: | 303 public: |
304 static GrXferProcessor* Create(BlendFormula blendFormula) { | 304 static GrXferProcessor* Create(BlendFormula blendFormula) { |
305 return SkNEW_ARGS(PorterDuffXferProcessor, (blendFormula)); | 305 return SkNEW_ARGS(PorterDuffXferProcessor, (blendFormula)); |
306 } | 306 } |
307 | 307 |
308 const char* name() const override { return "Porter Duff"; } | 308 const char* name() const override { return "Porter Duff"; } |
309 bool hasSecondaryOutput() const override { return fBlendFormula.hasSecondary
Output(); } | |
310 | 309 |
311 GrGLXferProcessor* createGLInstance() const override; | 310 GrGLXferProcessor* createGLInstance() const override; |
312 | 311 |
313 BlendFormula getBlendFormula() const { return fBlendFormula; } | 312 BlendFormula getBlendFormula() const { return fBlendFormula; } |
314 | 313 |
315 private: | 314 private: |
316 PorterDuffXferProcessor(BlendFormula blendFormula) : fBlendFormula(blendForm
ula) { | 315 PorterDuffXferProcessor(BlendFormula blendFormula) : fBlendFormula(blendForm
ula) { |
317 this->initClassID<PorterDuffXferProcessor>(); | 316 this->initClassID<PorterDuffXferProcessor>(); |
318 } | 317 } |
319 | 318 |
320 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 319 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
321 const GrProcOptInfo& coveragePO
I, | 320 const GrProcOptInfo& coveragePO
I, |
322 bool doesStencilWrite, | 321 bool doesStencilWrite, |
323 GrColor* overrideColor, | 322 GrColor* overrideColor, |
324 const GrCaps& caps) override; | 323 const GrCaps& caps) override; |
325 | 324 |
326 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 325 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
327 | 326 |
| 327 bool onHasSecondaryOutput() const override { return fBlendFormula.hasSeconda
ryOutput(); } |
| 328 |
328 void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { | 329 void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { |
329 blendInfo->fEquation = fBlendFormula.fBlendEquation; | 330 blendInfo->fEquation = fBlendFormula.fBlendEquation; |
330 blendInfo->fSrcBlend = fBlendFormula.fSrcCoeff; | 331 blendInfo->fSrcBlend = fBlendFormula.fSrcCoeff; |
331 blendInfo->fDstBlend = fBlendFormula.fDstCoeff; | 332 blendInfo->fDstBlend = fBlendFormula.fDstCoeff; |
332 blendInfo->fWriteColor = fBlendFormula.modifiesDst(); | 333 blendInfo->fWriteColor = fBlendFormula.modifiesDst(); |
333 } | 334 } |
334 | 335 |
335 bool onIsEqual(const GrXferProcessor& xpBase) const override { | 336 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
336 const PorterDuffXferProcessor& xp = xpBase.cast<PorterDuffXferProcessor>
(); | 337 const PorterDuffXferProcessor& xp = xpBase.cast<PorterDuffXferProcessor>
(); |
337 return fBlendFormula == xp.fBlendFormula; | 338 return fBlendFormula == xp.fBlendFormula; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 public: | 387 public: |
387 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { | 388 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { |
388 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); | 389 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); |
389 b->add32(SkToInt(xp.readsCoverage()) | | 390 b->add32(SkToInt(xp.readsCoverage()) | |
390 (xp.getBlendFormula().fPrimaryOutputType << 1) | | 391 (xp.getBlendFormula().fPrimaryOutputType << 1) | |
391 (xp.getBlendFormula().fSecondaryOutputType << 4)); | 392 (xp.getBlendFormula().fSecondaryOutputType << 4)); |
392 GR_STATIC_ASSERT(BlendFormula::kLast_OutputType < 8); | 393 GR_STATIC_ASSERT(BlendFormula::kLast_OutputType < 8); |
393 }; | 394 }; |
394 | 395 |
395 private: | 396 private: |
396 void onEmitCode(const EmitArgs& args) override { | 397 void emitOutputsForBlendState(const EmitArgs& args) override { |
397 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); | 398 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); |
398 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 399 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
399 | 400 |
400 BlendFormula blendFormula = xp.getBlendFormula(); | 401 BlendFormula blendFormula = xp.getBlendFormula(); |
401 if (blendFormula.hasSecondaryOutput()) { | 402 if (blendFormula.hasSecondaryOutput()) { |
402 append_color_output(xp, fsBuilder, blendFormula.fSecondaryOutputType
, | 403 append_color_output(xp, fsBuilder, blendFormula.fSecondaryOutputType
, |
403 args.fOutputSecondary, args.fInputColor, args.fI
nputCoverage); | 404 args.fOutputSecondary, args.fInputColor, args.fI
nputCoverage); |
404 } | 405 } |
405 append_color_output(xp, fsBuilder, blendFormula.fPrimaryOutputType, | 406 append_color_output(xp, fsBuilder, blendFormula.fPrimaryOutputType, |
406 args.fOutputPrimary, args.fInputColor, args.fInputCo
verage); | 407 args.fOutputPrimary, args.fInputColor, args.fInputCo
verage); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 453 |
453 /////////////////////////////////////////////////////////////////////////////// | 454 /////////////////////////////////////////////////////////////////////////////// |
454 | 455 |
455 class ShaderPDXferProcessor : public GrXferProcessor { | 456 class ShaderPDXferProcessor : public GrXferProcessor { |
456 public: | 457 public: |
457 static GrXferProcessor* Create(SkXfermode::Mode xfermode, const DstTexture*
dstTexture) { | 458 static GrXferProcessor* Create(SkXfermode::Mode xfermode, const DstTexture*
dstTexture) { |
458 return SkNEW_ARGS(ShaderPDXferProcessor, (xfermode, dstTexture)); | 459 return SkNEW_ARGS(ShaderPDXferProcessor, (xfermode, dstTexture)); |
459 } | 460 } |
460 | 461 |
461 const char* name() const override { return "Porter Duff Shader"; } | 462 const char* name() const override { return "Porter Duff Shader"; } |
462 bool hasSecondaryOutput() const override { return false; } | |
463 | 463 |
464 GrGLXferProcessor* createGLInstance() const override; | 464 GrGLXferProcessor* createGLInstance() const override; |
465 | 465 |
466 SkXfermode::Mode getXfermode() const { return fXfermode; } | 466 SkXfermode::Mode getXfermode() const { return fXfermode; } |
467 | 467 |
468 private: | 468 private: |
469 ShaderPDXferProcessor(SkXfermode::Mode xfermode, const DstTexture* dstTextur
e) | 469 ShaderPDXferProcessor(SkXfermode::Mode xfermode, const DstTexture* dstTextur
e) |
470 : INHERITED(dstTexture, true) | 470 : INHERITED(dstTexture, true) |
471 , fXfermode(xfermode) { | 471 , fXfermode(xfermode) { |
472 this->initClassID<ShaderPDXferProcessor>(); | 472 this->initClassID<ShaderPDXferProcessor>(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 536 } |
537 | 537 |
538 class GLShaderPDXferProcessor : public GrGLXferProcessor { | 538 class GLShaderPDXferProcessor : public GrGLXferProcessor { |
539 public: | 539 public: |
540 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { | 540 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { |
541 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>(
); | 541 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>(
); |
542 b->add32(xp.getXfermode()); | 542 b->add32(xp.getXfermode()); |
543 } | 543 } |
544 | 544 |
545 private: | 545 private: |
546 void onEmitCode(const EmitArgs& args) override { | 546 void emitBlendCodeForDstRead(GrGLXPBuilder* pb, const char* srcColor, const
char* dstColor, |
547 const ShaderPDXferProcessor& xp = args.fXP.cast<ShaderPDXferProcessor>()
; | 547 const char* outColor, const GrXferProcessor& pr
oc) override { |
548 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 548 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); |
| 549 GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
549 | 550 |
550 SkXfermode::Coeff srcCoeff, dstCoeff; | 551 SkXfermode::Coeff srcCoeff, dstCoeff; |
551 SkXfermode::ModeAsCoeff(xp.getXfermode(), &srcCoeff, &dstCoeff); | 552 SkXfermode::ModeAsCoeff(xp.getXfermode(), &srcCoeff, &dstCoeff); |
552 | 553 |
553 const char* dstColor = fsBuilder->dstColor(); | 554 fsBuilder->codeAppendf("%s =", outColor); |
554 | |
555 fsBuilder->codeAppend("vec4 colorBlend ="); | |
556 // append src blend | 555 // append src blend |
557 bool didAppend = append_porterduff_term(fsBuilder, srcCoeff, | 556 bool didAppend = append_porterduff_term(fsBuilder, srcCoeff, srcColor, s
rcColor, dstColor, |
558 args.fInputColor, args.fInputCol
or, | 557 false); |
559 dstColor, false); | |
560 // append dst blend | 558 // append dst blend |
561 SkAssertResult(append_porterduff_term(fsBuilder, dstCoeff, | 559 SkAssertResult(append_porterduff_term(fsBuilder, dstCoeff, dstColor, src
Color, dstColor, |
562 dstColor, args.fInputColor, | 560 didAppend)); |
563 dstColor, didAppend)); | |
564 fsBuilder->codeAppend(";"); | 561 fsBuilder->codeAppend(";"); |
565 | |
566 fsBuilder->codeAppendf("%s = %s * colorBlend + (vec4(1.0) - %s) * %s;", | |
567 args.fOutputPrimary, args.fInputCoverage, args.fI
nputCoverage, | |
568 dstColor); | |
569 } | 562 } |
570 | 563 |
571 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri
de {} | 564 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri
de {} |
572 | 565 |
573 typedef GrGLXferProcessor INHERITED; | 566 typedef GrGLXferProcessor INHERITED; |
574 }; | 567 }; |
575 | 568 |
576 /////////////////////////////////////////////////////////////////////////////// | 569 /////////////////////////////////////////////////////////////////////////////// |
577 | 570 |
578 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, | 571 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, |
(...skipping 10 matching lines...) Expand all Loading... |
589 class PDLCDXferProcessor : public GrXferProcessor { | 582 class PDLCDXferProcessor : public GrXferProcessor { |
590 public: | 583 public: |
591 static GrXferProcessor* Create(SkXfermode::Mode xfermode, const GrProcOptInf
o& colorPOI); | 584 static GrXferProcessor* Create(SkXfermode::Mode xfermode, const GrProcOptInf
o& colorPOI); |
592 | 585 |
593 ~PDLCDXferProcessor() override; | 586 ~PDLCDXferProcessor() override; |
594 | 587 |
595 const char* name() const override { return "Porter Duff LCD"; } | 588 const char* name() const override { return "Porter Duff LCD"; } |
596 | 589 |
597 GrGLXferProcessor* createGLInstance() const override; | 590 GrGLXferProcessor* createGLInstance() const override; |
598 | 591 |
599 bool hasSecondaryOutput() const override { return false; } | |
600 | |
601 private: | 592 private: |
602 PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha); | 593 PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha); |
603 | 594 |
604 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 595 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
605 const GrProcOptInfo& coveragePO
I, | 596 const GrProcOptInfo& coveragePO
I, |
606 bool doesStencilWrite, | 597 bool doesStencilWrite, |
607 GrColor* overrideColor, | 598 GrColor* overrideColor, |
608 const GrCaps& caps) override; | 599 const GrCaps& caps) override; |
609 | 600 |
610 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 601 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
(...skipping 24 matching lines...) Expand all Loading... |
635 class GLPDLCDXferProcessor : public GrGLXferProcessor { | 626 class GLPDLCDXferProcessor : public GrGLXferProcessor { |
636 public: | 627 public: |
637 GLPDLCDXferProcessor(const GrProcessor&) {} | 628 GLPDLCDXferProcessor(const GrProcessor&) {} |
638 | 629 |
639 virtual ~GLPDLCDXferProcessor() {} | 630 virtual ~GLPDLCDXferProcessor() {} |
640 | 631 |
641 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, | 632 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
642 GrProcessorKeyBuilder* b) {} | 633 GrProcessorKeyBuilder* b) {} |
643 | 634 |
644 private: | 635 private: |
645 void onEmitCode(const EmitArgs& args) override { | 636 void emitOutputsForBlendState(const EmitArgs& args) override { |
646 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 637 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
647 | 638 |
648 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, | 639 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, |
649 args.fInputCoverage); | 640 args.fInputCoverage); |
650 } | 641 } |
651 | 642 |
652 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri
de {}; | 643 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri
de {}; |
653 | 644 |
654 typedef GrGLXferProcessor INHERITED; | 645 typedef GrGLXferProcessor INHERITED; |
655 }; | 646 }; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 int* outSecondary) { | 821 int* outSecondary) { |
831 if (!!strcmp(xp->name(), "Porter Duff")) { | 822 if (!!strcmp(xp->name(), "Porter Duff")) { |
832 *outPrimary = *outSecondary = -1; | 823 *outPrimary = *outSecondary = -1; |
833 return; | 824 return; |
834 } | 825 } |
835 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); | 826 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); |
836 *outPrimary = blendFormula.fPrimaryOutputType; | 827 *outPrimary = blendFormula.fPrimaryOutputType; |
837 *outSecondary = blendFormula.fSecondaryOutputType; | 828 *outSecondary = blendFormula.fSecondaryOutputType; |
838 } | 829 } |
839 | 830 |
OLD | NEW |