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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 /////////////////////////////////////////////////////////////////////////////// | 495 /////////////////////////////////////////////////////////////////////////////// |
496 | 496 |
497 class GLCustomXP : public GrGLXferProcessor { | 497 class GLCustomXP : public GrGLXferProcessor { |
498 public: | 498 public: |
499 GLCustomXP(const GrXferProcessor&) {} | 499 GLCustomXP(const GrXferProcessor&) {} |
500 ~GLCustomXP() SK_OVERRIDE {} | 500 ~GLCustomXP() SK_OVERRIDE {} |
501 | 501 |
502 void emitCode(const EmitArgs& args) SK_OVERRIDE { | 502 static void GenKey(const GrXferProcessor& proc, const GrGLCaps&, GrProcessor
KeyBuilder* b) { |
| 503 uint32_t key = proc.numTextures(); |
| 504 SkASSERT(key <= 1); |
| 505 key |= proc.cast<GrCustomXP>().mode() << 1; |
| 506 b->add32(key); |
| 507 } |
| 508 |
| 509 private: |
| 510 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { |
503 SkXfermode::Mode mode = args.fXP.cast<GrCustomXP>().mode(); | 511 SkXfermode::Mode mode = args.fXP.cast<GrCustomXP>().mode(); |
504 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 512 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
505 const char* dstColor = fsBuilder->dstColor(); | 513 const char* dstColor = fsBuilder->dstColor(); |
506 | 514 |
507 emit_custom_xfermode_code(mode, fsBuilder, args.fOutputPrimary, args.fIn
putColor, dstColor); | 515 emit_custom_xfermode_code(mode, fsBuilder, args.fOutputPrimary, args.fIn
putColor, dstColor); |
508 | 516 |
509 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", | 517 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", |
510 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, | 518 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, |
511 args.fInputCoverage, dstColor); | 519 args.fInputCoverage, dstColor); |
512 } | 520 } |
513 | 521 |
514 void setData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVERR
IDE {} | 522 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE
RRIDE {} |
515 | 523 |
516 static void GenKey(const GrXferProcessor& proc, const GrGLCaps&, GrProcessor
KeyBuilder* b) { | |
517 uint32_t key = proc.numTextures(); | |
518 SkASSERT(key <= 1); | |
519 key |= proc.cast<GrCustomXP>().mode() << 1; | |
520 b->add32(key); | |
521 } | |
522 | |
523 private: | |
524 typedef GrGLFragmentProcessor INHERITED; | 524 typedef GrGLFragmentProcessor INHERITED; |
525 }; | 525 }; |
526 | 526 |
527 /////////////////////////////////////////////////////////////////////////////// | 527 /////////////////////////////////////////////////////////////////////////////// |
528 | 528 |
529 GrCustomXP::GrCustomXP(SkXfermode::Mode mode) | 529 GrCustomXP::GrCustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCop
y, |
530 : fMode(mode) { | 530 int32_t dstReadKey) |
| 531 : INHERITED(dstCopy, dstReadKey), fMode(mode) { |
531 this->initClassID<GrCustomXP>(); | 532 this->initClassID<GrCustomXP>(); |
532 this->setWillReadDstColor(); | 533 this->setWillReadDstColor(); |
533 } | 534 } |
534 | 535 |
535 void GrCustomXP::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder*
b) const { | 536 void GrCustomXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder
* b) const { |
536 GLCustomXP::GenKey(*this, caps, b); | 537 GLCustomXP::GenKey(*this, caps, b); |
537 } | 538 } |
538 | 539 |
539 GrGLXferProcessor* GrCustomXP::createGLInstance() const { | 540 GrGLXferProcessor* GrCustomXP::createGLInstance() const { |
540 return SkNEW_ARGS(GLCustomXP, (*this)); | 541 return SkNEW_ARGS(GLCustomXP, (*this)); |
541 } | 542 } |
542 | 543 |
543 bool GrCustomXP::onIsEqual(const GrXferProcessor& other) const { | 544 bool GrCustomXP::onIsEqual(const GrXferProcessor& other) const { |
544 const GrCustomXP& s = other.cast<GrCustomXP>(); | 545 const GrCustomXP& s = other.cast<GrCustomXP>(); |
545 return fMode == s.fMode; | 546 return fMode == s.fMode; |
(...skipping 24 matching lines...) Expand all Loading... |
570 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); | 571 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); |
571 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, | 572 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, |
572 GrContext*, | 573 GrContext*, |
573 const GrDrawTargetCaps&, | 574 const GrDrawTargetCaps&, |
574 GrTexture*[]) { | 575 GrTexture*[]) { |
575 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); | 576 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas
tSeparableMode); |
576 | 577 |
577 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); | 578 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); |
578 } | 579 } |
579 | 580 |
OLD | NEW |