| 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 #include "GrGLProgramDesc.h" | 7 #include "GrGLProgramDesc.h" |
| 8 | 8 |
| 9 #include "GrGLProcessor.h" | 9 #include "GrGLProcessor.h" |
| 10 #include "GrBackendProcessorFactory.h" | 10 #include "GrBackendProcessorFactory.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // alpha-only textures smear alpha across all four channels when rea
d. | 56 // alpha-only textures smear alpha across all four channels when rea
d. |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 | 62 |
| 63 static uint32_t gen_attrib_key(const GrGeometryProcessor& proc) { | 63 static uint32_t gen_attrib_key(const GrGeometryProcessor& proc) { |
| 64 uint32_t key = 0; | 64 uint32_t key = 0; |
| 65 | 65 |
| 66 const GrGeometryProcessor::VertexAttribArray& vars = proc.getVertexAttribs()
; | 66 const GrGeometryProcessor::VertexAttribArray& vars = proc.getAttribs(); |
| 67 int numAttributes = vars.count(); | 67 int numAttributes = vars.count(); |
| 68 SkASSERT(numAttributes <= 2); | 68 SkASSERT(numAttributes <= GrGeometryProcessor::kMaxVertexAttribs); |
| 69 for (int a = 0; a < numAttributes; ++a) { | 69 for (int a = 0; a < numAttributes; ++a) { |
| 70 uint32_t value = 1 << a; | 70 uint32_t value = 1 << a; |
| 71 key |= value; | 71 key |= value; |
| 72 } | 72 } |
| 73 return key; | 73 return key; |
| 74 } | 74 } |
| 75 | 75 |
| 76 static uint32_t gen_transform_key(const GrPendingFragmentStage& stage, | 76 static uint32_t gen_transform_key(const GrPendingFragmentStage& stage, |
| 77 bool useExplicitLocalCoords) { | 77 bool useExplicitLocalCoords) { |
| 78 uint32_t totalKey = 0; | 78 uint32_t totalKey = 0; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; | 199 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; |
| 200 | 200 |
| 201 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); | 201 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); |
| 202 if (gpu->caps()->pathRenderingSupport() && isPathRendering) { | 202 if (gpu->caps()->pathRenderingSupport() && isPathRendering) { |
| 203 header->fUseNvpr = true; | 203 header->fUseNvpr = true; |
| 204 SkASSERT(!optState.hasGeometryProcessor()); | 204 SkASSERT(!optState.hasGeometryProcessor()); |
| 205 } else { | 205 } else { |
| 206 header->fUseNvpr = false; | 206 header->fUseNvpr = false; |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool hasUniformColor = inputColorIsUsed && | 209 bool hasUniformColor = inputColorIsUsed && (isPathRendering || !descInfo.fHa
sVertexColor); |
| 210 (isPathRendering || !descInfo.hasColorVertexAttribute
()); | |
| 211 | |
| 212 bool hasUniformCoverage = inputCoverageIsUsed && | |
| 213 (isPathRendering || !descInfo.hasCoverageVertexAtt
ribute()); | |
| 214 | 210 |
| 215 if (!inputColorIsUsed) { | 211 if (!inputColorIsUsed) { |
| 216 header->fColorInput = GrProgramDesc::kAllOnes_ColorInput; | 212 header->fColorInput = GrProgramDesc::kAllOnes_ColorInput; |
| 217 } else if (hasUniformColor) { | 213 } else if (hasUniformColor) { |
| 218 header->fColorInput = GrProgramDesc::kUniform_ColorInput; | 214 header->fColorInput = GrProgramDesc::kUniform_ColorInput; |
| 219 } else { | 215 } else { |
| 220 header->fColorInput = GrProgramDesc::kAttribute_ColorInput; | 216 header->fColorInput = GrProgramDesc::kAttribute_ColorInput; |
| 221 SkASSERT(!header->fUseNvpr); | 217 SkASSERT(!header->fUseNvpr); |
| 222 } | 218 } |
| 223 | 219 |
| 224 bool covIsSolidWhite = !descInfo.hasCoverageVertexAttribute() && | 220 bool hasVertexCoverage = !isPathRendering && descInfo.fHasVertexCoverage; |
| 225 0xffffffff == optState.getCoverageColor(); | 221 |
| 222 bool covIsSolidWhite = !hasVertexCoverage && 0xffffffff == optState.getCover
ageColor(); |
| 226 | 223 |
| 227 if (covIsSolidWhite || !inputCoverageIsUsed) { | 224 if (covIsSolidWhite || !inputCoverageIsUsed) { |
| 228 header->fCoverageInput = GrProgramDesc::kAllOnes_ColorInput; | 225 header->fCoverageInput = GrProgramDesc::kAllOnes_ColorInput; |
| 229 } else if (hasUniformCoverage) { | 226 } else if (!hasVertexCoverage) { |
| 230 header->fCoverageInput = GrProgramDesc::kUniform_ColorInput; | 227 header->fCoverageInput = GrProgramDesc::kUniform_ColorInput; |
| 231 } else { | 228 } else { |
| 232 header->fCoverageInput = GrProgramDesc::kAttribute_ColorInput; | 229 header->fCoverageInput = GrProgramDesc::kAttribute_ColorInput; |
| 233 SkASSERT(!header->fUseNvpr); | 230 SkASSERT(!header->fUseNvpr); |
| 234 } | 231 } |
| 235 | 232 |
| 236 if (descInfo.fReadsDst) { | 233 if (descInfo.fReadsDst) { |
| 237 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); | 234 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); |
| 238 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); | 235 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); |
| 239 const GrTexture* dstCopyTexture = NULL; | 236 const GrTexture* dstCopyTexture = NULL; |
| 240 if (dstCopy) { | 237 if (dstCopy) { |
| 241 dstCopyTexture = dstCopy->texture(); | 238 dstCopyTexture = dstCopy->texture(); |
| 242 } | 239 } |
| 243 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, | 240 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, |
| 244 gpu->glCa
ps()); | 241 gpu->glCa
ps()); |
| 245 SkASSERT(0 != header->fDstReadKey); | 242 SkASSERT(0 != header->fDstReadKey); |
| 246 } else { | 243 } else { |
| 247 header->fDstReadKey = 0; | 244 header->fDstReadKey = 0; |
| 248 } | 245 } |
| 249 | 246 |
| 250 if (descInfo.fReadsFragPosition) { | 247 if (descInfo.fReadsFragPosition) { |
| 251 header->fFragPosKey = | 248 header->fFragPosKey = |
| 252 GrGLFragmentShaderBuilder::KeyForFragmentPosition(optState.getRe
nderTarget(), | 249 GrGLFragmentShaderBuilder::KeyForFragmentPosition(optState.getRe
nderTarget(), |
| 253 gpu->glCaps())
; | 250 gpu->glCaps())
; |
| 254 } else { | 251 } else { |
| 255 header->fFragPosKey = 0; | 252 header->fFragPosKey = 0; |
| 256 } | 253 } |
| 257 | 254 |
| 258 // Record attribute indices | |
| 259 header->fPositionAttributeIndex = descInfo.positionAttributeIndex(); | |
| 260 header->fLocalCoordAttributeIndex = descInfo.localCoordAttributeIndex(); | |
| 261 | |
| 262 // For constant color and coverage we need an attribute with an index beyond
those already set | |
| 263 int availableAttributeIndex = optState.getVertexAttribCount(); | |
| 264 if (descInfo.hasColorVertexAttribute()) { | |
| 265 header->fColorAttributeIndex = descInfo.colorVertexAttributeIndex(); | |
| 266 } else if (GrProgramDesc::kAttribute_ColorInput == header->fColorInput) { | |
| 267 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | |
| 268 header->fColorAttributeIndex = availableAttributeIndex; | |
| 269 availableAttributeIndex++; | |
| 270 } else { | |
| 271 header->fColorAttributeIndex = -1; | |
| 272 } | |
| 273 | |
| 274 if (descInfo.hasCoverageVertexAttribute()) { | |
| 275 header->fCoverageAttributeIndex = descInfo.coverageVertexAttributeIndex(
); | |
| 276 } else if (GrProgramDesc::kAttribute_ColorInput == header->fCoverageInput) { | |
| 277 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | |
| 278 header->fCoverageAttributeIndex = availableAttributeIndex; | |
| 279 } else { | |
| 280 header->fCoverageAttributeIndex = -1; | |
| 281 } | |
| 282 | |
| 283 header->fPrimaryOutputType = descInfo.fPrimaryOutputType; | 255 header->fPrimaryOutputType = descInfo.fPrimaryOutputType; |
| 284 header->fSecondaryOutputType = descInfo.fSecondaryOutputType; | 256 header->fSecondaryOutputType = descInfo.fSecondaryOutputType; |
| 285 | 257 |
| 286 header->fColorEffectCnt = optState.numColorStages(); | 258 header->fColorEffectCnt = optState.numColorStages(); |
| 287 header->fCoverageEffectCnt = optState.numCoverageStages(); | 259 header->fCoverageEffectCnt = optState.numCoverageStages(); |
| 288 desc->finalize(); | 260 desc->finalize(); |
| 289 return true; | 261 return true; |
| 290 } | 262 } |
| OLD | NEW |