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

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

Issue 1362873002: Mangle output var in GrGLFragmentProcessor::emitChild (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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/effects/SkArithmeticMode_gpu.cpp ('k') | src/gpu/gl/GrGLFragmentProcessor.h » ('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"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const char* inputAlpha = nullptr; 99 const char* inputAlpha = nullptr;
100 if (args.fInputColor) { 100 if (args.fInputColor) {
101 inputAlpha = "inputAlpha"; 101 inputAlpha = "inputAlpha";
102 opaqueInput = "opaqueInput"; 102 opaqueInput = "opaqueInput";
103 fsBuilder->codeAppendf("float inputAlpha = %s.a;", args.fInputColor); 103 fsBuilder->codeAppendf("float inputAlpha = %s.a;", args.fInputColor);
104 fsBuilder->codeAppendf("vec4 opaqueInput = vec4(%s.rgb / inputAlpha, 1); ", 104 fsBuilder->codeAppendf("vec4 opaqueInput = vec4(%s.rgb / inputAlpha, 1); ",
105 args.fInputColor); 105 args.fInputColor);
106 } 106 }
107 107
108 // declare outputColor and emit the code for each of the two children 108 // declare outputColor and emit the code for each of the two children
109 SkString outputColorSrc(args.fOutputColor); 109 SkString srcColor("src");
110 outputColorSrc.append("_src"); 110 this->emitChild(0, opaqueInput, &srcColor, args);
111 fsBuilder->codeAppendf("vec4 %s;\n", outputColorSrc.c_str());
112 this->emitChild(0, opaqueInput, outputColorSrc.c_str(), args);
113 111
114 SkString outputColorDst(args.fOutputColor); 112 SkString dstColor("dst");
115 outputColorDst.append("_dst"); 113 this->emitChild(1, opaqueInput, &dstColor, args);
116 fsBuilder->codeAppendf("vec4 %s;\n", outputColorDst.c_str());
117 this->emitChild(1, opaqueInput, outputColorDst.c_str(), args);
118 114
119 // emit blend code 115 // emit blend code
120 SkXfermode::Mode mode = cs.getMode(); 116 SkXfermode::Mode mode = cs.getMode();
121 fsBuilder->codeAppend("{");
122 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mo de)); 117 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mo de));
123 GrGLSLBlend::AppendMode(fsBuilder, outputColorSrc.c_str(), 118 GrGLSLBlend::AppendMode(fsBuilder, srcColor.c_str(), dstColor.c_str(), args. fOutputColor, mode);
124 outputColorDst.c_str(), args.fOutputColor, mode);
125 fsBuilder->codeAppend("}");
126 119
127 // re-multiply the output color by the input color's alpha 120 // re-multiply the output color by the input color's alpha
128 if (inputAlpha) { 121 if (inputAlpha) {
129 fsBuilder->codeAppendf("%s *= %s;", args.fOutputColor, inputAlpha); 122 fsBuilder->codeAppendf("%s *= %s;", args.fOutputColor, inputAlpha);
130 } 123 }
131 } 124 }
132 125
133 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromTwoProcessors( 126 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromTwoProcessors(
134 const GrFragmentProcessor* src, const GrFragmentProcessor* dst, SkXferm ode::Mode mode) { 127 const GrFragmentProcessor* src, const GrFragmentProcessor* dst, SkXferm ode::Mode mode) {
135 switch (mode) { 128 switch (mode) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 223
231 class GLComposeOneFragmentProcessor : public GrGLFragmentProcessor { 224 class GLComposeOneFragmentProcessor : public GrGLFragmentProcessor {
232 public: 225 public:
233 GLComposeOneFragmentProcessor(const GrProcessor& processor) {} 226 GLComposeOneFragmentProcessor(const GrProcessor& processor) {}
234 227
235 void emitCode(EmitArgs& args) override { 228 void emitCode(EmitArgs& args) override {
236 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder (); 229 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder ();
237 SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mod e(); 230 SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mod e();
238 ComposeOneFragmentProcessor::Child child = 231 ComposeOneFragmentProcessor::Child child =
239 args.fFp.cast<ComposeOneFragmentProcessor>().child(); 232 args.fFp.cast<ComposeOneFragmentProcessor>().child();
240 // declare _dstColor and emit the code for the two child 233 SkString childColor("child");
241 fsBuilder->codeAppendf("vec4 _child;"); 234 this->emitChild(0, nullptr, &childColor, args);
242 this->emitChild(0, nullptr, "_child", args);
243 235
244 const char* inputColor = args.fInputColor; 236 const char* inputColor = args.fInputColor;
245 // We don't try to optimize for this case at all 237 // We don't try to optimize for this case at all
246 if (!inputColor) { 238 if (!inputColor) {
247 fsBuilder->codeAppendf("const vec4 ones = vec4(1);"); 239 fsBuilder->codeAppendf("const vec4 ones = vec4(1);");
248 inputColor = "ones"; 240 inputColor = "ones";
249 } 241 }
250 242
251 // emit blend code 243 // emit blend code
252 fsBuilder->codeAppend("{");
253 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeNam e(mode)); 244 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeNam e(mode));
245 const char* childStr = childColor.c_str();
254 if (ComposeOneFragmentProcessor::kDst_Child == child) { 246 if (ComposeOneFragmentProcessor::kDst_Child == child) {
255 GrGLSLBlend::AppendMode(fsBuilder, inputColor, "_child", args.fOutpu tColor, mode); 247 GrGLSLBlend::AppendMode(fsBuilder, inputColor, childStr, args.fOutpu tColor, mode);
256 } else { 248 } else {
257 GrGLSLBlend::AppendMode(fsBuilder, "_child", inputColor, args.fOutpu tColor, mode); 249 GrGLSLBlend::AppendMode(fsBuilder, childStr, inputColor, args.fOutpu tColor, mode);
258 } 250 }
259 fsBuilder->codeAppend("}");
260 } 251 }
261 252
262 private: 253 private:
263 typedef GrGLFragmentProcessor INHERITED; 254 typedef GrGLFragmentProcessor INHERITED;
264 }; 255 };
265 256
266 ///////////////////////////////////////////////////////////////////// 257 /////////////////////////////////////////////////////////////////////
267 258
268 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeOneFragmentProcessor); 259 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeOneFragmentProcessor);
269 260
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 case SkXfermode::kClear_Mode: 297 case SkXfermode::kClear_Mode:
307 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, 298 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK,
308 GrConstColorProcessor::kIgnore_ InputMode); 299 GrConstColorProcessor::kIgnore_ InputMode);
309 case SkXfermode::kDst_Mode: 300 case SkXfermode::kDst_Mode:
310 return nullptr; 301 return nullptr;
311 default: 302 default:
312 return new ComposeOneFragmentProcessor(src, mode, 303 return new ComposeOneFragmentProcessor(src, mode,
313 ComposeOneFragmentProcessor:: kSrc_Child); 304 ComposeOneFragmentProcessor:: kSrc_Child);
314 } 305 }
315 } 306 }
OLDNEW
« no previous file with comments | « src/effects/SkArithmeticMode_gpu.cpp ('k') | src/gpu/gl/GrGLFragmentProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698