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

Side by Side Diff: src/gpu/effects/GrCoverageSetOpXP.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.h ('k') | src/gpu/effects/GrCustomXfermode.cpp » ('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 /* 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 /**
19 * This xfer processor directly blends the the src coverage with the dst using a set operator. It is
20 * useful for rendering coverage masks using CSG. It can optionally invert the s rc coverage before
21 * applying the set operator.
22 * */
23 class CoverageSetOpXP : public GrXferProcessor {
19 public: 24 public:
20 GrGLCoverageSetOpXP(const GrProcessor&) {} 25 static GrXferProcessor* Create(SkRegion::Op regionOp, bool invertCoverage) {
26 return SkNEW_ARGS(CoverageSetOpXP, (regionOp, invertCoverage));
27 }
21 28
22 ~GrGLCoverageSetOpXP() SK_OVERRIDE {} 29 ~CoverageSetOpXP() SK_OVERRIDE;
30
31 const char* name() const SK_OVERRIDE { return "Coverage Set Op"; }
32
33 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE;
34
35 bool hasSecondaryOutput() const SK_OVERRIDE { return false; }
36
37 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI,
38 const GrProcOptInfo& coveragePOI,
39 bool doesStencilWrite,
40 GrColor* color,
41 const GrDrawTargetCaps& caps) SK_ OVERRIDE;
42
43 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE;
44
45 bool invertCoverage() const { return fInvertCoverage; }
46
47 private:
48 CoverageSetOpXP(SkRegion::Op regionOp, bool fInvertCoverage);
49
50 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con st SK_OVERRIDE;
51
52 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE {
53 const CoverageSetOpXP& xp = xpBase.cast<CoverageSetOpXP>();
54 return (fRegionOp == xp.fRegionOp &&
55 fInvertCoverage == xp.fInvertCoverage);
56 }
57
58 SkRegion::Op fRegionOp;
59 bool fInvertCoverage;
60
61 typedef GrXferProcessor INHERITED;
62 };
63
64 ///////////////////////////////////////////////////////////////////////////////
65
66 class GLCoverageSetOpXP : public GrGLXferProcessor {
67 public:
68 GLCoverageSetOpXP(const GrProcessor&) {}
69
70 ~GLCoverageSetOpXP() SK_OVERRIDE {}
23 71
24 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, 72 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps,
25 GrProcessorKeyBuilder* b) { 73 GrProcessorKeyBuilder* b) {
26 const GrCoverageSetOpXP& xp = processor.cast<GrCoverageSetOpXP>(); 74 const CoverageSetOpXP& xp = processor.cast<CoverageSetOpXP>();
27 uint32_t key = xp.invertCoverage() ? 0x0 : 0x1; 75 uint32_t key = xp.invertCoverage() ? 0x0 : 0x1;
28 b->add32(key); 76 b->add32(key);
29 }; 77 };
30 78
31 private: 79 private:
32 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { 80 void onEmitCode(const EmitArgs& args) SK_OVERRIDE {
33 const GrCoverageSetOpXP& xp = args.fXP.cast<GrCoverageSetOpXP>(); 81 const CoverageSetOpXP& xp = args.fXP.cast<CoverageSetOpXP>();
34 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 82 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
35 83
36 if (xp.invertCoverage()) { 84 if (xp.invertCoverage()) {
37 fsBuilder->codeAppendf("%s = 1.0 - %s;", args.fOutputPrimary, args.f InputCoverage); 85 fsBuilder->codeAppendf("%s = 1.0 - %s;", args.fOutputPrimary, args.f InputCoverage);
38 } else { 86 } else {
39 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC overage); 87 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC overage);
40 } 88 }
41 } 89 }
42 90
43 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE RRIDE {}; 91 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) SK_OVE RRIDE {};
44 92
45 typedef GrGLXferProcessor INHERITED; 93 typedef GrGLXferProcessor INHERITED;
46 }; 94 };
47 95
48 /////////////////////////////////////////////////////////////////////////////// 96 ///////////////////////////////////////////////////////////////////////////////
49 97
50 GrCoverageSetOpXP::GrCoverageSetOpXP(SkRegion::Op regionOp, bool invertCoverage) 98 CoverageSetOpXP::CoverageSetOpXP(SkRegion::Op regionOp, bool invertCoverage)
51 : fRegionOp(regionOp) 99 : fRegionOp(regionOp)
52 , fInvertCoverage(invertCoverage) { 100 , fInvertCoverage(invertCoverage) {
53 this->initClassID<GrCoverageSetOpXP>(); 101 this->initClassID<CoverageSetOpXP>();
54 } 102 }
55 103
56 GrCoverageSetOpXP::~GrCoverageSetOpXP() { 104 CoverageSetOpXP::~CoverageSetOpXP() {
57 } 105 }
58 106
59 void GrCoverageSetOpXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKey Builder* b) const { 107 void CoverageSetOpXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBu ilder* b) const {
60 GrGLCoverageSetOpXP::GenKey(*this, caps, b); 108 GLCoverageSetOpXP::GenKey(*this, caps, b);
61 } 109 }
62 110
63 GrGLXferProcessor* GrCoverageSetOpXP::createGLInstance() const { 111 GrGLXferProcessor* CoverageSetOpXP::createGLInstance() const {
64 return SkNEW_ARGS(GrGLCoverageSetOpXP, (*this)); 112 return SkNEW_ARGS(GLCoverageSetOpXP, (*this));
65 } 113 }
66 114
67 GrXferProcessor::OptFlags 115 GrXferProcessor::OptFlags
68 GrCoverageSetOpXP::getOptimizations(const GrProcOptInfo& colorPOI, 116 CoverageSetOpXP::getOptimizations(const GrProcOptInfo& colorPOI,
69 const GrProcOptInfo& coveragePOI, 117 const GrProcOptInfo& coveragePOI,
70 bool doesStencilWrite, 118 bool doesStencilWrite,
71 GrColor* color, 119 GrColor* color,
72 const GrDrawTargetCaps& caps) { 120 const GrDrawTargetCaps& caps) {
73 // We never look at the color input 121 // We never look at the color input
74 return GrXferProcessor::kIgnoreColor_OptFlag; 122 return GrXferProcessor::kIgnoreColor_OptFlag;
75 } 123 }
76 124
77 void GrCoverageSetOpXP::getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) cons t { 125 void CoverageSetOpXP::getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const {
78 switch (fRegionOp) { 126 switch (fRegionOp) {
79 case SkRegion::kReplace_Op: 127 case SkRegion::kReplace_Op:
80 blendInfo->fSrcBlend = kOne_GrBlendCoeff; 128 blendInfo->fSrcBlend = kOne_GrBlendCoeff;
81 blendInfo->fDstBlend = kZero_GrBlendCoeff; 129 blendInfo->fDstBlend = kZero_GrBlendCoeff;
82 break; 130 break;
83 case SkRegion::kIntersect_Op: 131 case SkRegion::kIntersect_Op:
84 blendInfo->fSrcBlend = kDC_GrBlendCoeff; 132 blendInfo->fSrcBlend = kDC_GrBlendCoeff;
85 blendInfo->fDstBlend = kZero_GrBlendCoeff; 133 blendInfo->fDstBlend = kZero_GrBlendCoeff;
86 break; 134 break;
87 case SkRegion::kUnion_Op: 135 case SkRegion::kUnion_Op:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 224 }
177 default: 225 default:
178 return NULL; 226 return NULL;
179 } 227 }
180 } 228 }
181 229
182 GrXferProcessor* 230 GrXferProcessor*
183 GrCoverageSetOpXPFactory::onCreateXferProcessor(const GrProcOptInfo& colorPOI, 231 GrCoverageSetOpXPFactory::onCreateXferProcessor(const GrProcOptInfo& colorPOI,
184 const GrProcOptInfo& covPOI, 232 const GrProcOptInfo& covPOI,
185 const GrDeviceCoordTexture* dstC opy) const { 233 const GrDeviceCoordTexture* dstC opy) const {
186 return GrCoverageSetOpXP::Create(fRegionOp, fInvertCoverage); 234 return CoverageSetOpXP::Create(fRegionOp, fInvertCoverage);
187 } 235 }
188 236
189 void GrCoverageSetOpXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, 237 void GrCoverageSetOpXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI,
190 const GrProcOptInfo& coverageP OI, 238 const GrProcOptInfo& coverageP OI,
191 GrXPFactory::InvariantOutput* output) const { 239 GrXPFactory::InvariantOutput* output) const {
192 if (SkRegion::kReplace_Op == fRegionOp) { 240 if (SkRegion::kReplace_Op == fRegionOp) {
193 if (coveragePOI.isSolidWhite()) { 241 if (coveragePOI.isSolidWhite()) {
194 output->fBlendedColor = GrColor_WHITE; 242 output->fBlendedColor = GrColor_WHITE;
195 output->fBlendedColorFlags = kRGBA_GrColorComponentFlags; 243 output->fBlendedColorFlags = kRGBA_GrColorComponentFlags;
196 } else { 244 } else {
(...skipping 11 matching lines...) Expand all
208 256
209 GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(SkRandom* random, 257 GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(SkRandom* random,
210 GrContext*, 258 GrContext*,
211 const GrDrawTargetCaps&, 259 const GrDrawTargetCaps&,
212 GrTexture*[]) { 260 GrTexture*[]) {
213 SkRegion::Op regionOp = SkRegion::Op(random->nextULessThan(SkRegion::kLastOp + 1)); 261 SkRegion::Op regionOp = SkRegion::Op(random->nextULessThan(SkRegion::kLastOp + 1));
214 bool invertCoverage = random->nextBool(); 262 bool invertCoverage = random->nextBool();
215 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage); 263 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage);
216 } 264 }
217 265
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCoverageSetOpXP.h ('k') | src/gpu/effects/GrCustomXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698