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

Side by Side Diff: src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp

Issue 554833002: Calculate Primary and Secondary output types in the GrOptDrawState (Closed) Base URL: https://skia.googlesource.com/skia.git@optReadDst
Patch Set: Rebase Created 6 years, 2 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/gl/GrGpuGL_program.cpp ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.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 2014 Google Inc. 2 * Copyright 2014 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 "GrGLFragmentShaderBuilder.h" 8 #include "GrGLFragmentShaderBuilder.h"
9 #include "GrGLShaderStringBuilder.h" 9 #include "GrGLShaderStringBuilder.h"
10 #include "GrGLProgramBuilder.h" 10 #include "GrGLProgramBuilder.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 declared_color_output_name()); 297 declared_color_output_name());
298 fHasCustomColorOutput = true; 298 fHasCustomColorOutput = true;
299 } 299 }
300 } 300 }
301 301
302 void GrGLFragmentShaderBuilder::emitCodeAfterEffects(const GrGLSLExpr4& inputCol or, const GrGLSLExpr4& inputCoverage) { 302 void GrGLFragmentShaderBuilder::emitCodeAfterEffects(const GrGLSLExpr4& inputCol or, const GrGLSLExpr4& inputCoverage) {
303 const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader (); 303 const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader ();
304 304
305 /////////////////////////////////////////////////////////////////////////// 305 ///////////////////////////////////////////////////////////////////////////
306 // write the secondary color output if necessary 306 // write the secondary color output if necessary
307 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutpu t)) { 307 if (GrOptDrawState::kNone_SecondaryOutputType != header.fSecondaryOutputType ) {
308 const char* secondaryOutputName = this->enableSecondaryOutput(); 308 const char* secondaryOutputName = this->enableSecondaryOutput();
309
310 // default coeff to ones for kCoverage_DualSrcOutput
311 GrGLSLExpr4 coeff(1); 309 GrGLSLExpr4 coeff(1);
312 if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == header.fCov erageOutput) { 310 switch (header.fSecondaryOutputType) {
313 // Get (1-A) into coeff 311 case GrOptDrawState::kCoverage_SecondaryOutputType:
314 coeff = GrGLSLExpr4::VectorCast(GrGLSLExpr1(1) - inputColor.a()); 312 break;
315 } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == 313 case GrOptDrawState::kCoverageISA_SecondaryOutputType:
316 header.fCoverageOutput){ 314 // Get (1-A) into coeff
317 // Get (1-RGBA) into coeff 315 coeff = GrGLSLExpr4::VectorCast(GrGLSLExpr1(1) - inputColor.a()) ;
318 coeff = GrGLSLExpr4(1) - inputColor; 316 break;
317 case GrOptDrawState::kCoverageISC_SecondaryOutputType:
318 // Get (1-RGBA) into coeff
319 coeff = GrGLSLExpr4(1) - inputColor;
320 break;
321 default:
322 SkFAIL("Unexpected Secondary Output");
319 } 323 }
320 // Get coeff * coverage into modulate and then write that to the dual so urce output. 324 // Get coeff * coverage into modulate and then write that to the dual so urce output.
321 codeAppendf("\t%s = %s;\n", secondaryOutputName, (coeff * inputCoverage) .c_str()); 325 codeAppendf("\t%s = %s;\n", secondaryOutputName, (coeff * inputCoverage) .c_str());
322 } 326 }
323 327
324 /////////////////////////////////////////////////////////////////////////// 328 ///////////////////////////////////////////////////////////////////////////
325 // combine color and coverage as frag color 329 // combine color and coverage as frag color
326 330
327 // Get "color * coverage" into fragColor 331 // Get "color * coverage" into fragColor
328 GrGLSLExpr4 fragColor = inputColor * inputCoverage; 332 GrGLSLExpr4 fragColor = inputColor * inputCoverage;
329 // Now tack on "+(1-coverage)dst onto the frag color if we were asked to do so. 333 switch (header.fPrimaryOutputType) {
330 if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == header.fCoverageOutpu t) { 334 case GrOptDrawState::kModulate_PrimaryOutputType:
331 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inputCoverage; 335 break;
332 336 case GrOptDrawState::kCombineWithDst_PrimaryOutputType:
333 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(dstColor()); 337 {
334 338 // Tack on "+(1-coverage)dst onto the frag color.
335 fragColor = fragColor + dstContribution; 339 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inputCoverage;
340 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(dstColor()) ;
341 fragColor = fragColor + dstContribution;
342 }
343 break;
344 default:
345 SkFAIL("Unknown Primary Output");
336 } 346 }
337 codeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_str()); 347 codeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_str());
338 } 348 }
339 349
340 const char* GrGLFragmentShaderBuilder::enableSecondaryOutput() { 350 const char* GrGLFragmentShaderBuilder::enableSecondaryOutput() {
341 if (!fHasSecondaryOutput) { 351 if (!fHasSecondaryOutput) {
342 fOutputs.push_back().set(kVec4f_GrSLType, 352 fOutputs.push_back().set(kVec4f_GrSLType,
343 GrGLShaderVar::kOut_TypeModifier, 353 GrGLShaderVar::kOut_TypeModifier,
344 dual_source_output_name()); 354 dual_source_output_name());
345 fHasSecondaryOutput = true; 355 fHasSecondaryOutput = true;
346 } 356 }
347 return dual_source_output_name(); 357 return dual_source_output_name();
348 } 358 }
349 359
350 const char* GrGLFragmentShaderBuilder::getColorOutputName() const { 360 const char* GrGLFragmentShaderBuilder::getColorOutputName() const {
351 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ; 361 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ;
352 } 362 }
353 363
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL_program.cpp ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698