| 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/GrGLSLBlend.h" | 16 #include "gl/GrGLSLBlend.h" |
| 17 #include "gl/GrGLXferProcessor.h" | 17 #include "gl/GrGLXferProcessor.h" |
| 18 #include "gl/builders/GrGLFragmentShaderBuilder.h" | 18 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 19 #include "gl/builders/GrGLProgramBuilder.h" | 19 #include "glsl/GrGLSLProgramBuilder.h" |
| 20 #include "glsl/GrGLSLProgramDataManager.h" | 20 #include "glsl/GrGLSLProgramDataManager.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. |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 return fBlendFormula == xp.fBlendFormula; | 374 return fBlendFormula == xp.fBlendFormula; |
| 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, GrGLXPFragmen
tBuilder* fsBuilder, | 384 static void append_color_output(const PorterDuffXferProcessor& xp, |
| 385 GrGLSLXPFragmentBuilder* fsBuilder, |
| 385 BlendFormula::OutputType outputType, const char*
output, | 386 BlendFormula::OutputType outputType, const char*
output, |
| 386 const char* inColor, const char* inCoverage) { | 387 const char* inColor, const char* inCoverage) { |
| 387 switch (outputType) { | 388 switch (outputType) { |
| 388 case BlendFormula::kNone_OutputType: | 389 case BlendFormula::kNone_OutputType: |
| 389 fsBuilder->codeAppendf("%s = vec4(0.0);", output); | 390 fsBuilder->codeAppendf("%s = vec4(0.0);", output); |
| 390 break; | 391 break; |
| 391 case BlendFormula::kCoverage_OutputType: | 392 case BlendFormula::kCoverage_OutputType: |
| 392 // 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. |
| 393 fsBuilder->codeAppendf("%s = %s;", | 394 fsBuilder->codeAppendf("%s = %s;", |
| 394 output, xp.readsCoverage() ? inCoverage : "ve
c4(1.0)"); | 395 output, xp.readsCoverage() ? inCoverage : "ve
c4(1.0)"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); | 434 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); |
| 434 b->add32(SkToInt(xp.readsCoverage()) | | 435 b->add32(SkToInt(xp.readsCoverage()) | |
| 435 (xp.getBlendFormula().fPrimaryOutputType << 1) | | 436 (xp.getBlendFormula().fPrimaryOutputType << 1) | |
| 436 (xp.getBlendFormula().fSecondaryOutputType << 4)); | 437 (xp.getBlendFormula().fSecondaryOutputType << 4)); |
| 437 GR_STATIC_ASSERT(BlendFormula::kLast_OutputType < 8); | 438 GR_STATIC_ASSERT(BlendFormula::kLast_OutputType < 8); |
| 438 }; | 439 }; |
| 439 | 440 |
| 440 private: | 441 private: |
| 441 void emitOutputsForBlendState(const EmitArgs& args) override { | 442 void emitOutputsForBlendState(const EmitArgs& args) override { |
| 442 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); | 443 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); |
| 443 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 444 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
| 444 | 445 |
| 445 BlendFormula blendFormula = xp.getBlendFormula(); | 446 BlendFormula blendFormula = xp.getBlendFormula(); |
| 446 if (blendFormula.hasSecondaryOutput()) { | 447 if (blendFormula.hasSecondaryOutput()) { |
| 447 append_color_output(xp, fsBuilder, blendFormula.fSecondaryOutputType
, | 448 append_color_output(xp, fsBuilder, blendFormula.fSecondaryOutputType
, |
| 448 args.fOutputSecondary, args.fInputColor, args.fI
nputCoverage); | 449 args.fOutputSecondary, args.fInputColor, args.fI
nputCoverage); |
| 449 } | 450 } |
| 450 append_color_output(xp, fsBuilder, blendFormula.fPrimaryOutputType, | 451 append_color_output(xp, fsBuilder, blendFormula.fPrimaryOutputType, |
| 451 args.fOutputPrimary, args.fInputColor, args.fInputCo
verage); | 452 args.fOutputPrimary, args.fInputColor, args.fInputCo
verage); |
| 452 } | 453 } |
| 453 | 454 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 public: | 540 public: |
| 540 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { | 541 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { |
| 541 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>(
); | 542 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>(
); |
| 542 b->add32(xp.getXfermode()); | 543 b->add32(xp.getXfermode()); |
| 543 } | 544 } |
| 544 | 545 |
| 545 private: | 546 private: |
| 546 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, cons
t char* dstColor, | 547 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, cons
t char* dstColor, |
| 547 const char* outColor, const GrXferProcessor& pr
oc) override { | 548 const char* outColor, const GrXferProcessor& pr
oc) override { |
| 548 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); | 549 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); |
| 549 GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 550 GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 550 | 551 |
| 551 GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.getX
fermode()); | 552 GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.getX
fermode()); |
| 552 } | 553 } |
| 553 | 554 |
| 554 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} | 555 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} |
| 555 | 556 |
| 556 typedef GrGLXferProcessor INHERITED; | 557 typedef GrGLXferProcessor INHERITED; |
| 557 }; | 558 }; |
| 558 | 559 |
| 559 /////////////////////////////////////////////////////////////////////////////// | 560 /////////////////////////////////////////////////////////////////////////////// |
| 560 | 561 |
| 561 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, | 562 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, |
| 562 GrProcessorKeyBuilder* b) cons
t { | 563 GrProcessorKeyBuilder* b) const
{ |
| 563 GLShaderPDXferProcessor::GenKey(*this, b); | 564 GLShaderPDXferProcessor::GenKey(*this, b); |
| 564 } | 565 } |
| 565 | 566 |
| 566 GrGLXferProcessor* ShaderPDXferProcessor::createGLInstance() const { | 567 GrGLXferProcessor* ShaderPDXferProcessor::createGLInstance() const { |
| 567 return new GLShaderPDXferProcessor; | 568 return new GLShaderPDXferProcessor; |
| 568 } | 569 } |
| 569 | 570 |
| 570 /////////////////////////////////////////////////////////////////////////////// | 571 /////////////////////////////////////////////////////////////////////////////// |
| 571 | 572 |
| 572 class PDLCDXferProcessor : public GrXferProcessor { | 573 class PDLCDXferProcessor : public GrXferProcessor { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 public: | 618 public: |
| 618 GLPDLCDXferProcessor(const GrProcessor&) {} | 619 GLPDLCDXferProcessor(const GrProcessor&) {} |
| 619 | 620 |
| 620 virtual ~GLPDLCDXferProcessor() {} | 621 virtual ~GLPDLCDXferProcessor() {} |
| 621 | 622 |
| 622 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, | 623 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
| 623 GrProcessorKeyBuilder* b) {} | 624 GrProcessorKeyBuilder* b) {} |
| 624 | 625 |
| 625 private: | 626 private: |
| 626 void emitOutputsForBlendState(const EmitArgs& args) override { | 627 void emitOutputsForBlendState(const EmitArgs& args) override { |
| 627 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 628 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
| 628 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, | 629 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, |
| 629 args.fInputCoverage); | 630 args.fInputCoverage); |
| 630 } | 631 } |
| 631 | 632 |
| 632 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {}; | 633 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {}; |
| 633 | 634 |
| 634 typedef GrGLXferProcessor INHERITED; | 635 typedef GrGLXferProcessor INHERITED; |
| 635 }; | 636 }; |
| 636 | 637 |
| 637 /////////////////////////////////////////////////////////////////////////////// | 638 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 int* outPrimary, | 820 int* outPrimary, |
| 820 int* outSecondary) { | 821 int* outSecondary) { |
| 821 if (!!strcmp(xp->name(), "Porter Duff")) { | 822 if (!!strcmp(xp->name(), "Porter Duff")) { |
| 822 *outPrimary = *outSecondary = -1; | 823 *outPrimary = *outSecondary = -1; |
| 823 return; | 824 return; |
| 824 } | 825 } |
| 825 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); | 826 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)-
>getBlendFormula(); |
| 826 *outPrimary = blendFormula.fPrimaryOutputType; | 827 *outPrimary = blendFormula.fPrimaryOutputType; |
| 827 *outSecondary = blendFormula.fSecondaryOutputType; | 828 *outSecondary = blendFormula.fSecondaryOutputType; |
| 828 } | 829 } |
| OLD | NEW |