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 "GrColor.h" | 10 #include "GrColor.h" |
11 #include "GrDrawTargetCaps.h" | 11 #include "GrDrawTargetCaps.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 GrGLCoverageSetOpXP : public GrGLXferProcessor { | 18 class GrGLCoverageSetOpXP : public GrGLXferProcessor { |
19 public: | 19 public: |
20 GrGLCoverageSetOpXP(const GrProcessor&) {} | 20 GrGLCoverageSetOpXP(const GrProcessor&) {} |
21 | 21 |
22 ~GrGLCoverageSetOpXP() SK_OVERRIDE {} | 22 ~GrGLCoverageSetOpXP() SK_OVERRIDE {} |
23 | 23 |
| 24 void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 25 const GrCoverageSetOpXP& xp = args.fXP.cast<GrCoverageSetOpXP>(); |
| 26 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 27 |
| 28 if (xp.invertCoverage()) { |
| 29 fsBuilder->codeAppendf("%s = 1.0 - %s;", args.fOutputPrimary, args.f
InputCoverage); |
| 30 } else { |
| 31 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
overage); |
| 32 } |
| 33 } |
| 34 |
| 35 void setData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVERR
IDE {}; |
| 36 |
24 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, | 37 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, |
25 GrProcessorKeyBuilder* b) { | 38 GrProcessorKeyBuilder* b) { |
26 const GrCoverageSetOpXP& xp = processor.cast<GrCoverageSetOpXP>(); | 39 const GrCoverageSetOpXP& xp = processor.cast<GrCoverageSetOpXP>(); |
27 uint32_t key = xp.invertCoverage() ? 0x0 : 0x1; | 40 uint32_t key = xp.invertCoverage() ? 0x0 : 0x1; |
28 b->add32(key); | 41 b->add32(key); |
29 }; | 42 }; |
30 | 43 |
31 private: | 44 private: |
32 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { | |
33 const GrCoverageSetOpXP& xp = args.fXP.cast<GrCoverageSetOpXP>(); | |
34 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | |
35 | |
36 if (xp.invertCoverage()) { | |
37 fsBuilder->codeAppendf("%s = 1.0 - %s;", args.fOutputPrimary, args.f
InputCoverage); | |
38 } else { | |
39 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
overage); | |
40 } | |
41 } | |
42 | |
43 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE
RRIDE {}; | |
44 | |
45 typedef GrGLXferProcessor INHERITED; | 45 typedef GrGLXferProcessor INHERITED; |
46 }; | 46 }; |
47 | 47 |
48 /////////////////////////////////////////////////////////////////////////////// | 48 /////////////////////////////////////////////////////////////////////////////// |
49 | 49 |
50 GrCoverageSetOpXP::GrCoverageSetOpXP(SkRegion::Op regionOp, bool invertCoverage) | 50 GrCoverageSetOpXP::GrCoverageSetOpXP(SkRegion::Op regionOp, bool invertCoverage) |
51 : fRegionOp(regionOp) | 51 : fRegionOp(regionOp) |
52 , fInvertCoverage(invertCoverage) { | 52 , fInvertCoverage(invertCoverage) { |
53 this->initClassID<GrCoverageSetOpXP>(); | 53 this->initClassID<GrCoverageSetOpXP>(); |
54 } | 54 } |
55 | 55 |
56 GrCoverageSetOpXP::~GrCoverageSetOpXP() { | 56 GrCoverageSetOpXP::~GrCoverageSetOpXP() { |
57 } | 57 } |
58 | 58 |
59 void GrCoverageSetOpXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKey
Builder* b) const { | 59 void GrCoverageSetOpXP::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBu
ilder* b) const { |
60 GrGLCoverageSetOpXP::GenKey(*this, caps, b); | 60 GrGLCoverageSetOpXP::GenKey(*this, caps, b); |
61 } | 61 } |
62 | 62 |
63 GrGLXferProcessor* GrCoverageSetOpXP::createGLInstance() const { | 63 GrGLXferProcessor* GrCoverageSetOpXP::createGLInstance() const { |
64 return SkNEW_ARGS(GrGLCoverageSetOpXP, (*this)); | 64 return SkNEW_ARGS(GrGLCoverageSetOpXP, (*this)); |
65 } | 65 } |
66 | 66 |
67 GrXferProcessor::OptFlags | 67 GrXferProcessor::OptFlags |
68 GrCoverageSetOpXP::getOptimizations(const GrProcOptInfo& colorPOI, | 68 GrCoverageSetOpXP::getOptimizations(const GrProcOptInfo& colorPOI, |
69 const GrProcOptInfo& coveragePOI, | 69 const GrProcOptInfo& coveragePOI, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 static GrCoverageSetOpXPFactory gRevDiffCDXPF(regionOp, invertCo
verage); | 172 static GrCoverageSetOpXPFactory gRevDiffCDXPF(regionOp, invertCo
verage); |
173 return SkRef(&gRevDiffCDXPF); | 173 return SkRef(&gRevDiffCDXPF); |
174 } | 174 } |
175 break; | 175 break; |
176 } | 176 } |
177 default: | 177 default: |
178 return NULL; | 178 return NULL; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 GrXferProcessor* | 182 GrXferProcessor* GrCoverageSetOpXPFactory::createXferProcessor(const GrProcOptIn
fo& /* colorPOI*/, |
183 GrCoverageSetOpXPFactory::onCreateXferProcessor(const GrProcOptInfo& colorPOI, | 183 const GrProcOptIn
fo& covPOI) const { |
184 const GrProcOptInfo& covPOI, | |
185 const GrDeviceCoordTexture* dstC
opy) const { | |
186 return GrCoverageSetOpXP::Create(fRegionOp, fInvertCoverage); | 184 return GrCoverageSetOpXP::Create(fRegionOp, fInvertCoverage); |
187 } | 185 } |
188 | 186 |
189 void GrCoverageSetOpXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, | 187 void GrCoverageSetOpXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, |
190 const GrProcOptInfo& coverageP
OI, | 188 const GrProcOptInfo& coverageP
OI, |
191 GrXPFactory::InvariantOutput*
output) const { | 189 GrXPFactory::InvariantOutput*
output) const { |
192 if (SkRegion::kReplace_Op == fRegionOp) { | 190 if (SkRegion::kReplace_Op == fRegionOp) { |
193 if (coveragePOI.isSolidWhite()) { | 191 if (coveragePOI.isSolidWhite()) { |
194 output->fBlendedColor = GrColor_WHITE; | 192 output->fBlendedColor = GrColor_WHITE; |
195 output->fBlendedColorFlags = kRGBA_GrColorComponentFlags; | 193 output->fBlendedColorFlags = kRGBA_GrColorComponentFlags; |
(...skipping 12 matching lines...) Expand all Loading... |
208 | 206 |
209 GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(SkRandom* random, | 207 GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(SkRandom* random, |
210 GrContext*, | 208 GrContext*, |
211 const GrDrawTargetCaps&, | 209 const GrDrawTargetCaps&, |
212 GrTexture*[]) { | 210 GrTexture*[]) { |
213 SkRegion::Op regionOp = SkRegion::Op(random->nextULessThan(SkRegion::kLastOp
+ 1)); | 211 SkRegion::Op regionOp = SkRegion::Op(random->nextULessThan(SkRegion::kLastOp
+ 1)); |
214 bool invertCoverage = random->nextBool(); | 212 bool invertCoverage = random->nextBool(); |
215 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage); | 213 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage); |
216 } | 214 } |
217 | 215 |
OLD | NEW |