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

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, 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
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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 declared_color_output_name()); 296 declared_color_output_name());
297 fHasCustomColorOutput = true; 297 fHasCustomColorOutput = true;
298 } 298 }
299 } 299 }
300 300
301 void GrGLFragmentShaderBuilder::emitCodeAfterEffects(const GrGLSLExpr4& inputCol or, const GrGLSLExpr4& inputCoverage) { 301 void GrGLFragmentShaderBuilder::emitCodeAfterEffects(const GrGLSLExpr4& inputCol or, const GrGLSLExpr4& inputCoverage) {
302 const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader (); 302 const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader ();
303 303
304 /////////////////////////////////////////////////////////////////////////// 304 ///////////////////////////////////////////////////////////////////////////
305 // write the secondary color output if necessary 305 // write the secondary color output if necessary
306 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutpu t)) { 306 if (GrOptDrawState::kNone_SecondaryOutputType != header.fSecondaryOutputType ) {
307 const char* secondaryOutputName = this->enableSecondaryOutput(); 307 const char* secondaryOutputName = this->enableSecondaryOutput();
308
309 // default coeff to ones for kCoverage_DualSrcOutput
310 GrGLSLExpr4 coeff(1); 308 GrGLSLExpr4 coeff(1);
311 if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == header.fCov erageOutput) { 309 switch (header.fSecondaryOutputType) {
312 // Get (1-A) into coeff 310 case GrOptDrawState::kCoverage_SecondaryOutputType:
313 coeff = GrGLSLExpr4::VectorCast(GrGLSLExpr1(1) - inputColor.a()); 311 break;
314 } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == 312 case GrOptDrawState::kCoverageISA_SecondaryOutputType:
315 header.fCoverageOutput){ 313 // Get (1-A) into coeff
316 // Get (1-RGBA) into coeff 314 coeff = GrGLSLExpr4::VectorCast(GrGLSLExpr1(1) - inputColor.a()) ;
317 coeff = GrGLSLExpr4(1) - inputColor; 315 break;
316 case GrOptDrawState::kCoverageISC_SecondaryOutputType:
317 // Get (1-RGBA) into coeff
318 coeff = GrGLSLExpr4(1) - inputColor;
319 break;
320 default:
321 SkFAIL("Unexpected Secondary Output");
318 } 322 }
319 // Get coeff * coverage into modulate and then write that to the dual so urce output. 323 // Get coeff * coverage into modulate and then write that to the dual so urce output.
320 codeAppendf("\t%s = %s;\n", secondaryOutputName, (coeff * inputCoverage) .c_str()); 324 codeAppendf("\t%s = %s;\n", secondaryOutputName, (coeff * inputCoverage) .c_str());
321 } 325 }
322 326
323 /////////////////////////////////////////////////////////////////////////// 327 ///////////////////////////////////////////////////////////////////////////
324 // combine color and coverage as frag color 328 // combine color and coverage as frag color
325 329
326 // Get "color * coverage" into fragColor 330 // Get "color * coverage" into fragColor
327 GrGLSLExpr4 fragColor = inputColor * inputCoverage; 331 GrGLSLExpr4 fragColor = inputColor * inputCoverage;
328 // Now tack on "+(1-coverage)dst onto the frag color if we were asked to do so. 332 switch (header.fPrimaryOutputType) {
329 if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == header.fCoverageOutpu t) { 333 case GrOptDrawState::kModulate_PrimaryOutputType:
330 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inputCoverage; 334 break;
331 335 case GrOptDrawState::kCombineWithDst_PrimaryOutputType:
332 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(dstColor()); 336 {
333 337 // Tack on "+(1-coverage)dst onto the frag color.
334 fragColor = fragColor + dstContribution; 338 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inputCoverage;
339 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(dstColor()) ;
340 fragColor = fragColor + dstContribution;
341 }
342 break;
343 default:
344 SkFAIL("Unknown Primary Output");
335 } 345 }
336 codeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_str()); 346 codeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_str());
337 } 347 }
338 348
339 const char* GrGLFragmentShaderBuilder::enableSecondaryOutput() { 349 const char* GrGLFragmentShaderBuilder::enableSecondaryOutput() {
340 if (!fHasSecondaryOutput) { 350 if (!fHasSecondaryOutput) {
341 fOutputs.push_back().set(kVec4f_GrSLType, 351 fOutputs.push_back().set(kVec4f_GrSLType,
342 GrGLShaderVar::kOut_TypeModifier, 352 GrGLShaderVar::kOut_TypeModifier,
343 dual_source_output_name()); 353 dual_source_output_name());
344 fHasSecondaryOutput = true; 354 fHasSecondaryOutput = true;
345 } 355 }
346 return dual_source_output_name(); 356 return dual_source_output_name();
347 } 357 }
348 358
349 const char* GrGLFragmentShaderBuilder::getColorOutputName() const { 359 const char* GrGLFragmentShaderBuilder::getColorOutputName() const {
350 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ; 360 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ;
351 } 361 }
352 362
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698