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

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

Issue 1434313002: Make all GrFragmentProcessors GL independent. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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/GrTextureDomain.cpp ('k') | src/gpu/effects/GrYUVtoRGBEffect.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 * Copyright 2015 Google Inc. 2 * Copyright 2015 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/GrXfermodeFragmentProcessor.h" 8 #include "effects/GrXfermodeFragmentProcessor.h"
9 9
10 #include "GrFragmentProcessor.h" 10 #include "GrFragmentProcessor.h"
11 #include "effects/GrConstColorProcessor.h" 11 #include "effects/GrConstColorProcessor.h"
12 #include "gl/GrGLFragmentProcessor.h" 12 #include "glsl/GrGLSLFragmentProcessor.h"
13 #include "gl/GrGLSLBlend.h" 13 #include "glsl/GrGLSLBlend.h"
14 #include "glsl/GrGLSLFragmentShaderBuilder.h" 14 #include "glsl/GrGLSLFragmentShaderBuilder.h"
15 #include "glsl/GrGLSLProgramBuilder.h" 15 #include "glsl/GrGLSLProgramBuilder.h"
16 #include "SkGrPriv.h" 16 #include "SkGrPriv.h"
17 17
18 class ComposeTwoFragmentProcessor : public GrFragmentProcessor { 18 class ComposeTwoFragmentProcessor : public GrFragmentProcessor {
19 public: 19 public:
20 ComposeTwoFragmentProcessor(const GrFragmentProcessor* src, const GrFragment Processor* dst, 20 ComposeTwoFragmentProcessor(const GrFragmentProcessor* src, const GrFragment Processor* dst,
21 SkXfermode::Mode mode) 21 SkXfermode::Mode mode)
22 : fMode(mode) { 22 : fMode(mode) {
23 this->initClassID<ComposeTwoFragmentProcessor>(); 23 this->initClassID<ComposeTwoFragmentProcessor>();
(...skipping 15 matching lines...) Expand all
39 bool onIsEqual(const GrFragmentProcessor& other) const override { 39 bool onIsEqual(const GrFragmentProcessor& other) const override {
40 const ComposeTwoFragmentProcessor& cs = other.cast<ComposeTwoFragmentPro cessor>(); 40 const ComposeTwoFragmentProcessor& cs = other.cast<ComposeTwoFragmentPro cessor>();
41 return fMode == cs.fMode; 41 return fMode == cs.fMode;
42 } 42 }
43 43
44 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 44 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
45 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); 45 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
46 } 46 }
47 47
48 private: 48 private:
49 GrGLFragmentProcessor* onCreateGLInstance() const override; 49 GrGLSLFragmentProcessor* onCreateGLInstance() const override;
50 50
51 SkXfermode::Mode fMode; 51 SkXfermode::Mode fMode;
52 52
53 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 53 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
54 54
55 typedef GrFragmentProcessor INHERITED; 55 typedef GrFragmentProcessor INHERITED;
56 }; 56 };
57 57
58 ///////////////////////////////////////////////////////////////////// 58 /////////////////////////////////////////////////////////////////////
59 59
60 class GLComposeTwoFragmentProcessor : public GrGLFragmentProcessor { 60 class GLComposeTwoFragmentProcessor : public GrGLSLFragmentProcessor {
61 public: 61 public:
62 GLComposeTwoFragmentProcessor(const GrProcessor& processor) {} 62 GLComposeTwoFragmentProcessor(const GrProcessor& processor) {}
63 63
64 void emitCode(EmitArgs&) override; 64 void emitCode(EmitArgs&) override;
65 65
66 private: 66 private:
67 typedef GrGLFragmentProcessor INHERITED; 67 typedef GrGLSLFragmentProcessor INHERITED;
68 }; 68 };
69 69
70 ///////////////////////////////////////////////////////////////////// 70 /////////////////////////////////////////////////////////////////////
71 71
72 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeTwoFragmentProcessor); 72 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeTwoFragmentProcessor);
73 73
74 const GrFragmentProcessor* ComposeTwoFragmentProcessor::TestCreate(GrProcessorTe stData* d) { 74 const GrFragmentProcessor* ComposeTwoFragmentProcessor::TestCreate(GrProcessorTe stData* d) {
75 // Create two random frag procs. 75 // Create two random frag procs.
76 SkAutoTUnref<const GrFragmentProcessor> fpA(GrProcessorUnitTest::CreateChild FP(d)); 76 SkAutoTUnref<const GrFragmentProcessor> fpA(GrProcessorUnitTest::CreateChild FP(d));
77 SkAutoTUnref<const GrFragmentProcessor> fpB(GrProcessorUnitTest::CreateChild FP(d)); 77 SkAutoTUnref<const GrFragmentProcessor> fpB(GrProcessorUnitTest::CreateChild FP(d));
78 78
79 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( 79 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(
80 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); 80 d->fRandom->nextRangeU(0, SkXfermode::kLastMode));
81 return new ComposeTwoFragmentProcessor(fpA, fpB, mode); 81 return new ComposeTwoFragmentProcessor(fpA, fpB, mode);
82 } 82 }
83 83
84 GrGLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLInstance() const{ 84 GrGLSLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLInstance() const {
85 return new GLComposeTwoFragmentProcessor(*this); 85 return new GLComposeTwoFragmentProcessor(*this);
86 } 86 }
87 87
88 ///////////////////////////////////////////////////////////////////// 88 /////////////////////////////////////////////////////////////////////
89 89
90 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { 90 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) {
91 91
92 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ; 92 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ;
93 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc essor>(); 93 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc essor>();
94 94
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 readsInput = GrInvariantOutput::kWill_ReadInput; 195 readsInput = GrInvariantOutput::kWill_ReadInput;
196 } 196 }
197 } 197 }
198 inout->setToOther(blendFlags, blendColor, readsInput); 198 inout->setToOther(blendFlags, blendColor, readsInput);
199 } else { 199 } else {
200 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); 200 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
201 } 201 }
202 } 202 }
203 203
204 private: 204 private:
205 GrGLFragmentProcessor* onCreateGLInstance() const override; 205 GrGLSLFragmentProcessor* onCreateGLInstance() const override;
206 206
207 SkXfermode::Mode fMode; 207 SkXfermode::Mode fMode;
208 Child fChild; 208 Child fChild;
209 209
210 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 210 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
211 211
212 typedef GrFragmentProcessor INHERITED; 212 typedef GrFragmentProcessor INHERITED;
213 }; 213 };
214 214
215 ////////////////////////////////////////////////////////////////////////////// 215 //////////////////////////////////////////////////////////////////////////////
216 216
217 class GLComposeOneFragmentProcessor : public GrGLFragmentProcessor { 217 class GLComposeOneFragmentProcessor : public GrGLSLFragmentProcessor {
218 public: 218 public:
219 GLComposeOneFragmentProcessor(const GrProcessor& processor) {} 219 GLComposeOneFragmentProcessor(const GrProcessor& processor) {}
220 220
221 void emitCode(EmitArgs& args) override { 221 void emitCode(EmitArgs& args) override {
222 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild er(); 222 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild er();
223 SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mod e(); 223 SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mod e();
224 ComposeOneFragmentProcessor::Child child = 224 ComposeOneFragmentProcessor::Child child =
225 args.fFp.cast<ComposeOneFragmentProcessor>().child(); 225 args.fFp.cast<ComposeOneFragmentProcessor>().child();
226 SkString childColor("child"); 226 SkString childColor("child");
227 this->emitChild(0, nullptr, &childColor, args); 227 this->emitChild(0, nullptr, &childColor, args);
228 228
229 const char* inputColor = args.fInputColor; 229 const char* inputColor = args.fInputColor;
230 // We don't try to optimize for this case at all 230 // We don't try to optimize for this case at all
231 if (!inputColor) { 231 if (!inputColor) {
232 fsBuilder->codeAppendf("const vec4 ones = vec4(1);"); 232 fsBuilder->codeAppendf("const vec4 ones = vec4(1);");
233 inputColor = "ones"; 233 inputColor = "ones";
234 } 234 }
235 235
236 // emit blend code 236 // emit blend code
237 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeNam e(mode)); 237 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeNam e(mode));
238 const char* childStr = childColor.c_str(); 238 const char* childStr = childColor.c_str();
239 if (ComposeOneFragmentProcessor::kDst_Child == child) { 239 if (ComposeOneFragmentProcessor::kDst_Child == child) {
240 GrGLSLBlend::AppendMode(fsBuilder, inputColor, childStr, args.fOutpu tColor, mode); 240 GrGLSLBlend::AppendMode(fsBuilder, inputColor, childStr, args.fOutpu tColor, mode);
241 } else { 241 } else {
242 GrGLSLBlend::AppendMode(fsBuilder, childStr, inputColor, args.fOutpu tColor, mode); 242 GrGLSLBlend::AppendMode(fsBuilder, childStr, inputColor, args.fOutpu tColor, mode);
243 } 243 }
244 } 244 }
245 245
246 private: 246 private:
247 typedef GrGLFragmentProcessor INHERITED; 247 typedef GrGLSLFragmentProcessor INHERITED;
248 }; 248 };
249 249
250 ///////////////////////////////////////////////////////////////////// 250 /////////////////////////////////////////////////////////////////////
251 251
252 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeOneFragmentProcessor); 252 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeOneFragmentProcessor);
253 253
254 const GrFragmentProcessor* ComposeOneFragmentProcessor::TestCreate(GrProcessorTe stData* d) { 254 const GrFragmentProcessor* ComposeOneFragmentProcessor::TestCreate(GrProcessorTe stData* d) {
255 // Create one random frag procs. 255 // Create one random frag procs.
256 // For now, we'll prevent either children from being a shader with children to prevent the 256 // For now, we'll prevent either children from being a shader with children to prevent the
257 // possibility of an arbitrarily large tree of procs. 257 // possibility of an arbitrarily large tree of procs.
258 SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChild FP(d)); 258 SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChild FP(d));
259 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( 259 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(
260 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); 260 d->fRandom->nextRangeU(0, SkXfermode::kLastMode));
261 ComposeOneFragmentProcessor::Child child = d->fRandom->nextBool() ? 261 ComposeOneFragmentProcessor::Child child = d->fRandom->nextBool() ?
262 ComposeOneFragmentProcessor::kDst_Child : 262 ComposeOneFragmentProcessor::kDst_Child :
263 ComposeOneFragmentProcessor::kSrc_Child; 263 ComposeOneFragmentProcessor::kSrc_Child;
264 return new ComposeOneFragmentProcessor(dst, mode, child); 264 return new ComposeOneFragmentProcessor(dst, mode, child);
265 } 265 }
266 266
267 GrGLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLInstance() const { 267 GrGLSLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLInstance() const {
268 return new GLComposeOneFragmentProcessor(*this); 268 return new GLComposeOneFragmentProcessor(*this);
269 } 269 }
270 270
271 ////////////////////////////////////////////////////////////////////////////// 271 //////////////////////////////////////////////////////////////////////////////
272 272
273 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromDstProcessor( 273 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromDstProcessor(
274 const GrFragmentProcessor* dst, SkXfermode::Mode mode) { 274 const GrFragmentProcessor* dst, SkXfermode::Mode mode) {
275 switch (mode) { 275 switch (mode) {
276 case SkXfermode::kClear_Mode: 276 case SkXfermode::kClear_Mode:
277 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, 277 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK,
(...skipping 12 matching lines...) Expand all
290 case SkXfermode::kClear_Mode: 290 case SkXfermode::kClear_Mode:
291 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, 291 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK,
292 GrConstColorProcessor::kIgnore_ InputMode); 292 GrConstColorProcessor::kIgnore_ InputMode);
293 case SkXfermode::kDst_Mode: 293 case SkXfermode::kDst_Mode:
294 return nullptr; 294 return nullptr;
295 default: 295 default:
296 return new ComposeOneFragmentProcessor(src, mode, 296 return new ComposeOneFragmentProcessor(src, mode,
297 ComposeOneFragmentProcessor:: kSrc_Child); 297 ComposeOneFragmentProcessor:: kSrc_Child);
298 } 298 }
299 } 299 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrTextureDomain.cpp ('k') | src/gpu/effects/GrYUVtoRGBEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698