| 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 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 } else { | 400 } else { |
| 401 return SkNEW_ARGS(GrCustomXferFP, (mode, background)); | 401 return SkNEW_ARGS(GrCustomXferFP, (mode, background)); |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 /////////////////////////////////////////////////////////////////////////////// | 405 /////////////////////////////////////////////////////////////////////////////// |
| 406 | 406 |
| 407 class GLCustomXferFP : public GrGLFragmentProcessor { | 407 class GLCustomXferFP : public GrGLFragmentProcessor { |
| 408 public: | 408 public: |
| 409 GLCustomXferFP(const GrFragmentProcessor&) {} | 409 GLCustomXferFP(const GrFragmentProcessor&) {} |
| 410 ~GLCustomXferFP() SK_OVERRIDE {}; | 410 ~GLCustomXferFP() override {}; |
| 411 | 411 |
| 412 void emitCode(GrGLFPBuilder* builder, | 412 void emitCode(GrGLFPBuilder* builder, |
| 413 const GrFragmentProcessor& fp, | 413 const GrFragmentProcessor& fp, |
| 414 const char* outputColor, | 414 const char* outputColor, |
| 415 const char* inputColor, | 415 const char* inputColor, |
| 416 const TransformedCoordsArray& coords, | 416 const TransformedCoordsArray& coords, |
| 417 const TextureSamplerArray& samplers) SK_OVERRIDE { | 417 const TextureSamplerArray& samplers) override { |
| 418 SkXfermode::Mode mode = fp.cast<GrCustomXferFP>().mode(); | 418 SkXfermode::Mode mode = fp.cast<GrCustomXferFP>().mode(); |
| 419 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 419 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 420 const char* dstColor = "bgColor"; | 420 const char* dstColor = "bgColor"; |
| 421 fsBuilder->codeAppendf("vec4 %s = ", dstColor); | 421 fsBuilder->codeAppendf("vec4 %s = ", dstColor); |
| 422 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.getType()); | 422 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.getType()); |
| 423 fsBuilder->codeAppendf(";"); | 423 fsBuilder->codeAppendf(";"); |
| 424 | 424 |
| 425 emit_custom_xfermode_code(mode, fsBuilder, outputColor, inputColor, dstC
olor); | 425 emit_custom_xfermode_code(mode, fsBuilder, outputColor, inputColor, dstC
olor); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE
{} | 428 void setData(const GrGLProgramDataManager&, const GrProcessor&) override {} |
| 429 | 429 |
| 430 static void GenKey(const GrFragmentProcessor& proc, const GrGLCaps&, GrProce
ssorKeyBuilder* b) { | 430 static void GenKey(const GrFragmentProcessor& proc, const GrGLCaps&, GrProce
ssorKeyBuilder* b) { |
| 431 // The background may come from the dst or from a texture. | 431 // The background may come from the dst or from a texture. |
| 432 uint32_t key = proc.numTextures(); | 432 uint32_t key = proc.numTextures(); |
| 433 SkASSERT(key <= 1); | 433 SkASSERT(key <= 1); |
| 434 key |= proc.cast<GrCustomXferFP>().mode() << 1; | 434 key |= proc.cast<GrCustomXferFP>().mode() << 1; |
| 435 b->add32(key); | 435 b->add32(key); |
| 436 } | 436 } |
| 437 | 437 |
| 438 private: | 438 private: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 public: | 488 public: |
| 489 static GrXferProcessor* Create(SkXfermode::Mode mode, const GrDeviceCoordTex
ture* dstCopy, | 489 static GrXferProcessor* Create(SkXfermode::Mode mode, const GrDeviceCoordTex
ture* dstCopy, |
| 490 bool willReadDstColor) { | 490 bool willReadDstColor) { |
| 491 if (!GrCustomXfermode::IsSupportedMode(mode)) { | 491 if (!GrCustomXfermode::IsSupportedMode(mode)) { |
| 492 return NULL; | 492 return NULL; |
| 493 } else { | 493 } else { |
| 494 return SkNEW_ARGS(CustomXP, (mode, dstCopy, willReadDstColor)); | 494 return SkNEW_ARGS(CustomXP, (mode, dstCopy, willReadDstColor)); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 ~CustomXP() SK_OVERRIDE {}; | 498 ~CustomXP() override {}; |
| 499 | 499 |
| 500 const char* name() const SK_OVERRIDE { return "Custom Xfermode"; } | 500 const char* name() const override { return "Custom Xfermode"; } |
| 501 | 501 |
| 502 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE; | 502 GrGLXferProcessor* createGLInstance() const override; |
| 503 | 503 |
| 504 bool hasSecondaryOutput() const SK_OVERRIDE { return false; } | 504 bool hasSecondaryOutput() const override { return false; } |
| 505 | 505 |
| 506 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, | 506 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, |
| 507 const GrProcOptInfo& coveragePOI, | 507 const GrProcOptInfo& coveragePOI, |
| 508 bool doesStencilWrite, | 508 bool doesStencilWrite, |
| 509 GrColor* overrideColor, | 509 GrColor* overrideColor, |
| 510 const GrDrawTargetCaps& caps) SK_
OVERRIDE; | 510 const GrDrawTargetCaps& caps) ove
rride; |
| 511 | 511 |
| 512 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE { | 512 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { |
| 513 blendInfo->fSrcBlend = kOne_GrBlendCoeff; | 513 blendInfo->fSrcBlend = kOne_GrBlendCoeff; |
| 514 blendInfo->fDstBlend = kZero_GrBlendCoeff; | 514 blendInfo->fDstBlend = kZero_GrBlendCoeff; |
| 515 blendInfo->fBlendConstant = 0; | 515 blendInfo->fBlendConstant = 0; |
| 516 } | 516 } |
| 517 | 517 |
| 518 SkXfermode::Mode mode() const { return fMode; } | 518 SkXfermode::Mode mode() const { return fMode; } |
| 519 | 519 |
| 520 private: | 520 private: |
| 521 CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool wi
llReadDstColor); | 521 CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool wi
llReadDstColor); |
| 522 | 522 |
| 523 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st SK_OVERRIDE; | 523 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st override; |
| 524 | 524 |
| 525 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE; | 525 bool onIsEqual(const GrXferProcessor& xpBase) const override; |
| 526 | 526 |
| 527 SkXfermode::Mode fMode; | 527 SkXfermode::Mode fMode; |
| 528 | 528 |
| 529 typedef GrXferProcessor INHERITED; | 529 typedef GrXferProcessor INHERITED; |
| 530 }; | 530 }; |
| 531 | 531 |
| 532 /////////////////////////////////////////////////////////////////////////////// | 532 /////////////////////////////////////////////////////////////////////////////// |
| 533 | 533 |
| 534 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { | 534 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { |
| 535 if (!GrCustomXfermode::IsSupportedMode(mode)) { | 535 if (!GrCustomXfermode::IsSupportedMode(mode)) { |
| 536 return NULL; | 536 return NULL; |
| 537 } else { | 537 } else { |
| 538 return SkNEW_ARGS(GrCustomXPFactory, (mode)); | 538 return SkNEW_ARGS(GrCustomXPFactory, (mode)); |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 | 541 |
| 542 /////////////////////////////////////////////////////////////////////////////// | 542 /////////////////////////////////////////////////////////////////////////////// |
| 543 | 543 |
| 544 class GLCustomXP : public GrGLXferProcessor { | 544 class GLCustomXP : public GrGLXferProcessor { |
| 545 public: | 545 public: |
| 546 GLCustomXP(const GrXferProcessor&) {} | 546 GLCustomXP(const GrXferProcessor&) {} |
| 547 ~GLCustomXP() SK_OVERRIDE {} | 547 ~GLCustomXP() override {} |
| 548 | 548 |
| 549 static void GenKey(const GrXferProcessor& proc, const GrGLCaps&, GrProcessor
KeyBuilder* b) { | 549 static void GenKey(const GrXferProcessor& proc, const GrGLCaps&, GrProcessor
KeyBuilder* b) { |
| 550 uint32_t key = proc.numTextures(); | 550 uint32_t key = proc.numTextures(); |
| 551 SkASSERT(key <= 1); | 551 SkASSERT(key <= 1); |
| 552 key |= proc.cast<CustomXP>().mode() << 1; | 552 key |= proc.cast<CustomXP>().mode() << 1; |
| 553 b->add32(key); | 553 b->add32(key); |
| 554 } | 554 } |
| 555 | 555 |
| 556 private: | 556 private: |
| 557 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { | 557 void onEmitCode(const EmitArgs& args) override { |
| 558 SkXfermode::Mode mode = args.fXP.cast<CustomXP>().mode(); | 558 SkXfermode::Mode mode = args.fXP.cast<CustomXP>().mode(); |
| 559 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 559 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 560 const char* dstColor = fsBuilder->dstColor(); | 560 const char* dstColor = fsBuilder->dstColor(); |
| 561 | 561 |
| 562 emit_custom_xfermode_code(mode, fsBuilder, args.fOutputPrimary, args.fIn
putColor, dstColor); | 562 emit_custom_xfermode_code(mode, fsBuilder, args.fOutputPrimary, args.fIn
putColor, dstColor); |
| 563 | 563 |
| 564 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", | 564 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", |
| 565 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, | 565 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, |
| 566 args.fInputCoverage, dstColor); | 566 args.fInputCoverage, dstColor); |
| 567 } | 567 } |
| 568 | 568 |
| 569 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE
RRIDE {} | 569 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri
de {} |
| 570 | 570 |
| 571 typedef GrGLFragmentProcessor INHERITED; | 571 typedef GrGLFragmentProcessor INHERITED; |
| 572 }; | 572 }; |
| 573 | 573 |
| 574 /////////////////////////////////////////////////////////////////////////////// | 574 /////////////////////////////////////////////////////////////////////////////// |
| 575 | 575 |
| 576 CustomXP::CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, | 576 CustomXP::CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, |
| 577 bool willReadDstColor) | 577 bool willReadDstColor) |
| 578 : INHERITED(dstCopy, willReadDstColor), fMode(mode) { | 578 : INHERITED(dstCopy, willReadDstColor), fMode(mode) { |
| 579 this->initClassID<CustomXP>(); | 579 this->initClassID<CustomXP>(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); | 626 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); |
| 627 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, | 627 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, |
| 628 GrContext*, | 628 GrContext*, |
| 629 const GrDrawTargetCaps&, | 629 const GrDrawTargetCaps&, |
| 630 GrTexture*[]) { | 630 GrTexture*[]) { |
| 631 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); | 631 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); |
| 632 | 632 |
| 633 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); | 633 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); |
| 634 } | 634 } |
| 635 | 635 |
| OLD | NEW |