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

Side by Side Diff: src/gpu/gl/GrGLProgram.cpp

Issue 14925010: Move loops that chain together effects into GrGLShaderBuilder from GrGLProgram. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Address comments and fix for emitting code for skipped effects Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLEffectMatrix.cpp ('k') | src/gpu/gl/GrGLProgramDesc.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 2011 Google Inc. 2 * Copyright 2011 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 "GrGLProgram.h" 8 #include "GrGLProgram.h"
9 9
10 #include "GrAllocator.h" 10 #include "GrAllocator.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // Get the coeffs for the Mode-based color filter, determine if color is nee ded. 478 // Get the coeffs for the Mode-based color filter, determine if color is nee ded.
479 SkXfermode::Coeff colorCoeff; 479 SkXfermode::Coeff colorCoeff;
480 SkXfermode::Coeff filterColorCoeff; 480 SkXfermode::Coeff filterColorCoeff;
481 SkAssertResult( 481 SkAssertResult(
482 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(fDesc.fColorFilter Xfermode), 482 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(fDesc.fColorFilter Xfermode),
483 &filterColorCoeff, 483 &filterColorCoeff,
484 &colorCoeff)); 484 &colorCoeff));
485 bool needColor, needFilterColor; 485 bool needColor, needFilterColor;
486 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor ); 486 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor );
487 487
488 // used in order for builder to return the per-stage uniform handles.
489 SkTArray<GrGLUniformManager::UniformHandle, true>* stageUniformArrays[GrDraw State::kNumStages];
490
488 if (needColor) { 491 if (needColor) {
489 //////////////////////////////////////////////////////////////////////// ///
490 // compute the color
491 // if we have color stages string them together, feeding the output colo r
492 // of each to the next and generating code for each stage.
493 SkString outColor;
494 for (int s = 0; s < fDesc.fFirstCoverageStage; ++s) { 492 for (int s = 0; s < fDesc.fFirstCoverageStage; ++s) {
495 if (GrGLEffect::kNoEffectKey != fDesc.fEffectKeys[s]) { 493 stageUniformArrays[s] = &fUniformHandles.fEffectSamplerUnis[s];
496 if (kZeros_GrSLConstantVec == knownColorValue) { 494 }
497 // Effects have no way to communicate zeros, they treat an e mpty string as ones.
498 inColor = "initialColor";
499 builder.fsCodeAppendf("\tvec4 %s = %s;\n", inColor.c_str(), GrGLSLZerosVecf(4));
500 }
501 // create var to hold stage result
502 outColor = "color";
503 outColor.appendS32(s);
504 builder.fsCodeAppendf("\tvec4 %s;\n", outColor.c_str());
505 495
506 builder.setCurrentStage(s); 496 builder.emitEffects(stages,
507 fEffects[s] = builder.createAndEmitGLEffect(*stages[s], 497 fDesc.fEffectKeys,
508 fDesc.fEffectKeys[s] , 498 fDesc.fFirstCoverageStage,
509 inColor.size() ? inC olor.c_str() : NULL, 499 &inColor,
510 outColor.c_str(), 500 &knownColorValue,
511 &fUniformHandles.fEf fectSamplerUnis[s]); 501 stageUniformArrays,
512 builder.setNonStage(); 502 fEffects);
513 inColor = outColor;
514 knownColorValue = kNone_GrSLConstantVec;
515 }
516 }
517 } 503 }
518 504
519 // Insert the color filter. This will soon be replaced by a color effect. 505 // Insert the color filter. This will soon be replaced by a color effect.
520 if (SkXfermode::kDst_Mode != fDesc.fColorFilterXfermode) { 506 if (SkXfermode::kDst_Mode != fDesc.fColorFilterXfermode) {
521 const char* colorFilterColorUniName = NULL; 507 const char* colorFilterColorUniName = NULL;
522 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder:: kFragment_ShaderType, 508 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder:: kFragment_ShaderType,
523 kVec4f_GrSLType, "F ilterColor", 509 kVec4f_GrSLType, "F ilterColor",
524 &colorFilterColorUn iName); 510 &colorFilterColorUn iName);
525 511
526 builder.fsCodeAppend("\tvec4 filteredColor;\n"); 512 builder.fsCodeAppend("\tvec4 filteredColor;\n");
527 const char* color; 513 const char* color;
528 // add_color_filter requires a real input string. 514 // add_color_filter requires a real input string.
529 if (knownColorValue == kOnes_GrSLConstantVec) { 515 if (knownColorValue == kOnes_GrSLConstantVec) {
530 color = GrGLSLOnesVecf(4); 516 color = GrGLSLOnesVecf(4);
531 } else if (knownColorValue == kZeros_GrSLConstantVec) { 517 } else if (knownColorValue == kZeros_GrSLConstantVec) {
532 color = GrGLSLZerosVecf(4); 518 color = GrGLSLZerosVecf(4);
533 } else { 519 } else {
534 color = inColor.c_str(); 520 color = inColor.c_str();
535 } 521 }
536 add_color_filter(&builder, "filteredColor", filterColorCoeff, 522 add_color_filter(&builder, "filteredColor", filterColorCoeff,
537 colorCoeff, colorFilterColorUniName, color); 523 colorCoeff, colorFilterColorUniName, color);
538 inColor = "filteredColor"; 524 inColor = "filteredColor";
539 } 525 }
540 526
541 /////////////////////////////////////////////////////////////////////////// 527 ///////////////////////////////////////////////////////////////////////////
542 // compute the partial coverage 528 // compute the partial coverage
543
544 // incoming coverage to current stage being processed.
545 SkString inCoverage; 529 SkString inCoverage;
546 GrSLConstantVec knownCoverageValue = this->genInputCoverage(&builder, &inCov erage); 530 GrSLConstantVec knownCoverageValue = this->genInputCoverage(&builder, &inCov erage);
547 531
548 SkString outCoverage; 532 for (int s = fDesc.fFirstCoverageStage, i = 0; s < GrDrawState::kNumStages; ++s, ++i) {
549 for (int s = fDesc.fFirstCoverageStage; s < GrDrawState::kNumStages; ++s) { 533 stageUniformArrays[i] = &fUniformHandles.fEffectSamplerUnis[s];
550 if (fDesc.fEffectKeys[s]) { 534 }
551 if (kZeros_GrSLConstantVec == knownCoverageValue) {
552 // Effects have no way to communicate zeros, they treat an empty string as ones.
553 inCoverage = "initialCoverage";
554 builder.fsCodeAppendf("\tvec4 %s = %s;\n", inCoverage.c_str(), G rGLSLZerosVecf(4));
555 }
556 // create var to hold stage output
557 outCoverage = "coverage";
558 outCoverage.appendS32(s);
559 builder.fsCodeAppendf("\tvec4 %s;\n", outCoverage.c_str());
560 535
561 builder.setCurrentStage(s); 536 builder.emitEffects(stages + fDesc.fFirstCoverageStage,
562 fEffects[s] = builder.createAndEmitGLEffect( 537 fDesc.fEffectKeys + fDesc.fFirstCoverageStage,
563 *stages[s], 538 GrDrawState::kNumStages - fDesc.fFirstCoverageStage,
564 fDesc.fEffectKeys[s], 539 &inCoverage,
565 inCoverage.size() ? inCoverage.c_str () : NULL, 540 &knownCoverageValue,
566 outCoverage.c_str(), 541 stageUniformArrays,
567 &fUniformHandles.fEffectSamplerUnis[ s]); 542 fEffects + fDesc.fFirstCoverageStage);
568 builder.setNonStage();
569 inCoverage = outCoverage;
570 knownCoverageValue = kNone_GrSLConstantVec;
571 }
572 }
573 543
574 // discard if coverage is zero 544 // discard if coverage is zero
575 if (fDesc.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageVa lue) { 545 if (fDesc.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageVa lue) {
576 if (kZeros_GrSLConstantVec == knownCoverageValue) { 546 if (kZeros_GrSLConstantVec == knownCoverageValue) {
577 // This is unfortunate. 547 // This is unfortunate.
578 builder.fsCodeAppend("\tdiscard;\n"); 548 builder.fsCodeAppend("\tdiscard;\n");
579 } else { 549 } else {
580 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n", 550 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n",
581 inCoverage.c_str()); 551 inCoverage.c_str());
582 } 552 }
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 SkScalarToFloat(m[SkMatrix::kMTransX]), 952 SkScalarToFloat(m[SkMatrix::kMTransX]),
983 SkScalarToFloat(m[SkMatrix::kMTransY]), 953 SkScalarToFloat(m[SkMatrix::kMTransY]),
984 SkScalarToFloat(m[SkMatrix::kMPersp2]) 954 SkScalarToFloat(m[SkMatrix::kMPersp2])
985 }; 955 };
986 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); 956 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt);
987 fMatrixState.fViewMatrix = drawState.getViewMatrix(); 957 fMatrixState.fViewMatrix = drawState.getViewMatrix();
988 fMatrixState.fRenderTargetSize = size; 958 fMatrixState.fRenderTargetSize = size;
989 fMatrixState.fRenderTargetOrigin = rt->origin(); 959 fMatrixState.fRenderTargetOrigin = rt->origin();
990 } 960 }
991 } 961 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLEffectMatrix.cpp ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698