| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 if (requiresCoverageAttrib) { | 214 if (requiresCoverageAttrib) { |
| 215 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex(
); | 215 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex(
); |
| 216 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput)
{ | 216 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput)
{ |
| 217 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | 217 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
| 218 header->fCoverageAttributeIndex = availableAttributeIndex; | 218 header->fCoverageAttributeIndex = availableAttributeIndex; |
| 219 } else { | 219 } else { |
| 220 header->fCoverageAttributeIndex = -1; | 220 header->fCoverageAttributeIndex = -1; |
| 221 } | 221 } |
| 222 | 222 |
| 223 // Here we deal with whether/how we handle color and coverage separately. | 223 header->fPrimaryOutputType = optState.getPrimaryOutputType(); |
| 224 | 224 header->fSecondaryOutputType = optState.getSecondaryOutputType(); |
| 225 // Set this default and then possibly change our mind if there is coverage. | |
| 226 header->fCoverageOutput = kModulate_CoverageOutput; | |
| 227 | |
| 228 // If we do have coverage determine whether it matters. | |
| 229 bool separateCoverageFromColor = optState.hasGeometryProcessor(); | |
| 230 if (!optState.isCoverageDrawing() && | |
| 231 (optState.numCoverageStages() > 0 || | |
| 232 optState.hasGeometryProcessor() || | |
| 233 requiresCoverageAttrib)) { | |
| 234 | |
| 235 if (gpu->caps()->dualSourceBlendingSupport()) { | |
| 236 if (kZero_GrBlendCoeff == dstCoeff) { | |
| 237 // write the coverage value to second color | |
| 238 header->fCoverageOutput = kSecondaryCoverage_CoverageOutput; | |
| 239 separateCoverageFromColor = true; | |
| 240 } else if (kSA_GrBlendCoeff == dstCoeff) { | |
| 241 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
| 242 header->fCoverageOutput = kSecondaryCoverageISA_CoverageOutput; | |
| 243 separateCoverageFromColor = true; | |
| 244 } else if (kSC_GrBlendCoeff == dstCoeff) { | |
| 245 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
| 246 header->fCoverageOutput = kSecondaryCoverageISC_CoverageOutput; | |
| 247 separateCoverageFromColor = true; | |
| 248 } | |
| 249 } else if (optState.readsDst() && | |
| 250 kOne_GrBlendCoeff == srcCoeff && | |
| 251 kZero_GrBlendCoeff == dstCoeff) { | |
| 252 header->fCoverageOutput = kCombineWithDst_CoverageOutput; | |
| 253 separateCoverageFromColor = true; | |
| 254 } | |
| 255 } | |
| 256 | 225 |
| 257 for (int s = 0; s < optState.numColorStages(); ++s) { | 226 for (int s = 0; s < optState.numColorStages(); ++s) { |
| 258 colorStages->push_back(&optState.getColorStage(s)); | 227 colorStages->push_back(&optState.getColorStage(s)); |
| 259 } | 228 } |
| 260 SkTArray<const GrEffectStage*, true>* array; | |
| 261 if (separateCoverageFromColor) { | |
| 262 array = coverageStages; | |
| 263 } else { | |
| 264 array = colorStages; | |
| 265 } | |
| 266 for (int s = 0; s < optState.numCoverageStages(); ++s) { | 229 for (int s = 0; s < optState.numCoverageStages(); ++s) { |
| 267 array->push_back(&optState.getCoverageStage(s)); | 230 coverageStages->push_back(&optState.getCoverageStage(s)); |
| 268 } | 231 } |
| 269 | 232 |
| 270 header->fColorEffectCnt = colorStages->count(); | 233 header->fColorEffectCnt = colorStages->count(); |
| 271 header->fCoverageEffectCnt = coverageStages->count(); | 234 header->fCoverageEffectCnt = coverageStages->count(); |
| 272 | 235 |
| 273 desc->finalize(); | 236 desc->finalize(); |
| 274 return true; | 237 return true; |
| 275 } | 238 } |
| 276 | 239 |
| 277 void GrGLProgramDesc::finalize() { | 240 void GrGLProgramDesc::finalize() { |
| 278 int keyLength = fKey.count(); | 241 int keyLength = fKey.count(); |
| 279 SkASSERT(0 == (keyLength % 4)); | 242 SkASSERT(0 == (keyLength % 4)); |
| 280 *this->atOffset<uint32_t, kLengthOffset>() = SkToU32(keyLength); | 243 *this->atOffset<uint32_t, kLengthOffset>() = SkToU32(keyLength); |
| 281 | 244 |
| 282 uint32_t* checksum = this->atOffset<uint32_t, kChecksumOffset>(); | 245 uint32_t* checksum = this->atOffset<uint32_t, kChecksumOffset>(); |
| 283 *checksum = 0; | 246 *checksum = 0; |
| 284 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); | 247 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); |
| 285 } | 248 } |
| 286 | 249 |
| 287 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 250 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
| 288 size_t keyLength = other.keyLength(); | 251 size_t keyLength = other.keyLength(); |
| 289 fKey.reset(keyLength); | 252 fKey.reset(keyLength); |
| 290 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 253 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
| 291 return *this; | 254 return *this; |
| 292 } | 255 } |
| OLD | NEW |