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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
9 #include "GrGLProgramDesc.h" | 9 #include "GrGLProgramDesc.h" |
10 #include "GrBackendEffectFactory.h" | 10 #include "GrBackendEffectFactory.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 coverageStages->reset(); | 173 coverageStages->reset(); |
174 | 174 |
175 bool inputColorIsUsed = optState.inputColorIsUsed(); | 175 bool inputColorIsUsed = optState.inputColorIsUsed(); |
176 bool inputCoverageIsUsed = optState.inputColorIsUsed(); | 176 bool inputCoverageIsUsed = optState.inputColorIsUsed(); |
177 | 177 |
178 // The descriptor is used as a cache key. Thus when a field of the | 178 // The descriptor is used as a cache key. Thus when a field of the |
179 // descriptor will not affect program generation (because of the attribute | 179 // descriptor will not affect program generation (because of the attribute |
180 // bindings in use or other descriptor field settings) it should be set | 180 // bindings in use or other descriptor field settings) it should be set |
181 // to a canonical value to avoid duplicate programs with different keys. | 181 // to a canonical value to avoid duplicate programs with different keys. |
182 | 182 |
183 bool requiresColorAttrib = optState.hasColorVertexAttribute(); | |
184 bool requiresCoverageAttrib = optState.hasCoverageVertexAttribute(); | |
185 bool requiresLocalCoordAttrib = optState.requiresLocalCoordAttrib(); | 183 bool requiresLocalCoordAttrib = optState.requiresLocalCoordAttrib(); |
186 | 184 |
187 int numStages = optState.numTotalStages(); | 185 int numStages = optState.numTotalStages(); |
188 | 186 |
189 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 187 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
190 // Make room for everything up to and including the array of offsets to effe
ct keys. | 188 // Make room for everything up to and including the array of offsets to effe
ct keys. |
191 desc->fKey.reset(); | 189 desc->fKey.reset(); |
192 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_
t) * numStages); | 190 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_
t) * numStages); |
193 | 191 |
194 int offsetAndSizeIndex = 0; | 192 int offsetAndSizeIndex = 0; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 251 } |
254 | 252 |
255 if (!effectKeySuccess) { | 253 if (!effectKeySuccess) { |
256 desc->fKey.reset(); | 254 desc->fKey.reset(); |
257 return false; | 255 return false; |
258 } | 256 } |
259 | 257 |
260 // Because header is a pointer into the dynamic array, we can't push any new
data into the key | 258 // Because header is a pointer into the dynamic array, we can't push any new
data into the key |
261 // below here. | 259 // below here. |
262 | 260 |
263 header->fUseFragShaderOnly = gpu->caps()->pathRenderingSupport() && | |
264 GrGpu::IsPathRenderingDrawType(drawType) && | |
265 gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunct
ion_TexturingMode; | |
266 SkASSERT(!header->fUseFragShaderOnly || !optState.hasGeometryProcessor()); | |
267 | 261 |
268 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; | 262 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; |
269 | 263 |
270 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything | 264 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything |
271 // other than pass through values from the VS to the FS anyway). | 265 // other than pass through values from the VS to the FS anyway). |
272 #if GR_GL_EXPERIMENTAL_GS | 266 #if GR_GL_EXPERIMENTAL_GS |
273 #if 0 | 267 #if 0 |
274 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); | 268 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); |
275 #else | 269 #else |
276 header->fExperimentalGS = false; | 270 header->fExperimentalGS = false; |
277 #endif | 271 #endif |
278 #endif | 272 #endif |
279 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || header->fUseFr
agShaderOnly; | 273 |
| 274 if (gpu->caps()->pathRenderingSupport() && |
| 275 GrGpu::IsPathRenderingDrawType(drawType) && |
| 276 gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunct
ion_TexturingMode) { |
| 277 header->fUseFragShaderOnly = true; |
| 278 SkASSERT(!optState.hasGeometryProcessor()); |
| 279 } else { |
| 280 header->fUseFragShaderOnly = false; |
| 281 } |
| 282 |
| 283 bool defaultToUniformInputs = GrGpu::IsPathRenderingDrawType(drawType) || |
| 284 GR_GL_NO_CONSTANT_ATTRIBUTES; |
280 | 285 |
281 if (!inputColorIsUsed) { | 286 if (!inputColorIsUsed) { |
282 header->fColorInput = kAllOnes_ColorInput; | 287 header->fColorInput = kAllOnes_ColorInput; |
283 } else if (defaultToUniformInputs && !requiresColorAttrib) { | 288 } else if (defaultToUniformInputs && !optState.hasColorVertexAttribute()) { |
284 header->fColorInput = kUniform_ColorInput; | 289 header->fColorInput = kUniform_ColorInput; |
285 } else { | 290 } else { |
286 header->fColorInput = kAttribute_ColorInput; | 291 header->fColorInput = kAttribute_ColorInput; |
287 header->fUseFragShaderOnly = false; | 292 SkASSERT(!header->fUseFragShaderOnly); |
288 } | 293 } |
289 | 294 |
290 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == optState.get
CoverageColor(); | 295 bool covIsSolidWhite = !optState.hasCoverageVertexAttribute() && |
| 296 0xffffffff == optState.getCoverageColor(); |
291 | 297 |
292 if (covIsSolidWhite || !inputCoverageIsUsed) { | 298 if (covIsSolidWhite || !inputCoverageIsUsed) { |
293 header->fCoverageInput = kAllOnes_ColorInput; | 299 header->fCoverageInput = kAllOnes_ColorInput; |
294 } else if (defaultToUniformInputs && !requiresCoverageAttrib) { | 300 } else if (defaultToUniformInputs && !optState.hasCoverageVertexAttribute())
{ |
295 header->fCoverageInput = kUniform_ColorInput; | 301 header->fCoverageInput = kUniform_ColorInput; |
296 } else { | 302 } else { |
297 header->fCoverageInput = kAttribute_ColorInput; | 303 header->fCoverageInput = kAttribute_ColorInput; |
298 header->fUseFragShaderOnly = false; | 304 SkASSERT(!header->fUseFragShaderOnly); |
299 } | 305 } |
300 | 306 |
301 if (optState.readsDst()) { | 307 if (optState.readsDst()) { |
302 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); | 308 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); |
303 const GrTexture* dstCopyTexture = NULL; | 309 const GrTexture* dstCopyTexture = NULL; |
304 if (dstCopy) { | 310 if (dstCopy) { |
305 dstCopyTexture = dstCopy->texture(); | 311 dstCopyTexture = dstCopy->texture(); |
306 } | 312 } |
307 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, | 313 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, |
308 gpu->glCaps()); | 314 gpu->glCaps()); |
309 SkASSERT(0 != header->fDstReadKey); | 315 SkASSERT(0 != header->fDstReadKey); |
310 } else { | 316 } else { |
311 header->fDstReadKey = 0; | 317 header->fDstReadKey = 0; |
312 } | 318 } |
313 | 319 |
314 if (optState.readsFragPosition()) { | 320 if (optState.readsFragPosition()) { |
315 header->fFragPosKey = GrGLFragmentShaderBuilder::KeyForFragmentPosition( | 321 header->fFragPosKey = GrGLFragmentShaderBuilder::KeyForFragmentPosition( |
316 optState.getRenderTarget(), gpu->glCaps()); | 322 optState.getRenderTarget(), gpu->glCaps()); |
317 } else { | 323 } else { |
318 header->fFragPosKey = 0; | 324 header->fFragPosKey = 0; |
319 } | 325 } |
320 | 326 |
321 // Record attribute indices | 327 // Record attribute indices |
322 header->fPositionAttributeIndex = optState.positionAttributeIndex(); | 328 header->fPositionAttributeIndex = optState.positionAttributeIndex(); |
323 header->fLocalCoordAttributeIndex = optState.localCoordAttributeIndex(); | 329 header->fLocalCoordAttributeIndex = optState.localCoordAttributeIndex(); |
324 | 330 |
325 // For constant color and coverage we need an attribute with an index beyond
those already set | 331 // For constant color and coverage we need an attribute with an index beyond
those already set |
326 int availableAttributeIndex = optState.getVertexAttribCount(); | 332 int availableAttributeIndex = optState.getVertexAttribCount(); |
327 if (requiresColorAttrib) { | 333 if (optState.hasColorVertexAttribute()) { |
328 header->fColorAttributeIndex = optState.colorVertexAttributeIndex(); | 334 header->fColorAttributeIndex = optState.colorVertexAttributeIndex(); |
329 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fColorInput) { | 335 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fColorInput) { |
330 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | 336 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
331 header->fColorAttributeIndex = availableAttributeIndex; | 337 header->fColorAttributeIndex = availableAttributeIndex; |
332 availableAttributeIndex++; | 338 availableAttributeIndex++; |
333 } else { | 339 } else { |
334 header->fColorAttributeIndex = -1; | 340 header->fColorAttributeIndex = -1; |
335 } | 341 } |
336 | 342 |
337 if (requiresCoverageAttrib) { | 343 if (optState.hasCoverageVertexAttribute()) { |
338 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex(
); | 344 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex(
); |
339 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput)
{ | 345 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput)
{ |
340 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | 346 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
341 header->fCoverageAttributeIndex = availableAttributeIndex; | 347 header->fCoverageAttributeIndex = availableAttributeIndex; |
342 } else { | 348 } else { |
343 header->fCoverageAttributeIndex = -1; | 349 header->fCoverageAttributeIndex = -1; |
344 } | 350 } |
345 | 351 |
346 header->fPrimaryOutputType = optState.getPrimaryOutputType(); | 352 header->fPrimaryOutputType = optState.getPrimaryOutputType(); |
347 header->fSecondaryOutputType = optState.getSecondaryOutputType(); | 353 header->fSecondaryOutputType = optState.getSecondaryOutputType(); |
(...skipping 21 matching lines...) Expand all Loading... |
369 *checksum = 0; | 375 *checksum = 0; |
370 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); | 376 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); |
371 } | 377 } |
372 | 378 |
373 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 379 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
374 size_t keyLength = other.keyLength(); | 380 size_t keyLength = other.keyLength(); |
375 fKey.reset(keyLength); | 381 fKey.reset(keyLength); |
376 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 382 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
377 return *this; | 383 return *this; |
378 } | 384 } |
OLD | NEW |