| 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 "GrProcessor.h" | 10 #include "GrProcessor.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 key[0] = (textureKey << 16 | transformKey); | 151 key[0] = (textureKey << 16 | transformKey); |
| 152 key[1] = (classID << 16 | SkToU16(processorKeySize)); | 152 key[1] = (classID << 16 | SkToU16(processorKeySize)); |
| 153 return true; | 153 return true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool GrGLProgramDescBuilder::Build(const GrOptDrawState& optState, | 156 bool GrGLProgramDescBuilder::Build(const GrOptDrawState& optState, |
| 157 const GrProgramDesc::DescInfo& descInfo, | 157 const GrProgramDesc::DescInfo& descInfo, |
| 158 GrGpu::DrawType drawType, | 158 GrGpu::DrawType drawType, |
| 159 GrGpuGL* gpu, | 159 GrGpuGL* gpu, |
| 160 GrProgramDesc* desc) { | 160 GrProgramDesc* desc) { |
| 161 bool inputColorIsUsed = descInfo.fInputColorIsUsed; | |
| 162 bool inputCoverageIsUsed = descInfo.fInputCoverageIsUsed; | |
| 163 | |
| 164 // The descriptor is used as a cache key. Thus when a field of the | 161 // The descriptor is used as a cache key. Thus when a field of the |
| 165 // descriptor will not affect program generation (because of the attribute | 162 // descriptor will not affect program generation (because of the attribute |
| 166 // bindings in use or other descriptor field settings) it should be set | 163 // bindings in use or other descriptor field settings) it should be set |
| 167 // to a canonical value to avoid duplicate programs with different keys. | 164 // to a canonical value to avoid duplicate programs with different keys. |
| 168 | 165 |
| 169 bool requiresLocalCoordAttrib = descInfo.fRequiresLocalCoordAttrib; | 166 bool requiresLocalCoordAttrib = descInfo.fRequiresLocalCoordAttrib; |
| 170 | 167 |
| 171 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); | 168 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); |
| 172 // Make room for everything up to the effect keys. | 169 // Make room for everything up to the effect keys. |
| 173 desc->fKey.reset(); | 170 desc->fKey.reset(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 202 } |
| 206 | 203 |
| 207 // --------DO NOT MOVE HEADER ABOVE THIS LINE-------------------------------
------------------- | 204 // --------DO NOT MOVE HEADER ABOVE THIS LINE-------------------------------
------------------- |
| 208 // Because header is a pointer into the dynamic array, we can't push any new
data into the key | 205 // Because header is a pointer into the dynamic array, we can't push any new
data into the key |
| 209 // below here. | 206 // below here. |
| 210 GLKeyHeader* header = desc->atOffset<GLKeyHeader, kHeaderOffset>(); | 207 GLKeyHeader* header = desc->atOffset<GLKeyHeader, kHeaderOffset>(); |
| 211 | 208 |
| 212 // make sure any padding in the header is zeroed. | 209 // make sure any padding in the header is zeroed. |
| 213 memset(header, 0, kHeaderSize); | 210 memset(header, 0, kHeaderSize); |
| 214 | 211 |
| 215 header->fHasGeometryProcessor = optState.hasGeometryProcessor(); | |
| 216 | |
| 217 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); | 212 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); |
| 218 if (gpu->caps()->pathRenderingSupport() && isPathRendering) { | 213 if (gpu->caps()->pathRenderingSupport() && isPathRendering) { |
| 219 header->fUseNvpr = true; | 214 header->fUseNvpr = true; |
| 220 SkASSERT(!optState.hasGeometryProcessor()); | 215 SkASSERT(!optState.hasGeometryProcessor()); |
| 221 } else { | 216 } else { |
| 222 header->fUseNvpr = false; | 217 header->fUseNvpr = false; |
| 223 } | 218 } |
| 224 | 219 |
| 225 bool hasUniformColor = inputColorIsUsed && (isPathRendering || !descInfo.fHa
sVertexColor); | |
| 226 | |
| 227 if (!inputColorIsUsed) { | |
| 228 header->fColorInput = GrProgramDesc::kAllOnes_ColorInput; | |
| 229 } else if (hasUniformColor) { | |
| 230 header->fColorInput = GrProgramDesc::kUniform_ColorInput; | |
| 231 } else { | |
| 232 header->fColorInput = GrProgramDesc::kAttribute_ColorInput; | |
| 233 SkASSERT(!header->fUseNvpr); | |
| 234 } | |
| 235 | |
| 236 bool hasVertexCoverage = !isPathRendering && descInfo.fHasVertexCoverage; | |
| 237 | |
| 238 bool covIsSolidWhite = !hasVertexCoverage && 0xffffffff == optState.getCover
ageColor(); | |
| 239 | |
| 240 if (covIsSolidWhite || !inputCoverageIsUsed) { | |
| 241 header->fCoverageInput = GrProgramDesc::kAllOnes_ColorInput; | |
| 242 } else if (!hasVertexCoverage) { | |
| 243 header->fCoverageInput = GrProgramDesc::kUniform_ColorInput; | |
| 244 } else { | |
| 245 header->fCoverageInput = GrProgramDesc::kAttribute_ColorInput; | |
| 246 SkASSERT(!header->fUseNvpr); | |
| 247 } | |
| 248 | |
| 249 if (descInfo.fReadsDst) { | 220 if (descInfo.fReadsDst) { |
| 250 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); | 221 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); |
| 251 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); | 222 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); |
| 252 const GrTexture* dstCopyTexture = NULL; | 223 const GrTexture* dstCopyTexture = NULL; |
| 253 if (dstCopy) { | 224 if (dstCopy) { |
| 254 dstCopyTexture = dstCopy->texture(); | 225 dstCopyTexture = dstCopy->texture(); |
| 255 } | 226 } |
| 256 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, | 227 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, |
| 257 gpu->glCa
ps()); | 228 gpu->glCa
ps()); |
| 258 SkASSERT(0 != header->fDstReadKey); | 229 SkASSERT(0 != header->fDstReadKey); |
| 259 } else { | 230 } else { |
| 260 header->fDstReadKey = 0; | 231 header->fDstReadKey = 0; |
| 261 } | 232 } |
| 262 | 233 |
| 263 if (descInfo.fReadsFragPosition) { | 234 if (descInfo.fReadsFragPosition) { |
| 264 header->fFragPosKey = | 235 header->fFragPosKey = |
| 265 GrGLFragmentShaderBuilder::KeyForFragmentPosition(optState.getRe
nderTarget(), | 236 GrGLFragmentShaderBuilder::KeyForFragmentPosition(optState.getRe
nderTarget(), |
| 266 gpu->glCaps())
; | 237 gpu->glCaps())
; |
| 267 } else { | 238 } else { |
| 268 header->fFragPosKey = 0; | 239 header->fFragPosKey = 0; |
| 269 } | 240 } |
| 270 | 241 |
| 271 header->fColorEffectCnt = optState.numColorStages(); | 242 header->fColorEffectCnt = optState.numColorStages(); |
| 272 header->fCoverageEffectCnt = optState.numCoverageStages(); | 243 header->fCoverageEffectCnt = optState.numCoverageStages(); |
| 273 desc->finalize(); | 244 desc->finalize(); |
| 274 return true; | 245 return true; |
| 275 } | 246 } |
| OLD | NEW |