| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrGLProgramDesc.h" | 8 #include "GrGLProgramDesc.h" |
| 9 #include "GrBackendEffectFactory.h" | 9 #include "GrBackendEffectFactory.h" |
| 10 #include "GrDrawEffect.h" | 10 #include "GrDrawEffect.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); | 25 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); |
| 26 | 26 |
| 27 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | | 27 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | |
| 28 GrDrawState::kEmitCoverage_BlendOptFl
ag)); | 28 GrDrawState::kEmitCoverage_BlendOptFl
ag)); |
| 29 | 29 |
| 30 // The descriptor is used as a cache key. Thus when a field of the | 30 // The descriptor is used as a cache key. Thus when a field of the |
| 31 // descriptor will not affect program generation (because of the attribute | 31 // descriptor will not affect program generation (because of the attribute |
| 32 // bindings in use or other descriptor field settings) it should be set | 32 // bindings in use or other descriptor field settings) it should be set |
| 33 // to a canonical value to avoid duplicate programs with different keys. | 33 // to a canonical value to avoid duplicate programs with different keys. |
| 34 | 34 |
| 35 // Must initialize all fields or cache will have false negatives! | |
| 36 desc->fAttribBindings = drawState.getAttribBindings(); | |
| 37 | 35 |
| 38 desc->fEmitsPointSize = isPoints; | 36 desc->fEmitsPointSize = isPoints; |
| 39 | 37 |
| 40 bool requiresAttributeColors = | 38 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute()
; |
| 41 !skipColor && SkToBool(desc->fAttribBindings & GrDrawState::kColor_Attri
bBindingsBit); | 39 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt
tribute(); |
| 42 bool requiresAttributeCoverage = | 40 // we only need the local coords if we're actually going to generate effect
code |
| 43 !skipCoverage && SkToBool(desc->fAttribBindings & GrDrawState::kCoverage
_AttribBindingsBit); | 41 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && |
| 42 drawState.hasLocalCoordAttribute(); |
| 44 | 43 |
| 45 // fColorInput/fCoverageInput records how colors are specified for the progr
am so we strip the | 44 // fColorInput/fCoverageInput records how colors are specified for the progr
am so we strip the |
| 46 // bits from the bindings to avoid false negatives when searching for an exi
sting program in the | 45 // bits from the bindings to avoid false negatives when searching for an exi
sting program in the |
| 47 // cache. | 46 // cache. |
| 48 desc->fAttribBindings &= | |
| 49 ~(GrDrawState::kColor_AttribBindingsBit | GrDrawState::kCoverage_AttribB
indingsBit); | |
| 50 | 47 |
| 51 desc->fColorFilterXfermode = skipColor ? SkXfermode::kDst_Mode : drawState.g
etColorFilterMode(); | 48 desc->fColorFilterXfermode = skipColor ? SkXfermode::kDst_Mode : drawState.g
etColorFilterMode(); |
| 52 | 49 |
| 53 // no reason to do edge aa or look at per-vertex coverage if coverage is ign
ored | |
| 54 if (skipCoverage) { | |
| 55 desc->fAttribBindings &= ~(GrDrawState::kCoverage_AttribBindingsBit); | |
| 56 } | |
| 57 | 50 |
| 58 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); | 51 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); |
| 59 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || | 52 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || |
| 60 (!requiresAttributeColors && 0xffffffff == drawStat
e.getColor()); | 53 (!requiresColorAttrib && 0xffffffff == drawState.ge
tColor()); |
| 61 if (colorIsTransBlack) { | 54 if (colorIsTransBlack) { |
| 62 desc->fColorInput = kTransBlack_ColorInput; | 55 desc->fColorInput = kTransBlack_ColorInput; |
| 63 } else if (colorIsSolidWhite) { | 56 } else if (colorIsSolidWhite) { |
| 64 desc->fColorInput = kSolidWhite_ColorInput; | 57 desc->fColorInput = kSolidWhite_ColorInput; |
| 65 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeColors) { | 58 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresColorAttrib) { |
| 66 desc->fColorInput = kUniform_ColorInput; | 59 desc->fColorInput = kUniform_ColorInput; |
| 67 } else { | 60 } else { |
| 68 desc->fColorInput = kAttribute_ColorInput; | 61 desc->fColorInput = kAttribute_ColorInput; |
| 69 } | 62 } |
| 70 | 63 |
| 71 bool covIsSolidWhite = !requiresAttributeCoverage && 0xffffffff == drawState
.getCoverage(); | 64 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge
tCoverage(); |
| 72 | 65 |
| 73 if (skipCoverage) { | 66 if (skipCoverage) { |
| 74 desc->fCoverageInput = kTransBlack_ColorInput; | 67 desc->fCoverageInput = kTransBlack_ColorInput; |
| 75 } else if (covIsSolidWhite) { | 68 } else if (covIsSolidWhite) { |
| 76 desc->fCoverageInput = kSolidWhite_ColorInput; | 69 desc->fCoverageInput = kSolidWhite_ColorInput; |
| 77 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeCoverage) { | 70 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresCoverageAttrib) { |
| 78 desc->fCoverageInput = kUniform_ColorInput; | 71 desc->fCoverageInput = kUniform_ColorInput; |
| 79 } else { | 72 } else { |
| 80 desc->fCoverageInput = kAttribute_ColorInput; | 73 desc->fCoverageInput = kAttribute_ColorInput; |
| 81 } | 74 } |
| 82 | 75 |
| 83 int lastEnabledStage = -1; | 76 int lastEnabledStage = -1; |
| 84 | 77 |
| 85 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 78 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 86 | 79 |
| 87 bool skip = s < drawState.getFirstCoverageStage() ? skipColor : skipCove
rage; | 80 bool skip = s < drawState.getFirstCoverageStage() ? skipColor : skipCove
rage; |
| 88 if (!skip && drawState.isStageEnabled(s)) { | 81 if (!skip && drawState.isStageEnabled(s)) { |
| 89 lastEnabledStage = s; | 82 lastEnabledStage = s; |
| 90 const GrEffectRef& effect = *drawState.getStage(s).getEffect(); | 83 const GrEffectRef& effect = *drawState.getStage(s).getEffect(); |
| 91 const GrBackendEffectFactory& factory = effect->getFactory(); | 84 const GrBackendEffectFactory& factory = effect->getFactory(); |
| 92 bool explicitLocalCoords = (drawState.getAttribBindings() & | 85 GrDrawEffect drawEffect(drawState.getStage(s), requiresLocalCoordAtt
rib); |
| 93 GrDrawState::kLocalCoords_AttribBindings
Bit); | |
| 94 GrDrawEffect drawEffect(drawState.getStage(s), explicitLocalCoords); | |
| 95 desc->fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()
); | 86 desc->fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()
); |
| 96 } else { | 87 } else { |
| 97 desc->fEffectKeys[s] = 0; | 88 desc->fEffectKeys[s] = 0; |
| 98 } | 89 } |
| 99 } | 90 } |
| 100 | 91 |
| 101 desc->fDualSrcOutput = kNone_DualSrcOutput; | 92 desc->fDualSrcOutput = kNone_DualSrcOutput; |
| 102 | 93 |
| 103 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything | 94 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything |
| 104 // other than pass through values from the VS to the FS anyway). | 95 // other than pass through values from the VS to the FS anyway). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 int firstCoverageStage = GrDrawState::kNumStages; | 109 int firstCoverageStage = GrDrawState::kNumStages; |
| 119 desc->fDiscardIfZeroCoverage = false; // Enabled below if stenciling and the
re is coverage. | 110 desc->fDiscardIfZeroCoverage = false; // Enabled below if stenciling and the
re is coverage. |
| 120 bool hasCoverage = false; | 111 bool hasCoverage = false; |
| 121 // If we're rendering coverage-as-color then it's as though there are no cov
erage stages. | 112 // If we're rendering coverage-as-color then it's as though there are no cov
erage stages. |
| 122 if (!drawState.isCoverageDrawing()) { | 113 if (!drawState.isCoverageDrawing()) { |
| 123 // We can have coverage either through a stage or coverage vertex attrib
utes. | 114 // We can have coverage either through a stage or coverage vertex attrib
utes. |
| 124 if (drawState.getFirstCoverageStage() <= lastEnabledStage) { | 115 if (drawState.getFirstCoverageStage() <= lastEnabledStage) { |
| 125 firstCoverageStage = drawState.getFirstCoverageStage(); | 116 firstCoverageStage = drawState.getFirstCoverageStage(); |
| 126 hasCoverage = true; | 117 hasCoverage = true; |
| 127 } else { | 118 } else { |
| 128 hasCoverage = requiresAttributeCoverage; | 119 hasCoverage = requiresCoverageAttrib; |
| 129 } | 120 } |
| 130 } | 121 } |
| 131 | 122 |
| 132 if (hasCoverage) { | 123 if (hasCoverage) { |
| 133 // color filter is applied between color/coverage computation | 124 // color filter is applied between color/coverage computation |
| 134 if (SkXfermode::kDst_Mode != desc->fColorFilterXfermode) { | 125 if (SkXfermode::kDst_Mode != desc->fColorFilterXfermode) { |
| 135 desc->fFirstCoverageStage = firstCoverageStage; | 126 desc->fFirstCoverageStage = firstCoverageStage; |
| 136 } | 127 } |
| 137 | 128 |
| 138 // If we're stenciling then we want to discard samples that have zero co
verage | 129 // If we're stenciling then we want to discard samples that have zero co
verage |
| (...skipping 14 matching lines...) Expand all Loading... |
| 153 desc->fDualSrcOutput = kCoverageISA_DualSrcOutput; | 144 desc->fDualSrcOutput = kCoverageISA_DualSrcOutput; |
| 154 desc->fFirstCoverageStage = firstCoverageStage; | 145 desc->fFirstCoverageStage = firstCoverageStage; |
| 155 } else if (kSC_GrBlendCoeff == dstCoeff) { | 146 } else if (kSC_GrBlendCoeff == dstCoeff) { |
| 156 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 147 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
| 157 desc->fDualSrcOutput = kCoverageISC_DualSrcOutput; | 148 desc->fDualSrcOutput = kCoverageISC_DualSrcOutput; |
| 158 desc->fFirstCoverageStage = firstCoverageStage; | 149 desc->fFirstCoverageStage = firstCoverageStage; |
| 159 } | 150 } |
| 160 } | 151 } |
| 161 } | 152 } |
| 162 | 153 |
| 163 desc->fPositionAttributeIndex = drawState.getAttribIndex(GrDrawState::kPosit
ion_AttribIndex); | 154 desc->fPositionAttributeIndex = drawState.positionAttributeIndex(); |
| 164 if (requiresAttributeColors) { | 155 desc->fLocalCoordAttributeIndex = drawState.localCoordAttributeIndex(); |
| 165 desc->fColorAttributeIndex = drawState.getAttribIndex(GrDrawState::kColo
r_AttribIndex); | 156 |
| 157 // For constant color and coverage we need an attribute with an index beyond
those already set |
| 158 int availableAttributeIndex = drawState.getVertexAttribCount(); |
| 159 if (requiresColorAttrib) { |
| 160 desc->fColorAttributeIndex = drawState.colorVertexAttributeIndex(); |
| 161 } else if (GrGLProgramDesc::kAttribute_ColorInput == desc->fColorInput) { |
| 162 GrAssert(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
| 163 desc->fColorAttributeIndex = availableAttributeIndex; |
| 164 availableAttributeIndex++; |
| 166 } else { | 165 } else { |
| 167 desc->fColorAttributeIndex = GrDrawState::kColorOverrideAttribIndexValue
; | 166 desc->fColorAttributeIndex = -1; |
| 168 } | |
| 169 if (requiresAttributeCoverage) { | |
| 170 desc->fCoverageAttributeIndex = drawState.getAttribIndex(GrDrawState::kC
overage_AttribIndex); | |
| 171 } else { | |
| 172 desc->fCoverageAttributeIndex = GrDrawState::kCoverageOverrideAttribInde
xValue; | |
| 173 } | |
| 174 if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { | |
| 175 desc->fLocalCoordsAttributeIndex = drawState.getAttribIndex(GrDrawState:
:kLocalCoords_AttribIndex); | |
| 176 } | 167 } |
| 177 | 168 |
| 178 #if GR_DEBUG | 169 if (requiresCoverageAttrib) { |
| 179 // Verify valid vertex attribute state. These assertions should probably be
done somewhere | 170 desc->fCoverageAttributeIndex = drawState.coverageVertexAttributeIndex()
; |
| 180 // higher up the callstack | 171 } else if (GrGLProgramDesc::kAttribute_ColorInput == desc->fCoverageInput) { |
| 181 const GrVertexAttrib* vertexAttribs = drawState.getVertexAttribs(); | 172 GrAssert(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
| 182 GrAssert(desc->fPositionAttributeIndex < GrDrawState::kVertexAttribCnt); | 173 desc->fCoverageAttributeIndex = availableAttributeIndex; |
| 183 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fPositionAttributeIndex]
.fType).fCount == 2); | 174 } else { |
| 184 if (requiresAttributeColors) { | 175 desc->fCoverageAttributeIndex = -1; |
| 185 GrAssert(desc->fColorAttributeIndex < GrDrawState::kVertexAttribCnt); | |
| 186 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fColorAttributeIndex
].fType).fCount == 4); | |
| 187 } | 176 } |
| 188 if (requiresAttributeCoverage) { | |
| 189 GrAssert(desc->fCoverageAttributeIndex < GrDrawState::kVertexAttribCnt); | |
| 190 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fCoverageAttributeIn
dex].fType).fCount == 4); | |
| 191 } | |
| 192 if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { | |
| 193 GrAssert(desc->fLocalCoordsAttributeIndex < GrDrawState::kVertexAttribCn
t); | |
| 194 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fLocalCoordsAttribut
eIndex].fType).fCount == 2); | |
| 195 } | |
| 196 #endif | |
| 197 } | 177 } |
| OLD | NEW |