OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "effects/GrCoverageSetOpXP.h" | 9 #include "effects/GrCoverageSetOpXP.h" |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
14 #include "gl/GrGLXferProcessor.h" | 14 #include "gl/GrGLXferProcessor.h" |
15 #include "gl/builders/GrGLFragmentShaderBuilder.h" | 15 #include "gl/builders/GrGLFragmentShaderBuilder.h" |
16 #include "gl/builders/GrGLProgramBuilder.h" | 16 #include "gl/builders/GrGLProgramBuilder.h" |
17 | 17 |
18 class CoverageSetOpXP : public GrXferProcessor { | 18 class CoverageSetOpXP : public GrXferProcessor { |
19 public: | 19 public: |
20 static GrXferProcessor* Create(SkRegion::Op regionOp, bool invertCoverage) { | 20 static GrXferProcessor* Create(SkRegion::Op regionOp, bool invertCoverage) { |
21 return SkNEW_ARGS(CoverageSetOpXP, (regionOp, invertCoverage)); | 21 return SkNEW_ARGS(CoverageSetOpXP, (regionOp, invertCoverage)); |
22 } | 22 } |
23 | 23 |
24 ~CoverageSetOpXP() override; | 24 ~CoverageSetOpXP() override; |
25 | 25 |
26 const char* name() const override { return "Coverage Set Op"; } | 26 const char* name() const override { return "Coverage Set Op"; } |
27 | 27 |
28 GrGLXferProcessor* createGLInstance() const override; | 28 GrGLXferProcessor* createGLInstance() const override; |
29 | 29 |
30 bool hasSecondaryOutput() const override { return false; } | |
31 | |
32 bool invertCoverage() const { return fInvertCoverage; } | 30 bool invertCoverage() const { return fInvertCoverage; } |
33 | 31 |
34 private: | 32 private: |
35 CoverageSetOpXP(SkRegion::Op regionOp, bool fInvertCoverage); | 33 CoverageSetOpXP(SkRegion::Op regionOp, bool fInvertCoverage); |
36 | 34 |
37 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 35 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
38 const GrProcOptInfo& coveragePO
I, | 36 const GrProcOptInfo& coveragePO
I, |
39 bool doesStencilWrite, | 37 bool doesStencilWrite, |
40 GrColor* color, | 38 GrColor* color, |
41 const GrCaps& caps) override; | 39 const GrCaps& caps) override; |
(...skipping 23 matching lines...) Expand all Loading... |
65 ~GLCoverageSetOpXP() override {} | 63 ~GLCoverageSetOpXP() override {} |
66 | 64 |
67 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, | 65 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
68 GrProcessorKeyBuilder* b) { | 66 GrProcessorKeyBuilder* b) { |
69 const CoverageSetOpXP& xp = processor.cast<CoverageSetOpXP>(); | 67 const CoverageSetOpXP& xp = processor.cast<CoverageSetOpXP>(); |
70 uint32_t key = xp.invertCoverage() ? 0x0 : 0x1; | 68 uint32_t key = xp.invertCoverage() ? 0x0 : 0x1; |
71 b->add32(key); | 69 b->add32(key); |
72 }; | 70 }; |
73 | 71 |
74 private: | 72 private: |
75 void onEmitCode(const EmitArgs& args) override { | 73 void emitOutputsForBlendState(const EmitArgs& args) override { |
76 const CoverageSetOpXP& xp = args.fXP.cast<CoverageSetOpXP>(); | 74 const CoverageSetOpXP& xp = args.fXP.cast<CoverageSetOpXP>(); |
77 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 75 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
78 | 76 |
79 if (xp.invertCoverage()) { | 77 if (xp.invertCoverage()) { |
80 fsBuilder->codeAppendf("%s = 1.0 - %s;", args.fOutputPrimary, args.f
InputCoverage); | 78 fsBuilder->codeAppendf("%s = 1.0 - %s;", args.fOutputPrimary, args.f
InputCoverage); |
81 } else { | 79 } else { |
82 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
overage); | 80 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
overage); |
83 } | 81 } |
84 } | 82 } |
85 | 83 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 238 |
241 GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(SkRandom* random, | 239 GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(SkRandom* random, |
242 GrContext*, | 240 GrContext*, |
243 const GrCaps&, | 241 const GrCaps&, |
244 GrTexture*[]) { | 242 GrTexture*[]) { |
245 SkRegion::Op regionOp = SkRegion::Op(random->nextULessThan(SkRegion::kLastOp
+ 1)); | 243 SkRegion::Op regionOp = SkRegion::Op(random->nextULessThan(SkRegion::kLastOp
+ 1)); |
246 bool invertCoverage = random->nextBool(); | 244 bool invertCoverage = random->nextBool(); |
247 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage); | 245 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage); |
248 } | 246 } |
249 | 247 |
OLD | NEW |