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

Unified Diff: src/gpu/gl/GrGLProgram.cpp

Issue 14233006: Perform coverage blend with the dst in the shader when using a dst-reading xfermode. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLProgram.cpp
===================================================================
--- src/gpu/gl/GrGLProgram.cpp (revision 8756)
+++ src/gpu/gl/GrGLProgram.cpp (working copy)
@@ -96,18 +96,22 @@
void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff,
GrBlendCoeff* dstCoeff) const {
- switch (fDesc.fDualSrcOutput) {
- case GrGLProgramDesc::kNone_DualSrcOutput:
+ switch (fDesc.fCoverageOutput) {
+ case GrGLProgramDesc::kModulate_CoverageOutput:
break;
- // the prog will write a coverage value to the secondary
+ // The prog will write a coverage value to the secondary
// output and the dst is blended by one minus that value.
- case GrGLProgramDesc::kCoverage_DualSrcOutput:
- case GrGLProgramDesc::kCoverageISA_DualSrcOutput:
- case GrGLProgramDesc::kCoverageISC_DualSrcOutput:
- *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
- break;
+ case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput:
+ case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput:
+ case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput:
+ *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
+ break;
+ case GrGLProgramDesc::kCombineWithDst_CoverageOutput:
robertphillips 2013/04/18 22:02:03 rm trailing /?
bsalomon 2013/04/19 13:14:49 Done.
+ // We should only have set this if the blend was specified as (1, 0)/
+ GrAssert(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *dstCoeff);
+ break;
default:
- GrCrash("Unexpected dual source blend output");
+ GrCrash("Unexpected coverage output");
break;
}
}
@@ -418,6 +422,20 @@
return true;
}
robertphillips 2013/04/18 22:02:03 move into above namespace?
bsalomon 2013/04/19 13:14:49 Done.
+void expand_known_value4f(SkString* string, GrSLConstantVec vec) {
+ GrAssert(string->isEmpty() == (vec != kNone_GrSLConstantVec));
+ switch (vec) {
+ case kNone_GrSLConstantVec:
+ break;
+ case kZeros_GrSLConstantVec:
+ *string = GrGLSLZerosVecf(4);
+ break;
+ case kOnes_GrSLConstantVec:
+ *string = GrGLSLOnesVecf(4);
+ break;
+ }
+}
+
bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
GrAssert(0 == fProgramID);
@@ -564,14 +582,16 @@
}
}
- if (GrGLProgramDesc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) {
+ GrGLProgramDesc::CoverageOutput coverageOutput =
+ static_cast<GrGLProgramDesc::CoverageOutput>(fDesc.fCoverageOutput);
+ if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(coverageOutput)) {
builder.fFSOutputs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kOut_TypeModifier,
dual_source_output_name());
// default coeff to ones for kCoverage_DualSrcOutput
SkString coeff;
GrSLConstantVec knownCoeffValue = kOnes_GrSLConstantVec;
robertphillips 2013/04/18 22:02:03 Why not use coverageOutput here rather than fDesc.
- if (GrGLProgramDesc::kCoverageISA_DualSrcOutput == fDesc.fDualSrcOutput) {
+ if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == fDesc.fCoverageOutput) {
// Get (1-A) into coeff
SkString inColorAlpha;
GrGLSLGetComponent4f(&inColorAlpha,
@@ -585,7 +605,7 @@
kOnes_GrSLConstantVec,
knownColorValue,
true);
- } else if (GrGLProgramDesc::kCoverageISC_DualSrcOutput == fDesc.fDualSrcOutput) {
+ } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == coverageOutput) {
// Get (1-RGBA) into coeff
knownCoeffValue = GrGLSLSubtractf<4>(&coeff,
NULL,
@@ -609,15 +629,42 @@
///////////////////////////////////////////////////////////////////////////
// combine color and coverage as frag color
robertphillips 2013/04/18 22:02:03 Add quotes ... "color * coverage"?
bsalomon 2013/04/19 13:14:49 Done.
- // Get color * coverage into modulate and write that to frag shader's output.
- SkString modulate;
- GrGLSLModulatef<4>(&modulate,
- inColor.c_str(),
- inCoverage.c_str(),
- knownColorValue,
- knownCoverageValue,
- false);
- builder.fsCodeAppendf("\t%s = %s;\n", colorOutput.getName().c_str(), modulate.c_str());
+ // Get color * coverage into fragColor
+ SkString fragColor;
+ GrSLConstantVec knownFragColorValue = GrGLSLModulatef<4>(&fragColor,
+ inColor.c_str(),
+ inCoverage.c_str(),
+ knownColorValue,
+ knownCoverageValue,
+ true);
robertphillips 2013/04/18 22:02:03 "+(1-coverage)dst"?
bsalomon 2013/04/19 13:14:49 Done.
+ // Now tack on +(1-coverage)dst onto the frag color if we were asked to do so.
+ if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == coverageOutput) {
+ SkString dstCoeff;
+ GrSLConstantVec knownDstCoeffValue = GrGLSLSubtractf<4>(&dstCoeff,
+ NULL,
+ inCoverage.c_str(),
+ kOnes_GrSLConstantVec,
+ knownCoverageValue,
robertphillips 2013/04/18 22:02:03 indent on true?
bsalomon 2013/04/19 13:14:49 Done.
+ true);
+ SkString dstContribution;
+ GrSLConstantVec knownDstContributionValue = GrGLSLModulatef<4>(&dstContribution,
+ dstCoeff.c_str(),
+ builder.dstColor(),
+ knownDstCoeffValue,
+ kNone_GrSLConstantVec,
+ true);
+ SkString oldFragColor = fragColor;
+ fragColor.reset();
+ GrGLSLAddf<4>(&fragColor,
+ oldFragColor.c_str(),
+ dstContribution.c_str(),
+ knownFragColorValue,
+ knownDstContributionValue,
+ false);
+ } else {
+ expand_known_value4f(&fragColor, knownFragColorValue);
+ }
+ builder.fsCodeAppendf("\t%s = %s;\n", colorOutput.getName().c_str(), fragColor.c_str());
///////////////////////////////////////////////////////////////////////////
// insert GS
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698