| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 colorStages->reset(); | 59 colorStages->reset(); |
| 60 coverageStages->reset(); | 60 coverageStages->reset(); |
| 61 | 61 |
| 62 // This should already have been caught | 62 // This should already have been caught |
| 63 SkASSERT(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); | 63 SkASSERT(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); |
| 64 | 64 |
| 65 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); | 65 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); |
| 66 | 66 |
| 67 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | | 67 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | |
| 68 GrDrawState::kEmitCoverage_BlendOptFl
ag)); | 68 GrDrawState::kEmitCoverage_BlendOptFl
ag)); |
| 69 |
| 69 int firstEffectiveColorStage = 0; | 70 int firstEffectiveColorStage = 0; |
| 70 bool inputColorIsUsed = true; | 71 bool inputColorIsUsed = true; |
| 71 if (!skipColor) { | 72 if (!skipColor) { |
| 72 firstEffectiveColorStage = drawState.numColorStages(); | 73 firstEffectiveColorStage = drawState.numColorStages(); |
| 73 while (firstEffectiveColorStage > 0 && inputColorIsUsed) { | 74 while (firstEffectiveColorStage > 0 && inputColorIsUsed) { |
| 74 --firstEffectiveColorStage; | 75 --firstEffectiveColorStage; |
| 75 const GrEffect* effect = drawState.getColorStage(firstEffectiveColor
Stage).getEffect(); | 76 const GrEffect* effect = drawState.getColorStage(firstEffectiveColor
Stage).getEffect(); |
| 76 inputColorIsUsed = effect->willUseInputColor(); | 77 inputColorIsUsed = effect->willUseInputColor(); |
| 77 } | 78 } |
| 78 } | 79 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 // descriptor will not affect program generation (because of the attribute | 93 // descriptor will not affect program generation (because of the attribute |
| 93 // bindings in use or other descriptor field settings) it should be set | 94 // bindings in use or other descriptor field settings) it should be set |
| 94 // to a canonical value to avoid duplicate programs with different keys. | 95 // to a canonical value to avoid duplicate programs with different keys. |
| 95 | 96 |
| 96 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute()
; | 97 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute()
; |
| 97 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt
tribute(); | 98 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt
tribute(); |
| 98 // we only need the local coords if we're actually going to generate effect
code | 99 // we only need the local coords if we're actually going to generate effect
code |
| 99 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && | 100 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && |
| 100 drawState.hasLocalCoordAttribute(); | 101 drawState.hasLocalCoordAttribute(); |
| 101 | 102 |
| 102 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); | |
| 103 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || | |
| 104 (!requiresColorAttrib && 0xffffffff == drawState.ge
tColor()) || | |
| 105 (!inputColorIsUsed); | |
| 106 | |
| 107 bool readsDst = false; | 103 bool readsDst = false; |
| 108 bool readFragPosition = false; | 104 bool readFragPosition = false; |
| 109 // We use vertexshader-less shader programs only when drawing paths. | 105 // We use vertexshader-less shader programs only when drawing paths. |
| 110 bool hasVertexCode = !(GrGpu::kDrawPath_DrawType == drawType || | 106 bool hasVertexCode = !(GrGpu::kDrawPath_DrawType == drawType || |
| 111 GrGpu::kDrawPaths_DrawType == drawType); | 107 GrGpu::kDrawPaths_DrawType == drawType); |
| 112 int numStages = 0; | 108 int numStages = 0; |
| 113 if (!skipColor) { | 109 if (!skipColor) { |
| 114 numStages += drawState.numColorStages() - firstEffectiveColorStage; | 110 numStages += drawState.numColorStages() - firstEffectiveColorStage; |
| 115 } | 111 } |
| 116 if (!skipCoverage) { | 112 if (!skipCoverage) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // other than pass through values from the VS to the FS anyway). | 181 // other than pass through values from the VS to the FS anyway). |
| 186 #if GR_GL_EXPERIMENTAL_GS | 182 #if GR_GL_EXPERIMENTAL_GS |
| 187 #if 0 | 183 #if 0 |
| 188 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); | 184 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); |
| 189 #else | 185 #else |
| 190 header->fExperimentalGS = false; | 186 header->fExperimentalGS = false; |
| 191 #endif | 187 #endif |
| 192 #endif | 188 #endif |
| 193 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p
athRenderingSupport(); | 189 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p
athRenderingSupport(); |
| 194 | 190 |
| 195 if (colorIsTransBlack) { | 191 if (defaultToUniformInputs && !requiresColorAttrib && inputColorIsUsed) { |
| 196 header->fColorInput = kTransBlack_ColorInput; | |
| 197 } else if (colorIsSolidWhite) { | |
| 198 header->fColorInput = kSolidWhite_ColorInput; | |
| 199 } else if (defaultToUniformInputs && !requiresColorAttrib) { | |
| 200 header->fColorInput = kUniform_ColorInput; | 192 header->fColorInput = kUniform_ColorInput; |
| 201 } else { | 193 } else { |
| 202 header->fColorInput = kAttribute_ColorInput; | 194 header->fColorInput = kAttribute_ColorInput; |
| 203 header->fHasVertexCode = true; | 195 header->fHasVertexCode = true; |
| 204 } | 196 } |
| 205 | 197 |
| 206 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge
tCoverageColor(); | 198 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge
tCoverageColor(); |
| 207 | 199 |
| 208 if (skipCoverage) { | 200 if ((covIsSolidWhite || !inputCoverageIsUsed) && !skipCoverage) { |
| 209 header->fCoverageInput = kTransBlack_ColorInput; | |
| 210 } else if (covIsSolidWhite || !inputCoverageIsUsed) { | |
| 211 header->fCoverageInput = kSolidWhite_ColorInput; | 201 header->fCoverageInput = kSolidWhite_ColorInput; |
| 212 } else if (defaultToUniformInputs && !requiresCoverageAttrib) { | 202 } else if (defaultToUniformInputs && !requiresCoverageAttrib && inputCoverag
eIsUsed) { |
| 213 header->fCoverageInput = kUniform_ColorInput; | 203 header->fCoverageInput = kUniform_ColorInput; |
| 214 } else { | 204 } else { |
| 215 header->fCoverageInput = kAttribute_ColorInput; | 205 header->fCoverageInput = kAttribute_ColorInput; |
| 216 header->fHasVertexCode = true; | 206 header->fHasVertexCode = true; |
| 217 } | 207 } |
| 218 | 208 |
| 219 if (readsDst) { | 209 if (readsDst) { |
| 220 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); | 210 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); |
| 221 const GrTexture* dstCopyTexture = NULL; | 211 const GrTexture* dstCopyTexture = NULL; |
| 222 if (NULL != dstCopy) { | 212 if (NULL != dstCopy) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 *checksum = 0; | 315 *checksum = 0; |
| 326 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); | 316 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); |
| 327 } | 317 } |
| 328 | 318 |
| 329 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 319 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
| 330 size_t keyLength = other.keyLength(); | 320 size_t keyLength = other.keyLength(); |
| 331 fKey.reset(keyLength); | 321 fKey.reset(keyLength); |
| 332 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 322 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
| 333 return *this; | 323 return *this; |
| 334 } | 324 } |
| OLD | NEW |