| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 | 336 |
| 337 if (requiresCoverageAttrib) { | 337 if (requiresCoverageAttrib) { |
| 338 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex(
); | 338 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex(
); |
| 339 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput)
{ | 339 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput)
{ |
| 340 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | 340 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
| 341 header->fCoverageAttributeIndex = availableAttributeIndex; | 341 header->fCoverageAttributeIndex = availableAttributeIndex; |
| 342 } else { | 342 } else { |
| 343 header->fCoverageAttributeIndex = -1; | 343 header->fCoverageAttributeIndex = -1; |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Here we deal with whether/how we handle color and coverage separately. | 346 header->fPrimaryOutputType = optState.getPrimaryOutputType(); |
| 347 | 347 header->fSecondaryOutputType = optState.getSecondaryOutputType(); |
| 348 // Set this default and then possibly change our mind if there is coverage. | |
| 349 header->fCoverageOutput = kModulate_CoverageOutput; | |
| 350 | |
| 351 // If we do have coverage determine whether it matters. | |
| 352 bool separateCoverageFromColor = optState.hasGeometryProcessor(); | |
| 353 if (!optState.isCoverageDrawing() && | |
| 354 (optState.numCoverageStages() > 0 || | |
| 355 optState.hasGeometryProcessor() || | |
| 356 requiresCoverageAttrib)) { | |
| 357 | |
| 358 if (gpu->caps()->dualSourceBlendingSupport()) { | |
| 359 if (kZero_GrBlendCoeff == dstCoeff) { | |
| 360 // write the coverage value to second color | |
| 361 header->fCoverageOutput = kSecondaryCoverage_CoverageOutput; | |
| 362 separateCoverageFromColor = true; | |
| 363 } else if (kSA_GrBlendCoeff == dstCoeff) { | |
| 364 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
| 365 header->fCoverageOutput = kSecondaryCoverageISA_CoverageOutput; | |
| 366 separateCoverageFromColor = true; | |
| 367 } else if (kSC_GrBlendCoeff == dstCoeff) { | |
| 368 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
| 369 header->fCoverageOutput = kSecondaryCoverageISC_CoverageOutput; | |
| 370 separateCoverageFromColor = true; | |
| 371 } | |
| 372 } else if (optState.readsDst() && | |
| 373 kOne_GrBlendCoeff == srcCoeff && | |
| 374 kZero_GrBlendCoeff == dstCoeff) { | |
| 375 header->fCoverageOutput = kCombineWithDst_CoverageOutput; | |
| 376 separateCoverageFromColor = true; | |
| 377 } | |
| 378 } | |
| 379 | 348 |
| 380 for (int s = 0; s < optState.numColorStages(); ++s) { | 349 for (int s = 0; s < optState.numColorStages(); ++s) { |
| 381 colorStages->push_back(&optState.getColorStage(s)); | 350 colorStages->push_back(&optState.getColorStage(s)); |
| 382 } | 351 } |
| 383 SkTArray<const GrEffectStage*, true>* array; | |
| 384 if (separateCoverageFromColor) { | |
| 385 array = coverageStages; | |
| 386 } else { | |
| 387 array = colorStages; | |
| 388 } | |
| 389 for (int s = 0; s < optState.numCoverageStages(); ++s) { | 352 for (int s = 0; s < optState.numCoverageStages(); ++s) { |
| 390 array->push_back(&optState.getCoverageStage(s)); | 353 coverageStages->push_back(&optState.getCoverageStage(s)); |
| 391 } | 354 } |
| 392 | 355 |
| 393 header->fColorEffectCnt = colorStages->count(); | 356 header->fColorEffectCnt = colorStages->count(); |
| 394 header->fCoverageEffectCnt = coverageStages->count(); | 357 header->fCoverageEffectCnt = coverageStages->count(); |
| 395 | 358 |
| 396 desc->finalize(); | 359 desc->finalize(); |
| 397 return true; | 360 return true; |
| 398 } | 361 } |
| 399 | 362 |
| 400 void GrGLProgramDesc::finalize() { | 363 void GrGLProgramDesc::finalize() { |
| 401 int keyLength = fKey.count(); | 364 int keyLength = fKey.count(); |
| 402 SkASSERT(0 == (keyLength % 4)); | 365 SkASSERT(0 == (keyLength % 4)); |
| 403 *this->atOffset<uint32_t, kLengthOffset>() = SkToU32(keyLength); | 366 *this->atOffset<uint32_t, kLengthOffset>() = SkToU32(keyLength); |
| 404 | 367 |
| 405 uint32_t* checksum = this->atOffset<uint32_t, kChecksumOffset>(); | 368 uint32_t* checksum = this->atOffset<uint32_t, kChecksumOffset>(); |
| 406 *checksum = 0; | 369 *checksum = 0; |
| 407 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); | 370 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); |
| 408 } | 371 } |
| 409 | 372 |
| 410 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 373 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
| 411 size_t keyLength = other.keyLength(); | 374 size_t keyLength = other.keyLength(); |
| 412 fKey.reset(keyLength); | 375 fKey.reset(keyLength); |
| 413 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 376 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
| 414 return *this; | 377 return *this; |
| 415 } | 378 } |
| OLD | NEW |