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