| 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 class PorterDuffXferProcessor : public GrXferProcessor { | 35 class PorterDuffXferProcessor : public GrXferProcessor { |
| 36 public: | 36 public: |
| 37 static GrXferProcessor* Create(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, | 37 static GrXferProcessor* Create(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, |
| 38 GrColor constant, const GrDeviceCoordTexture*
dstCopy, | 38 GrColor constant, const GrDeviceCoordTexture*
dstCopy, |
| 39 bool willReadDstColor) { | 39 bool willReadDstColor) { |
| 40 return SkNEW_ARGS(PorterDuffXferProcessor, (srcBlend, dstBlend, constant
, dstCopy, | 40 return SkNEW_ARGS(PorterDuffXferProcessor, (srcBlend, dstBlend, constant
, dstCopy, |
| 41 willReadDstColor)); | 41 willReadDstColor)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ~PorterDuffXferProcessor() SK_OVERRIDE; | 44 ~PorterDuffXferProcessor() override; |
| 45 | 45 |
| 46 const char* name() const SK_OVERRIDE { return "Porter Duff"; } | 46 const char* name() const override { return "Porter Duff"; } |
| 47 | 47 |
| 48 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE; | 48 GrGLXferProcessor* createGLInstance() const override; |
| 49 | 49 |
| 50 bool hasSecondaryOutput() const SK_OVERRIDE; | 50 bool hasSecondaryOutput() const override; |
| 51 | 51 |
| 52 /////////////////////////////////////////////////////////////////////////// | 52 /////////////////////////////////////////////////////////////////////////// |
| 53 /// @name Stage Output Types | 53 /// @name Stage Output Types |
| 54 //// | 54 //// |
| 55 | 55 |
| 56 enum PrimaryOutputType { | 56 enum PrimaryOutputType { |
| 57 kNone_PrimaryOutputType, | 57 kNone_PrimaryOutputType, |
| 58 kColor_PrimaryOutputType, | 58 kColor_PrimaryOutputType, |
| 59 kCoverage_PrimaryOutputType, | 59 kCoverage_PrimaryOutputType, |
| 60 // Modulate color and coverage, write result as the color output. | 60 // Modulate color and coverage, write result as the color output. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 81 kSecondaryOutputTypeCnt, | 81 kSecondaryOutputTypeCnt, |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 PrimaryOutputType primaryOutputType() const { return fPrimaryOutputType; } | 84 PrimaryOutputType primaryOutputType() const { return fPrimaryOutputType; } |
| 85 SecondaryOutputType secondaryOutputType() const { return fSecondaryOutputTyp
e; } | 85 SecondaryOutputType secondaryOutputType() const { return fSecondaryOutputTyp
e; } |
| 86 | 86 |
| 87 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, | 87 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, |
| 88 const GrProcOptInfo& coveragePOI, | 88 const GrProcOptInfo& coveragePOI, |
| 89 bool doesStencilWrite, | 89 bool doesStencilWrite, |
| 90 GrColor* overrideColor, | 90 GrColor* overrideColor, |
| 91 const GrDrawTargetCaps& caps) SK_
OVERRIDE; | 91 const GrDrawTargetCaps& caps) ove
rride; |
| 92 | 92 |
| 93 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE { | 93 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { |
| 94 if (!this->willReadDstColor()) { | 94 if (!this->willReadDstColor()) { |
| 95 blendInfo->fSrcBlend = fSrcBlend; | 95 blendInfo->fSrcBlend = fSrcBlend; |
| 96 blendInfo->fDstBlend = fDstBlend; | 96 blendInfo->fDstBlend = fDstBlend; |
| 97 } else { | 97 } else { |
| 98 blendInfo->fSrcBlend = kOne_GrBlendCoeff; | 98 blendInfo->fSrcBlend = kOne_GrBlendCoeff; |
| 99 blendInfo->fDstBlend = kZero_GrBlendCoeff; | 99 blendInfo->fDstBlend = kZero_GrBlendCoeff; |
| 100 } | 100 } |
| 101 blendInfo->fBlendConstant = fBlendConstant; | 101 blendInfo->fBlendConstant = fBlendConstant; |
| 102 } | 102 } |
| 103 | 103 |
| 104 GrBlendCoeff getSrcBlend() const { return fSrcBlend; } | 104 GrBlendCoeff getSrcBlend() const { return fSrcBlend; } |
| 105 GrBlendCoeff getDstBlend() const { return fDstBlend; } | 105 GrBlendCoeff getDstBlend() const { return fDstBlend; } |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 PorterDuffXferProcessor(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, GrColo
r constant, | 108 PorterDuffXferProcessor(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, GrColo
r constant, |
| 109 const GrDeviceCoordTexture* dstCopy, bool willReadDs
tColor); | 109 const GrDeviceCoordTexture* dstCopy, bool willReadDs
tColor); |
| 110 | 110 |
| 111 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st SK_OVERRIDE; | 111 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st override; |
| 112 | 112 |
| 113 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE { | 113 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
| 114 const PorterDuffXferProcessor& xp = xpBase.cast<PorterDuffXferProcessor>
(); | 114 const PorterDuffXferProcessor& xp = xpBase.cast<PorterDuffXferProcessor>
(); |
| 115 if (fSrcBlend != xp.fSrcBlend || | 115 if (fSrcBlend != xp.fSrcBlend || |
| 116 fDstBlend != xp.fDstBlend || | 116 fDstBlend != xp.fDstBlend || |
| 117 fBlendConstant != xp.fBlendConstant || | 117 fBlendConstant != xp.fBlendConstant || |
| 118 fPrimaryOutputType != xp.fPrimaryOutputType || | 118 fPrimaryOutputType != xp.fPrimaryOutputType || |
| 119 fSecondaryOutputType != xp.fSecondaryOutputType) { | 119 fSecondaryOutputType != xp.fSecondaryOutputType) { |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); | 195 const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcess
or>(); |
| 196 b->add32(xp.primaryOutputType()); | 196 b->add32(xp.primaryOutputType()); |
| 197 b->add32(xp.secondaryOutputType()); | 197 b->add32(xp.secondaryOutputType()); |
| 198 if (xp.willReadDstColor()) { | 198 if (xp.willReadDstColor()) { |
| 199 b->add32(xp.getSrcBlend()); | 199 b->add32(xp.getSrcBlend()); |
| 200 b->add32(xp.getDstBlend()); | 200 b->add32(xp.getDstBlend()); |
| 201 } | 201 } |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 private: | 204 private: |
| 205 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { | 205 void onEmitCode(const EmitArgs& args) override { |
| 206 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); | 206 const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcesso
r>(); |
| 207 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 207 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 208 if (PorterDuffXferProcessor::kCustom_PrimaryOutputType != xp.primaryOutp
utType()) { | 208 if (PorterDuffXferProcessor::kCustom_PrimaryOutputType != xp.primaryOutp
utType()) { |
| 209 SkASSERT(!xp.willReadDstColor()); | 209 SkASSERT(!xp.willReadDstColor()); |
| 210 switch(xp.secondaryOutputType()) { | 210 switch(xp.secondaryOutputType()) { |
| 211 case PorterDuffXferProcessor::kNone_SecondaryOutputType: | 211 case PorterDuffXferProcessor::kNone_SecondaryOutputType: |
| 212 break; | 212 break; |
| 213 case PorterDuffXferProcessor::kCoverage_SecondaryOutputType: | 213 case PorterDuffXferProcessor::kCoverage_SecondaryOutputType: |
| 214 fsBuilder->codeAppendf("%s = %s;", args.fOutputSecondary, | 214 fsBuilder->codeAppendf("%s = %s;", args.fOutputSecondary, |
| 215 args.fInputCoverage); | 215 args.fInputCoverage); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 dstColor, args.fInputColor, | 260 dstColor, args.fInputColor, |
| 261 dstColor, didAppend)); | 261 dstColor, didAppend)); |
| 262 fsBuilder->codeAppend(";"); | 262 fsBuilder->codeAppend(";"); |
| 263 | 263 |
| 264 fsBuilder->codeAppendf("%s = %s * colorBlend + (vec4(1.0) - %s) * %s
;", | 264 fsBuilder->codeAppendf("%s = %s * colorBlend + (vec4(1.0) - %s) * %s
;", |
| 265 args.fOutputPrimary, args.fInputCoverage, arg
s.fInputCoverage, | 265 args.fOutputPrimary, args.fInputCoverage, arg
s.fInputCoverage, |
| 266 dstColor); | 266 dstColor); |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE
RRIDE {}; | 270 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri
de {}; |
| 271 | 271 |
| 272 typedef GrGLXferProcessor INHERITED; | 272 typedef GrGLXferProcessor INHERITED; |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 /////////////////////////////////////////////////////////////////////////////// | 275 /////////////////////////////////////////////////////////////////////////////// |
| 276 | 276 |
| 277 PorterDuffXferProcessor::PorterDuffXferProcessor(GrBlendCoeff srcBlend, | 277 PorterDuffXferProcessor::PorterDuffXferProcessor(GrBlendCoeff srcBlend, |
| 278 GrBlendCoeff dstBlend, | 278 GrBlendCoeff dstBlend, |
| 279 GrColor constant, | 279 GrColor constant, |
| 280 const GrDeviceCoordTexture* dst
Copy, | 280 const GrDeviceCoordTexture* dst
Copy, |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); | 700 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
| 701 | 701 |
| 702 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, | 702 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, |
| 703 GrContext*, | 703 GrContext*, |
| 704 const GrDrawTargetCaps&, | 704 const GrDrawTargetCaps&, |
| 705 GrTexture*[]) { | 705 GrTexture*[]) { |
| 706 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k
LastCoeffMode)); | 706 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k
LastCoeffMode)); |
| 707 return GrPorterDuffXPFactory::Create(mode); | 707 return GrPorterDuffXPFactory::Create(mode); |
| 708 } | 708 } |
| 709 | 709 |
| OLD | NEW |