| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // descriptor will not affect program generation (because of the attribute | 82 // descriptor will not affect program generation (because of the attribute |
| 83 // bindings in use or other descriptor field settings) it should be set | 83 // bindings in use or other descriptor field settings) it should be set |
| 84 // to a canonical value to avoid duplicate programs with different keys. | 84 // to a canonical value to avoid duplicate programs with different keys. |
| 85 | 85 |
| 86 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute()
; | 86 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute()
; |
| 87 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt
tribute(); | 87 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt
tribute(); |
| 88 // we only need the local coords if we're actually going to generate effect
code | 88 // we only need the local coords if we're actually going to generate effect
code |
| 89 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && | 89 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && |
| 90 drawState.hasLocalCoordAttribute(); | 90 drawState.hasLocalCoordAttribute(); |
| 91 | 91 |
| 92 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); | |
| 93 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || | |
| 94 (!requiresColorAttrib && 0xffffffff == drawState.ge
tColor()) || | |
| 95 (!inputColorIsUsed); | |
| 96 | |
| 97 int numEffects = (skipColor ? 0 : (drawState.numColorStages() - firstEffecti
veColorStage)) + | 92 int numEffects = (skipColor ? 0 : (drawState.numColorStages() - firstEffecti
veColorStage)) + |
| 98 (skipCoverage ? 0 : (drawState.numCoverageStages() - firstE
ffectiveCoverageStage)); | 93 (skipCoverage ? 0 : (drawState.numCoverageStages() - firstE
ffectiveCoverageStage)); |
| 99 | 94 |
| 100 size_t newKeyLength = KeyLength(numEffects); | 95 size_t newKeyLength = KeyLength(numEffects); |
| 101 bool allocChanged; | 96 bool allocChanged; |
| 102 desc->fKey.reset(newKeyLength, SkAutoMalloc::kAlloc_OnShrink, &allocChanged)
; | 97 desc->fKey.reset(newKeyLength, SkAutoMalloc::kAlloc_OnShrink, &allocChanged)
; |
| 103 if (allocChanged || !desc->fInitialized) { | 98 if (allocChanged || !desc->fInitialized) { |
| 104 // make sure any padding in the header is zero if we we haven't used thi
s allocation before. | 99 // make sure any padding in the header is zero if we we haven't used thi
s allocation before. |
| 105 memset(desc->header(), 0, kHeaderSize); | 100 memset(desc->header(), 0, kHeaderSize); |
| 106 } | 101 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // other than pass through values from the VS to the FS anyway). | 136 // other than pass through values from the VS to the FS anyway). |
| 142 #if GR_GL_EXPERIMENTAL_GS | 137 #if GR_GL_EXPERIMENTAL_GS |
| 143 #if 0 | 138 #if 0 |
| 144 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); | 139 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); |
| 145 #else | 140 #else |
| 146 header->fExperimentalGS = false; | 141 header->fExperimentalGS = false; |
| 147 #endif | 142 #endif |
| 148 #endif | 143 #endif |
| 149 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p
athRenderingSupport(); | 144 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p
athRenderingSupport(); |
| 150 | 145 |
| 151 if (colorIsTransBlack) { | 146 if (defaultToUniformInputs && !requiresColorAttrib) { |
| 152 header->fColorInput = kTransBlack_ColorInput; | |
| 153 } else if (colorIsSolidWhite) { | |
| 154 header->fColorInput = kSolidWhite_ColorInput; | |
| 155 } else if (defaultToUniformInputs && !requiresColorAttrib) { | |
| 156 header->fColorInput = kUniform_ColorInput; | 147 header->fColorInput = kUniform_ColorInput; |
| 157 } else { | 148 } else { |
| 158 header->fColorInput = kAttribute_ColorInput; | 149 header->fColorInput = kAttribute_ColorInput; |
| 159 header->fHasVertexCode = true; | 150 header->fHasVertexCode = true; |
| 160 } | 151 } |
| 161 | 152 |
| 162 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge
tCoverageColor(); | 153 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge
tCoverageColor(); |
| 163 | 154 |
| 164 if (skipCoverage) { | 155 if (covIsSolidWhite || !inputCoverageIsUsed) { |
| 165 header->fCoverageInput = kTransBlack_ColorInput; | |
| 166 } else if (covIsSolidWhite || !inputCoverageIsUsed) { | |
| 167 header->fCoverageInput = kSolidWhite_ColorInput; | 156 header->fCoverageInput = kSolidWhite_ColorInput; |
| 168 } else if (defaultToUniformInputs && !requiresCoverageAttrib) { | 157 } else if (defaultToUniformInputs && !requiresCoverageAttrib) { |
| 169 header->fCoverageInput = kUniform_ColorInput; | 158 header->fCoverageInput = kUniform_ColorInput; |
| 170 } else { | 159 } else { |
| 171 header->fCoverageInput = kAttribute_ColorInput; | 160 header->fCoverageInput = kAttribute_ColorInput; |
| 172 header->fHasVertexCode = true; | 161 header->fHasVertexCode = true; |
| 173 } | 162 } |
| 174 | 163 |
| 175 if (readsDst) { | 164 if (readsDst) { |
| 176 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); | 165 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 265 |
| 277 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 266 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
| 278 fInitialized = other.fInitialized; | 267 fInitialized = other.fInitialized; |
| 279 if (fInitialized) { | 268 if (fInitialized) { |
| 280 size_t keyLength = other.keyLength(); | 269 size_t keyLength = other.keyLength(); |
| 281 fKey.reset(keyLength); | 270 fKey.reset(keyLength); |
| 282 memcpy(fKey.get(), other.fKey.get(), keyLength); | 271 memcpy(fKey.get(), other.fKey.get(), keyLength); |
| 283 } | 272 } |
| 284 return *this; | 273 return *this; |
| 285 } | 274 } |
| OLD | NEW |