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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 375 } |
376 | 376 |
377 const BlendFormula fBlendFormula; | 377 const BlendFormula fBlendFormula; |
378 | 378 |
379 typedef GrXferProcessor INHERITED; | 379 typedef GrXferProcessor INHERITED; |
380 }; | 380 }; |
381 | 381 |
382 /////////////////////////////////////////////////////////////////////////////// | 382 /////////////////////////////////////////////////////////////////////////////// |
383 | 383 |
384 static void append_color_output(const PorterDuffXferProcessor& xp, | 384 static void append_color_output(const PorterDuffXferProcessor& xp, |
385 GrGLSLXPFragmentBuilder* fsBuilder, | 385 GrGLSLXPFragmentBuilder* fragBuilder, |
386 BlendFormula::OutputType outputType, const char*
output, | 386 BlendFormula::OutputType outputType, const char*
output, |
387 const char* inColor, const char* inCoverage) { | 387 const char* inColor, const char* inCoverage) { |
388 switch (outputType) { | 388 switch (outputType) { |
389 case BlendFormula::kNone_OutputType: | 389 case BlendFormula::kNone_OutputType: |
390 fsBuilder->codeAppendf("%s = vec4(0.0);", output); | 390 fragBuilder->codeAppendf("%s = vec4(0.0);", output); |
391 break; | 391 break; |
392 case BlendFormula::kCoverage_OutputType: | 392 case BlendFormula::kCoverage_OutputType: |
393 // We can have a coverage formula while not reading coverage if ther
e are mixed samples. | 393 // We can have a coverage formula while not reading coverage if ther
e are mixed samples. |
394 fsBuilder->codeAppendf("%s = %s;", | 394 fragBuilder->codeAppendf("%s = %s;", |
395 output, xp.readsCoverage() ? inCoverage : "ve
c4(1.0)"); | 395 output, xp.readsCoverage() ? inCoverage : "ve
c4(1.0)"); |
396 break; | 396 break; |
397 case BlendFormula::kModulate_OutputType: | 397 case BlendFormula::kModulate_OutputType: |
398 if (xp.readsCoverage()) { | 398 if (xp.readsCoverage()) { |
399 fsBuilder->codeAppendf("%s = %s * %s;", output, inColor, inCover
age); | 399 fragBuilder->codeAppendf("%s = %s * %s;", output, inColor, inCov
erage); |
400 } else { | 400 } else { |
401 fsBuilder->codeAppendf("%s = %s;", output, inColor); | 401 fragBuilder->codeAppendf("%s = %s;", output, inColor); |
402 } | 402 } |
403 break; | 403 break; |
404 case BlendFormula::kSAModulate_OutputType: | 404 case BlendFormula::kSAModulate_OutputType: |
405 if (xp.readsCoverage()) { | 405 if (xp.readsCoverage()) { |
406 fsBuilder->codeAppendf("%s = %s.a * %s;", output, inColor, inCov
erage); | 406 fragBuilder->codeAppendf("%s = %s.a * %s;", output, inColor, inC
overage); |
407 } else { | 407 } else { |
408 fsBuilder->codeAppendf("%s = %s;", output, inColor); | 408 fragBuilder->codeAppendf("%s = %s;", output, inColor); |
409 } | 409 } |
410 break; | 410 break; |
411 case BlendFormula::kISAModulate_OutputType: | 411 case BlendFormula::kISAModulate_OutputType: |
412 if (xp.readsCoverage()) { | 412 if (xp.readsCoverage()) { |
413 fsBuilder->codeAppendf("%s = (1.0 - %s.a) * %s;", output, inColo
r, inCoverage); | 413 fragBuilder->codeAppendf("%s = (1.0 - %s.a) * %s;", output, inCo
lor, inCoverage); |
414 } else { | 414 } else { |
415 fsBuilder->codeAppendf("%s = vec4(1.0 - %s.a);", output, inColor
); | 415 fragBuilder->codeAppendf("%s = vec4(1.0 - %s.a);", output, inCol
or); |
416 } | 416 } |
417 break; | 417 break; |
418 case BlendFormula::kISCModulate_OutputType: | 418 case BlendFormula::kISCModulate_OutputType: |
419 if (xp.readsCoverage()) { | 419 if (xp.readsCoverage()) { |
420 fsBuilder->codeAppendf("%s = (vec4(1.0) - %s) * %s;", output, in
Color, inCoverage); | 420 fragBuilder->codeAppendf("%s = (vec4(1.0) - %s) * %s;", output,
inColor, inCoverage); |
421 } else { | 421 } else { |
422 fsBuilder->codeAppendf("%s = vec4(1.0) - %s;", output, inColor); | 422 fragBuilder->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 GrGLSLXferProcessor { | 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* fragBuilder = args.fXPFragBuilder; |
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, fragBuilder, blendFormula.fSecondaryOutputTy
pe, |
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, fragBuilder, 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 GrGLSLXferProcessor INHERITED; | 457 typedef GrGLSLXferProcessor INHERITED; |
458 }; | 458 }; |
459 | 459 |
460 /////////////////////////////////////////////////////////////////////////////// | 460 /////////////////////////////////////////////////////////////////////////////// |
461 | 461 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 /////////////////////////////////////////////////////////////////////////////// | 537 /////////////////////////////////////////////////////////////////////////////// |
538 | 538 |
539 class GLShaderPDXferProcessor : public GrGLSLXferProcessor { | 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, |
548 const char* outColor, const GrXferProcessor& pr
oc) override { | 548 GrGLSLXPFragmentBuilder* fragBuilder, |
| 549 const char* srcColor, |
| 550 const char* dstColor, |
| 551 const char* outColor, |
| 552 const GrXferProcessor& proc) override { |
549 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); | 553 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); |
550 GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | |
551 | 554 |
552 GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.getX
fermode()); | 555 GrGLSLBlend::AppendMode(fragBuilder, srcColor, dstColor, outColor, xp.ge
tXfermode()); |
553 } | 556 } |
554 | 557 |
555 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} | 558 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} |
556 | 559 |
557 typedef GrGLSLXferProcessor INHERITED; | 560 typedef GrGLSLXferProcessor INHERITED; |
558 }; | 561 }; |
559 | 562 |
560 /////////////////////////////////////////////////////////////////////////////// | 563 /////////////////////////////////////////////////////////////////////////////// |
561 | 564 |
562 void ShaderPDXferProcessor::onGetGLSLProcessorKey(const GrGLSLCaps&, | 565 void ShaderPDXferProcessor::onGetGLSLProcessorKey(const GrGLSLCaps&, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 public: | 621 public: |
619 GLPDLCDXferProcessor(const GrProcessor&) {} | 622 GLPDLCDXferProcessor(const GrProcessor&) {} |
620 | 623 |
621 virtual ~GLPDLCDXferProcessor() {} | 624 virtual ~GLPDLCDXferProcessor() {} |
622 | 625 |
623 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, | 626 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
624 GrProcessorKeyBuilder* b) {} | 627 GrProcessorKeyBuilder* b) {} |
625 | 628 |
626 private: | 629 private: |
627 void emitOutputsForBlendState(const EmitArgs& args) override { | 630 void emitOutputsForBlendState(const EmitArgs& args) override { |
628 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 631 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; |
629 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, | 632 fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInp
utColor, |
630 args.fInputCoverage); | 633 args.fInputCoverage); |
631 } | 634 } |
632 | 635 |
633 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {}; | 636 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {}; |
634 | 637 |
635 typedef GrGLSLXferProcessor INHERITED; | 638 typedef GrGLSLXferProcessor INHERITED; |
636 }; | 639 }; |
637 | 640 |
638 /////////////////////////////////////////////////////////////////////////////// | 641 /////////////////////////////////////////////////////////////////////////////// |
639 | 642 |
640 PDLCDXferProcessor::PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha) | 643 PDLCDXferProcessor::PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha) |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 int* outPrimary, | 823 int* outPrimary, |
821 int* outSecondary) { | 824 int* outSecondary) { |
822 if (!!strcmp(xp->name(), "Porter Duff")) { | 825 if (!!strcmp(xp->name(), "Porter Duff")) { |
823 *outPrimary = *outSecondary = -1; | 826 *outPrimary = *outSecondary = -1; |
824 return; | 827 return; |
825 } | 828 } |
826 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); | 829 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); |
827 *outPrimary = blendFormula.fPrimaryOutputType; | 830 *outPrimary = blendFormula.fPrimaryOutputType; |
828 *outSecondary = blendFormula.fSecondaryOutputType; | 831 *outSecondary = blendFormula.fSecondaryOutputType; |
829 } | 832 } |
OLD | NEW |