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

Side by Side Diff: src/gpu/effects/GrCoverageSetOpXP.cpp

Issue 1488213002: Add in shader blending for CoverageSetOp XP (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebased Created 5 years 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/effects/SkArithmeticMode_gpu.cpp ('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 "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 "glsl/GrGLSLBlend.h"
14 #include "glsl/GrGLSLProgramBuilder.h" 15 #include "glsl/GrGLSLProgramBuilder.h"
15 #include "glsl/GrGLSLFragmentShaderBuilder.h" 16 #include "glsl/GrGLSLFragmentShaderBuilder.h"
16 #include "glsl/GrGLSLXferProcessor.h" 17 #include "glsl/GrGLSLXferProcessor.h"
17 18
18 class CoverageSetOpXP : public GrXferProcessor { 19 class CoverageSetOpXP : public GrXferProcessor {
19 public: 20 public:
20 static GrXferProcessor* Create(SkRegion::Op regionOp, bool invertCoverage) { 21 static GrXferProcessor* Create(SkRegion::Op regionOp, bool invertCoverage) {
21 return new CoverageSetOpXP(regionOp, invertCoverage); 22 return new CoverageSetOpXP(regionOp, invertCoverage);
22 } 23 }
23 24
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 case SkRegion::kReverseDifference_Op: 140 case SkRegion::kReverseDifference_Op:
140 blendInfo->fSrcBlend = kIDC_GrBlendCoeff; 141 blendInfo->fSrcBlend = kIDC_GrBlendCoeff;
141 blendInfo->fDstBlend = kZero_GrBlendCoeff; 142 blendInfo->fDstBlend = kZero_GrBlendCoeff;
142 break; 143 break;
143 } 144 }
144 blendInfo->fBlendConstant = 0; 145 blendInfo->fBlendConstant = 0;
145 } 146 }
146 147
147 /////////////////////////////////////////////////////////////////////////////// 148 ///////////////////////////////////////////////////////////////////////////////
148 149
150 class ShaderCSOXferProcessor : public GrXferProcessor {
151 public:
152 ShaderCSOXferProcessor(const DstTexture* dstTexture,
153 bool hasMixedSamples,
154 SkXfermode::Mode xfermode,
155 SkRegion::Op regionOp,
156 bool invertCoverage)
157 : INHERITED(dstTexture, true, hasMixedSamples)
158 , fRegionOp(regionOp)
159 , fInvertCoverage(invertCoverage) {
160 this->initClassID<ShaderCSOXferProcessor>();
161 }
162
163 const char* name() const override { return "Coverage Set Op Shader"; }
164
165 GrGLSLXferProcessor* createGLSLInstance() const override;
166
167 SkRegion::Op regionOp() const { return fRegionOp; }
168 bool invertCoverage() const { return fInvertCoverage; }
169
170 private:
171 GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations&, bool, GrColor*,
172 const GrCaps&) const override {
173 // We never look at the color input
174 return GrXferProcessor::kIgnoreColor_OptFlag;
175 }
176
177 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override;
178
179 bool onIsEqual(const GrXferProcessor& xpBase) const override {
180 const ShaderCSOXferProcessor& xp = xpBase.cast<ShaderCSOXferProcessor>() ;
181 return (fRegionOp == xp.fRegionOp &&
182 fInvertCoverage == xp.fInvertCoverage);
183 }
184
185 SkRegion::Op fRegionOp;
186 bool fInvertCoverage;
187
188 typedef GrXferProcessor INHERITED;
189 };
190
191 ///////////////////////////////////////////////////////////////////////////////
192
193 class GLShaderCSOXferProcessor : public GrGLSLXferProcessor {
194 public:
195 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) {
196 const ShaderCSOXferProcessor& xp = processor.cast<ShaderCSOXferProcessor >();
197 b->add32(xp.regionOp());
198 uint32_t key = xp.invertCoverage() ? 0x0 : 0x1;
199 b->add32(key);
200 }
201
202 private:
203 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb,
204 GrGLSLXPFragmentBuilder* fragBuilder,
205 const char* srcColor,
206 const char* srcCoverage,
207 const char* dstColor,
208 const char* outColor,
209 const char* outColorSecondary,
210 const GrXferProcessor& proc) override {
211 const ShaderCSOXferProcessor& xp = proc.cast<ShaderCSOXferProcessor>();
212
213 if (xp.invertCoverage()) {
214 fragBuilder->codeAppendf("%s = 1.0 - %s;", outColor, srcCoverage);
215 } else {
216 fragBuilder->codeAppendf("%s = %s;", outColor, srcCoverage);
217 }
218
219 GrGLSLBlend::AppendRegionOp(fragBuilder, outColor, dstColor, outColor, x p.regionOp());
220 }
221
222 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over ride {}
223
224 typedef GrGLSLXferProcessor INHERITED;
225 };
226
227 ///////////////////////////////////////////////////////////////////////////////
228
229 void ShaderCSOXferProcessor::onGetGLSLProcessorKey(const GrGLSLCaps&,
230 GrProcessorKeyBuilder* b) con st {
231 GLShaderCSOXferProcessor::GenKey(*this, b);
232 }
233
234 GrGLSLXferProcessor* ShaderCSOXferProcessor::createGLSLInstance() const {
235 return new GLShaderCSOXferProcessor;
236 }
237
238 ///////////////////////////////////////////////////////////////////////////////
239 //
149 GrCoverageSetOpXPFactory::GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool i nvertCoverage) 240 GrCoverageSetOpXPFactory::GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool i nvertCoverage)
150 : fRegionOp(regionOp) 241 : fRegionOp(regionOp)
151 , fInvertCoverage(invertCoverage) { 242 , fInvertCoverage(invertCoverage) {
152 this->initClassID<GrCoverageSetOpXPFactory>(); 243 this->initClassID<GrCoverageSetOpXPFactory>();
153 } 244 }
154 245
155 GrXPFactory* GrCoverageSetOpXPFactory::Create(SkRegion::Op regionOp, bool invert Coverage) { 246 GrXPFactory* GrCoverageSetOpXPFactory::Create(SkRegion::Op regionOp, bool invert Coverage) {
156 switch (regionOp) { 247 switch (regionOp) {
157 case SkRegion::kReplace_Op: { 248 case SkRegion::kReplace_Op: {
158 if (invertCoverage) { 249 if (invertCoverage) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 333 }
243 334
244 GR_DEFINE_XP_FACTORY_TEST(GrCoverageSetOpXPFactory); 335 GR_DEFINE_XP_FACTORY_TEST(GrCoverageSetOpXPFactory);
245 336
246 const GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(GrProcessorTestData* d) { 337 const GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(GrProcessorTestData* d) {
247 SkRegion::Op regionOp = SkRegion::Op(d->fRandom->nextULessThan(SkRegion::kLa stOp + 1)); 338 SkRegion::Op regionOp = SkRegion::Op(d->fRandom->nextULessThan(SkRegion::kLa stOp + 1));
248 bool invertCoverage = !d->fRenderTarget->hasMixedSamples() && d->fRandom->ne xtBool(); 339 bool invertCoverage = !d->fRenderTarget->hasMixedSamples() && d->fRandom->ne xtBool();
249 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage); 340 return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage);
250 } 341 }
251 342
OLDNEW
« no previous file with comments | « src/effects/SkArithmeticMode_gpu.cpp ('k') | src/gpu/effects/GrCustomXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698