| 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 20 matching lines...) Expand all Loading... |
| 31 kISA_GrBlendCoeff == dstCoeff || | 31 kISA_GrBlendCoeff == dstCoeff || |
| 32 kISC_GrBlendCoeff == dstCoeff; | 32 kISC_GrBlendCoeff == dstCoeff; |
| 33 } | 33 } |
| 34 | 34 |
| 35 class GrGLPorterDuffXferProcessor : public GrGLXferProcessor { | 35 class GrGLPorterDuffXferProcessor : public GrGLXferProcessor { |
| 36 public: | 36 public: |
| 37 GrGLPorterDuffXferProcessor(const GrProcessor&) {} | 37 GrGLPorterDuffXferProcessor(const GrProcessor&) {} |
| 38 | 38 |
| 39 virtual ~GrGLPorterDuffXferProcessor() {} | 39 virtual ~GrGLPorterDuffXferProcessor() {} |
| 40 | 40 |
| 41 void emitCode(const EmitArgs& args) SK_OVERRIDE { | 41 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, |
| 42 GrProcessorKeyBuilder* b) { |
| 43 const GrPorterDuffXferProcessor& xp = processor.cast<GrPorterDuffXferPro
cessor>(); |
| 44 b->add32(xp.primaryOutputType()); |
| 45 b->add32(xp.secondaryOutputType()); |
| 46 }; |
| 47 |
| 48 private: |
| 49 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { |
| 42 const GrPorterDuffXferProcessor& xp = args.fXP.cast<GrPorterDuffXferProc
essor>(); | 50 const GrPorterDuffXferProcessor& xp = args.fXP.cast<GrPorterDuffXferProc
essor>(); |
| 43 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 51 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 44 if (xp.hasSecondaryOutput()) { | 52 if (xp.hasSecondaryOutput()) { |
| 45 switch(xp.secondaryOutputType()) { | 53 switch(xp.secondaryOutputType()) { |
| 46 case GrPorterDuffXferProcessor::kCoverage_SecondaryOutputType: | 54 case GrPorterDuffXferProcessor::kCoverage_SecondaryOutputType: |
| 47 fsBuilder->codeAppendf("%s = %s;", args.fOutputSecondary, ar
gs.fInputCoverage); | 55 fsBuilder->codeAppendf("%s = %s;", args.fOutputSecondary, ar
gs.fInputCoverage); |
| 48 break; | 56 break; |
| 49 case GrPorterDuffXferProcessor::kCoverageISA_SecondaryOutputType
: | 57 case GrPorterDuffXferProcessor::kCoverageISA_SecondaryOutputType
: |
| 50 fsBuilder->codeAppendf("%s = (1.0 - %s.a) * %s;", | 58 fsBuilder->codeAppendf("%s = (1.0 - %s.a) * %s;", |
| 51 args.fOutputSecondary, args.fInputCol
or, | 59 args.fOutputSecondary, args.fInputCol
or, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 73 break; | 81 break; |
| 74 case GrPorterDuffXferProcessor::kModulate_PrimaryOutputType: | 82 case GrPorterDuffXferProcessor::kModulate_PrimaryOutputType: |
| 75 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, arg
s.fInputColor, | 83 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, arg
s.fInputColor, |
| 76 args.fInputCoverage); | 84 args.fInputCoverage); |
| 77 break; | 85 break; |
| 78 default: | 86 default: |
| 79 SkFAIL("Unexpected Primary Output"); | 87 SkFAIL("Unexpected Primary Output"); |
| 80 } | 88 } |
| 81 } | 89 } |
| 82 | 90 |
| 83 void setData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVERR
IDE {}; | 91 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE
RRIDE {}; |
| 84 | 92 |
| 85 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, | |
| 86 GrProcessorKeyBuilder* b) { | |
| 87 const GrPorterDuffXferProcessor& xp = processor.cast<GrPorterDuffXferPro
cessor>(); | |
| 88 b->add32(xp.primaryOutputType()); | |
| 89 b->add32(xp.secondaryOutputType()); | |
| 90 }; | |
| 91 | |
| 92 private: | |
| 93 typedef GrGLXferProcessor INHERITED; | 93 typedef GrGLXferProcessor INHERITED; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 /////////////////////////////////////////////////////////////////////////////// | 96 /////////////////////////////////////////////////////////////////////////////// |
| 97 | 97 |
| 98 GrPorterDuffXferProcessor::GrPorterDuffXferProcessor(GrBlendCoeff srcBlend, GrBl
endCoeff dstBlend, | 98 GrPorterDuffXferProcessor::GrPorterDuffXferProcessor(GrBlendCoeff srcBlend, |
| 99 GrColor constant) | 99 GrBlendCoeff dstBlend, |
| 100 GrColor constant, |
| 101 const GrDeviceCoordTexture*
dstCopy, |
| 102 bool willReadDstColor) |
| 100 : fSrcBlend(srcBlend) | 103 : fSrcBlend(srcBlend) |
| 101 , fDstBlend(dstBlend) | 104 , fDstBlend(dstBlend) |
| 102 , fBlendConstant(constant) | 105 , fBlendConstant(constant) |
| 103 , fPrimaryOutputType(kModulate_PrimaryOutputType) | 106 , fPrimaryOutputType(kModulate_PrimaryOutputType) |
| 104 , fSecondaryOutputType(kNone_SecondaryOutputType) { | 107 , fSecondaryOutputType(kNone_SecondaryOutputType) { |
| 105 this->initClassID<GrPorterDuffXferProcessor>(); | 108 this->initClassID<GrPorterDuffXferProcessor>(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 GrPorterDuffXferProcessor::~GrPorterDuffXferProcessor() { | 111 GrPorterDuffXferProcessor::~GrPorterDuffXferProcessor() { |
| 109 } | 112 } |
| 110 | 113 |
| 111 void GrPorterDuffXferProcessor::getGLProcessorKey(const GrGLCaps& caps, | 114 void GrPorterDuffXferProcessor::onGetGLProcessorKey(const GrGLCaps& caps, |
| 112 GrProcessorKeyBuilder* b) cons
t { | 115 GrProcessorKeyBuilder* b) co
nst { |
| 113 GrGLPorterDuffXferProcessor::GenKey(*this, caps, b); | 116 GrGLPorterDuffXferProcessor::GenKey(*this, caps, b); |
| 114 } | 117 } |
| 115 | 118 |
| 116 GrGLXferProcessor* GrPorterDuffXferProcessor::createGLInstance() const { | 119 GrGLXferProcessor* GrPorterDuffXferProcessor::createGLInstance() const { |
| 117 return SkNEW_ARGS(GrGLPorterDuffXferProcessor, (*this)); | 120 return SkNEW_ARGS(GrGLPorterDuffXferProcessor, (*this)); |
| 118 } | 121 } |
| 119 | 122 |
| 120 GrXferProcessor::OptFlags | 123 GrXferProcessor::OptFlags |
| 121 GrPorterDuffXferProcessor::getOptimizations(const GrProcOptInfo& colorPOI, | 124 GrPorterDuffXferProcessor::getOptimizations(const GrProcOptInfo& colorPOI, |
| 122 const GrProcOptInfo& coveragePOI, | 125 const GrProcOptInfo& coveragePOI, |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 case SkXfermode::kScreen_Mode: { | 349 case SkXfermode::kScreen_Mode: { |
| 347 static GrPorterDuffXPFactory gScreenPDXPF(kOne_GrBlendCoeff, kISC_Gr
BlendCoeff); | 350 static GrPorterDuffXPFactory gScreenPDXPF(kOne_GrBlendCoeff, kISC_Gr
BlendCoeff); |
| 348 return SkRef(&gScreenPDXPF); | 351 return SkRef(&gScreenPDXPF); |
| 349 break; | 352 break; |
| 350 } | 353 } |
| 351 default: | 354 default: |
| 352 return NULL; | 355 return NULL; |
| 353 } | 356 } |
| 354 } | 357 } |
| 355 | 358 |
| 356 GrXferProcessor* GrPorterDuffXPFactory::createXferProcessor(const GrProcOptInfo&
colorPOI, | 359 GrXferProcessor* |
| 357 const GrProcOptInfo&
covPOI) const { | 360 GrPorterDuffXPFactory::onCreateXferProcessor(const GrProcOptInfo& colorPOI, |
| 361 const GrProcOptInfo& covPOI, |
| 362 const GrDeviceCoordTexture* dstCopy
) const { |
| 358 if (!covPOI.isFourChannelOutput()) { | 363 if (!covPOI.isFourChannelOutput()) { |
| 359 return GrPorterDuffXferProcessor::Create(fSrcCoeff, fDstCoeff); | 364 return GrPorterDuffXferProcessor::Create(fSrcCoeff, fDstCoeff, 0, dstCop
y, |
| 365 this->willReadDstColor()); |
| 360 } else { | 366 } else { |
| 361 if (this->supportsRGBCoverage(colorPOI.color(), colorPOI.validFlags()))
{ | 367 if (this->supportsRGBCoverage(colorPOI.color(), colorPOI.validFlags()))
{ |
| 362 SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags()); | 368 SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags()); |
| 363 GrColor blendConstant = GrUnPreMulColor(colorPOI.color()); | 369 GrColor blendConstant = GrUnPreMulColor(colorPOI.color()); |
| 364 return GrPorterDuffXferProcessor::Create(kConstC_GrBlendCoeff, kISC_
GrBlendCoeff, | 370 return GrPorterDuffXferProcessor::Create(kConstC_GrBlendCoeff, kISC_
GrBlendCoeff, |
| 365 blendConstant); | 371 blendConstant, dstCopy, |
| 372 this->willReadDstColor()); |
| 366 } else { | 373 } else { |
| 367 return NULL; | 374 return NULL; |
| 368 } | 375 } |
| 369 } | 376 } |
| 370 } | 377 } |
| 371 | 378 |
| 372 bool GrPorterDuffXPFactory::supportsRGBCoverage(GrColor /*knownColor*/, | 379 bool GrPorterDuffXPFactory::supportsRGBCoverage(GrColor /*knownColor*/, |
| 373 uint32_t knownColorFlags) const
{ | 380 uint32_t knownColorFlags) const
{ |
| 374 if (kOne_GrBlendCoeff == fSrcCoeff && kISA_GrBlendCoeff == fDstCoeff && | 381 if (kOne_GrBlendCoeff == fSrcCoeff && kISA_GrBlendCoeff == fDstCoeff && |
| 375 kRGBA_GrColorComponentFlags == knownColorFlags) { | 382 kRGBA_GrColorComponentFlags == knownColorFlags) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 case kIConstC_GrBlendCoeff: | 484 case kIConstC_GrBlendCoeff: |
| 478 case kConstA_GrBlendCoeff: | 485 case kConstA_GrBlendCoeff: |
| 479 case kIConstA_GrBlendCoeff: | 486 case kIConstA_GrBlendCoeff: |
| 480 output->fBlendedColorFlags = 0; | 487 output->fBlendedColorFlags = 0; |
| 481 break; | 488 break; |
| 482 } | 489 } |
| 483 | 490 |
| 484 output->fWillBlendWithDst = false; | 491 output->fWillBlendWithDst = false; |
| 485 } | 492 } |
| 486 | 493 |
| 494 bool GrPorterDuffXPFactory::willReadDstColor() const { |
| 495 return false; |
| 496 } |
| 497 |
| 487 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); | 498 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
| 488 | 499 |
| 489 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, | 500 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, |
| 490 GrContext*, | 501 GrContext*, |
| 491 const GrDrawTargetCaps&, | 502 const GrDrawTargetCaps&, |
| 492 GrTexture*[]) { | 503 GrTexture*[]) { |
| 493 GrBlendCoeff src; | 504 GrBlendCoeff src; |
| 494 do { | 505 do { |
| 495 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); | 506 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); |
| 496 } while (GrBlendCoeffRefsSrc(src)); | 507 } while (GrBlendCoeffRefsSrc(src)); |
| 497 | 508 |
| 498 GrBlendCoeff dst; | 509 GrBlendCoeff dst; |
| 499 do { | 510 do { |
| 500 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); | 511 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); |
| 501 } while (GrBlendCoeffRefsDst(dst)); | 512 } while (GrBlendCoeffRefsDst(dst)); |
| 502 | 513 |
| 503 return GrPorterDuffXPFactory::Create(src, dst); | 514 return GrPorterDuffXPFactory::Create(src, dst); |
| 504 } | 515 } |
| 505 | 516 |
| OLD | NEW |