Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: src/gpu/effects/GrCustomXfermode.cpp

Issue 860383007: Move GrXferProcessor subclasses into cpp files (Closed) Base URL: https://skia.googlesource.com/skia.git@playDstCpy
Patch Set: Rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrCoverageSetOpXP.cpp ('k') | src/gpu/effects/GrCustomXfermodePriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 GrTexture* textures[]) { 477 GrTexture* textures[]) {
478 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas tSeparableMode); 478 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas tSeparableMode);
479 479
480 return SkNEW_ARGS(GrCustomXferFP, (static_cast<SkXfermode::Mode>(mode), text ures[0])); 480 return SkNEW_ARGS(GrCustomXferFP, (static_cast<SkXfermode::Mode>(mode), text ures[0]));
481 } 481 }
482 482
483 /////////////////////////////////////////////////////////////////////////////// 483 ///////////////////////////////////////////////////////////////////////////////
484 // Xfer Processor 484 // Xfer Processor
485 /////////////////////////////////////////////////////////////////////////////// 485 ///////////////////////////////////////////////////////////////////////////////
486 486
487 class CustomXP : public GrXferProcessor {
488 public:
489 static GrXferProcessor* Create(SkXfermode::Mode mode, const GrDeviceCoordTex ture* dstCopy,
490 bool willReadDstColor) {
491 if (!GrCustomXfermode::IsSupportedMode(mode)) {
492 return NULL;
493 } else {
494 return SkNEW_ARGS(CustomXP, (mode, dstCopy, willReadDstColor));
495 }
496 }
497
498 ~CustomXP() SK_OVERRIDE {};
499
500 const char* name() const SK_OVERRIDE { return "Custom Xfermode"; }
501
502 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE;
503
504 bool hasSecondaryOutput() const SK_OVERRIDE { return false; }
505
506 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI,
507 const GrProcOptInfo& coveragePOI,
508 bool doesStencilWrite,
509 GrColor* overrideColor,
510 const GrDrawTargetCaps& caps) SK_ OVERRIDE;
511
512 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE {
513 blendInfo->fSrcBlend = kOne_GrBlendCoeff;
514 blendInfo->fDstBlend = kZero_GrBlendCoeff;
515 blendInfo->fBlendConstant = 0;
516 }
517
518 SkXfermode::Mode mode() const { return fMode; }
519
520 private:
521 CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool wi llReadDstColor);
522
523 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con st SK_OVERRIDE;
524
525 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE;
526
527 SkXfermode::Mode fMode;
528
529 typedef GrXferProcessor INHERITED;
530 };
531
532 ///////////////////////////////////////////////////////////////////////////////
533
487 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { 534 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) {
488 if (!GrCustomXfermode::IsSupportedMode(mode)) { 535 if (!GrCustomXfermode::IsSupportedMode(mode)) {
489 return NULL; 536 return NULL;
490 } else { 537 } else {
491 return SkNEW_ARGS(GrCustomXPFactory, (mode)); 538 return SkNEW_ARGS(GrCustomXPFactory, (mode));
492 } 539 }
493 } 540 }
494 541
495 /////////////////////////////////////////////////////////////////////////////// 542 ///////////////////////////////////////////////////////////////////////////////
496 543
497 class GLCustomXP : public GrGLXferProcessor { 544 class GLCustomXP : public GrGLXferProcessor {
498 public: 545 public:
499 GLCustomXP(const GrXferProcessor&) {} 546 GLCustomXP(const GrXferProcessor&) {}
500 ~GLCustomXP() SK_OVERRIDE {} 547 ~GLCustomXP() SK_OVERRIDE {}
501 548
502 static void GenKey(const GrXferProcessor& proc, const GrGLCaps&, GrProcessor KeyBuilder* b) { 549 static void GenKey(const GrXferProcessor& proc, const GrGLCaps&, GrProcessor KeyBuilder* b) {
503 uint32_t key = proc.numTextures(); 550 uint32_t key = proc.numTextures();
504 SkASSERT(key <= 1); 551 SkASSERT(key <= 1);
505 key |= proc.cast<GrCustomXP>().mode() << 1; 552 key |= proc.cast<CustomXP>().mode() << 1;
506 b->add32(key); 553 b->add32(key);
507 } 554 }
508 555
509 private: 556 private:
510 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { 557 void onEmitCode(const EmitArgs& args) SK_OVERRIDE {
511 SkXfermode::Mode mode = args.fXP.cast<GrCustomXP>().mode(); 558 SkXfermode::Mode mode = args.fXP.cast<CustomXP>().mode();
512 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 559 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
513 const char* dstColor = fsBuilder->dstColor(); 560 const char* dstColor = fsBuilder->dstColor();
514 561
515 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);
516 563
517 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", 564 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;",
518 args.fOutputPrimary, args.fOutputPrimary, args.fI nputCoverage, 565 args.fOutputPrimary, args.fOutputPrimary, args.fI nputCoverage,
519 args.fInputCoverage, dstColor); 566 args.fInputCoverage, dstColor);
520 } 567 }
521 568
522 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE RRIDE {} 569 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE RRIDE {}
523 570
524 typedef GrGLFragmentProcessor INHERITED; 571 typedef GrGLFragmentProcessor INHERITED;
525 }; 572 };
526 573
527 /////////////////////////////////////////////////////////////////////////////// 574 ///////////////////////////////////////////////////////////////////////////////
528 575
529 GrCustomXP::GrCustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCop y, 576 CustomXP::CustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy,
530 bool willReadDstColor) 577 bool willReadDstColor)
531 : INHERITED(dstCopy, willReadDstColor), fMode(mode) { 578 : INHERITED(dstCopy, willReadDstColor), fMode(mode) {
532 this->initClassID<GrCustomXP>(); 579 this->initClassID<CustomXP>();
533 } 580 }
534 581
535 void GrCustomXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder * b) const { 582 void CustomXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const {
536 GLCustomXP::GenKey(*this, caps, b); 583 GLCustomXP::GenKey(*this, caps, b);
537 } 584 }
538 585
539 GrGLXferProcessor* GrCustomXP::createGLInstance() const { 586 GrGLXferProcessor* CustomXP::createGLInstance() const {
540 return SkNEW_ARGS(GLCustomXP, (*this)); 587 return SkNEW_ARGS(GLCustomXP, (*this));
541 } 588 }
542 589
543 bool GrCustomXP::onIsEqual(const GrXferProcessor& other) const { 590 bool CustomXP::onIsEqual(const GrXferProcessor& other) const {
544 const GrCustomXP& s = other.cast<GrCustomXP>(); 591 const CustomXP& s = other.cast<CustomXP>();
545 return fMode == s.fMode; 592 return fMode == s.fMode;
546 } 593 }
547 594
548 GrXferProcessor::OptFlags GrCustomXP::getOptimizations(const GrProcOptInfo& colo rPOI, 595 GrXferProcessor::OptFlags CustomXP::getOptimizations(const GrProcOptInfo& colorP OI,
549 const GrProcOptInfo& cove ragePOI, 596 const GrProcOptInfo& cove ragePOI,
550 bool doesStencilWrite, 597 bool doesStencilWrite,
551 GrColor* overrideColor, 598 GrColor* overrideColor,
552 const GrDrawTargetCaps& c aps) { 599 const GrDrawTargetCaps& c aps) {
553 return GrXferProcessor::kNone_Opt; 600 return GrXferProcessor::kNone_Opt;
554 } 601 }
555 602
556 /////////////////////////////////////////////////////////////////////////////// 603 ///////////////////////////////////////////////////////////////////////////////
557 604
558 GrCustomXPFactory::GrCustomXPFactory(SkXfermode::Mode mode) 605 GrCustomXPFactory::GrCustomXPFactory(SkXfermode::Mode mode)
559 : fMode(mode) { 606 : fMode(mode) {
560 this->initClassID<GrCustomXPFactory>(); 607 this->initClassID<GrCustomXPFactory>();
561 } 608 }
562 609
610 GrXferProcessor*
611 GrCustomXPFactory::onCreateXferProcessor(const GrProcOptInfo& colorPOI,
612 const GrProcOptInfo& coveragePOI,
613 const GrDeviceCoordTexture* dstCopy) co nst {
614 return CustomXP::Create(fMode, dstCopy, this->willReadDstColor());
615 }
616
617
563 void GrCustomXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, 618 void GrCustomXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI,
564 const GrProcOptInfo& coveragePOI, 619 const GrProcOptInfo& coveragePOI,
565 GrXPFactory::InvariantOutput* out put) const { 620 GrXPFactory::InvariantOutput* out put) const {
566 output->fWillBlendWithDst = true; 621 output->fWillBlendWithDst = true;
567 output->fBlendedColorFlags = 0; 622 output->fBlendedColorFlags = 0;
568 } 623 }
569 624
570 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); 625 GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory);
571 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand, 626 GrXPFactory* GrCustomXPFactory::TestCreate(SkRandom* rand,
572 GrContext*, 627 GrContext*,
573 const GrDrawTargetCaps&, 628 const GrDrawTargetCaps&,
574 GrTexture*[]) { 629 GrTexture*[]) {
575 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas tSeparableMode); 630 int mode = rand->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLas tSeparableMode);
576 631
577 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode))); 632 return SkNEW_ARGS(GrCustomXPFactory, (static_cast<SkXfermode::Mode>(mode)));
578 } 633 }
579 634
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCoverageSetOpXP.cpp ('k') | src/gpu/effects/GrCustomXfermodePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698