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 |
92 int numEffects = (skipColor ? 0 : (drawState.numColorStages() - firstEffecti
veColorStage)) + | 97 int numEffects = (skipColor ? 0 : (drawState.numColorStages() - firstEffecti
veColorStage)) + |
93 (skipCoverage ? 0 : (drawState.numCoverageStages() - firstE
ffectiveCoverageStage)); | 98 (skipCoverage ? 0 : (drawState.numCoverageStages() - firstE
ffectiveCoverageStage)); |
94 | 99 |
95 size_t newKeyLength = KeyLength(numEffects); | 100 size_t newKeyLength = KeyLength(numEffects); |
96 bool allocChanged; | 101 bool allocChanged; |
97 desc->fKey.reset(newKeyLength, SkAutoMalloc::kAlloc_OnShrink, &allocChanged)
; | 102 desc->fKey.reset(newKeyLength, SkAutoMalloc::kAlloc_OnShrink, &allocChanged)
; |
98 if (allocChanged || !desc->fInitialized) { | 103 if (allocChanged || !desc->fInitialized) { |
99 // make sure any padding in the header is zero if we we haven't used thi
s allocation before. | 104 // make sure any padding in the header is zero if we we haven't used thi
s allocation before. |
100 memset(desc->header(), 0, kHeaderSize); | 105 memset(desc->header(), 0, kHeaderSize); |
101 } | 106 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // other than pass through values from the VS to the FS anyway). | 141 // other than pass through values from the VS to the FS anyway). |
137 #if GR_GL_EXPERIMENTAL_GS | 142 #if GR_GL_EXPERIMENTAL_GS |
138 #if 0 | 143 #if 0 |
139 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); | 144 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); |
140 #else | 145 #else |
141 header->fExperimentalGS = false; | 146 header->fExperimentalGS = false; |
142 #endif | 147 #endif |
143 #endif | 148 #endif |
144 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p
athRenderingSupport(); | 149 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p
athRenderingSupport(); |
145 | 150 |
146 if (defaultToUniformInputs && !requiresColorAttrib) { | 151 if (colorIsTransBlack) { |
| 152 header->fColorInput = kTransBlack_ColorInput; |
| 153 } else if (colorIsSolidWhite) { |
| 154 header->fColorInput = kSolidWhite_ColorInput; |
| 155 } else if (defaultToUniformInputs && !requiresColorAttrib) { |
147 header->fColorInput = kUniform_ColorInput; | 156 header->fColorInput = kUniform_ColorInput; |
148 } else { | 157 } else { |
149 header->fColorInput = kAttribute_ColorInput; | 158 header->fColorInput = kAttribute_ColorInput; |
150 header->fHasVertexCode = true; | 159 header->fHasVertexCode = true; |
151 } | 160 } |
152 | 161 |
153 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge
tCoverageColor(); | 162 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge
tCoverageColor(); |
154 | 163 |
155 if (covIsSolidWhite || !inputCoverageIsUsed) { | 164 if (skipCoverage) { |
| 165 header->fCoverageInput = kTransBlack_ColorInput; |
| 166 } else if (covIsSolidWhite || !inputCoverageIsUsed) { |
156 header->fCoverageInput = kSolidWhite_ColorInput; | 167 header->fCoverageInput = kSolidWhite_ColorInput; |
157 } else if (defaultToUniformInputs && !requiresCoverageAttrib) { | 168 } else if (defaultToUniformInputs && !requiresCoverageAttrib) { |
158 header->fCoverageInput = kUniform_ColorInput; | 169 header->fCoverageInput = kUniform_ColorInput; |
159 } else { | 170 } else { |
160 header->fCoverageInput = kAttribute_ColorInput; | 171 header->fCoverageInput = kAttribute_ColorInput; |
161 header->fHasVertexCode = true; | 172 header->fHasVertexCode = true; |
162 } | 173 } |
163 | 174 |
164 if (readsDst) { | 175 if (readsDst) { |
165 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); | 176 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 276 |
266 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 277 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
267 fInitialized = other.fInitialized; | 278 fInitialized = other.fInitialized; |
268 if (fInitialized) { | 279 if (fInitialized) { |
269 size_t keyLength = other.keyLength(); | 280 size_t keyLength = other.keyLength(); |
270 fKey.reset(keyLength); | 281 fKey.reset(keyLength); |
271 memcpy(fKey.get(), other.fKey.get(), keyLength); | 282 memcpy(fKey.get(), other.fKey.get(), keyLength); |
272 } | 283 } |
273 return *this; | 284 return *this; |
274 } | 285 } |
OLD | NEW |