| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrRODrawState.h" | 8 #include "GrRODrawState.h" |
| 9 | 9 |
| 10 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 GrBlendCoeff* srcCoeff, | 177 GrBlendCoeff* srcCoeff, |
| 178 GrBlendCoeff* dstCoeff)
const { | 178 GrBlendCoeff* dstCoeff)
const { |
| 179 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 179 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| 180 if (NULL == srcCoeff) { | 180 if (NULL == srcCoeff) { |
| 181 srcCoeff = &bogusSrcCoeff; | 181 srcCoeff = &bogusSrcCoeff; |
| 182 } | 182 } |
| 183 if (NULL == dstCoeff) { | 183 if (NULL == dstCoeff) { |
| 184 dstCoeff = &bogusDstCoeff; | 184 dstCoeff = &bogusDstCoeff; |
| 185 } | 185 } |
| 186 | 186 |
| 187 if (forceCoverage) { | |
| 188 return this->calcBlendOpts(true, srcCoeff, dstCoeff); | |
| 189 } | |
| 190 | |
| 191 if (0 == (fBlendOptFlags & kInvalid_BlendOptFlag)) { | |
| 192 *srcCoeff = fOptSrcBlend; | |
| 193 *dstCoeff = fOptDstBlend; | |
| 194 return fBlendOptFlags; | |
| 195 } | |
| 196 | |
| 197 fBlendOptFlags = this->calcBlendOpts(forceCoverage, srcCoeff, dstCoeff); | |
| 198 fOptSrcBlend = *srcCoeff; | |
| 199 fOptDstBlend = *dstCoeff; | |
| 200 | |
| 201 return fBlendOptFlags; | |
| 202 } | |
| 203 | |
| 204 GrRODrawState::BlendOptFlags GrRODrawState::calcBlendOpts(bool forceCoverage, | |
| 205 GrBlendCoeff* srcCoeff
, | |
| 206 GrBlendCoeff* dstCoeff
) const { | |
| 207 *srcCoeff = this->getSrcBlendCoeff(); | 187 *srcCoeff = this->getSrcBlendCoeff(); |
| 208 *dstCoeff = this->getDstBlendCoeff(); | 188 *dstCoeff = this->getDstBlendCoeff(); |
| 209 | 189 |
| 210 if (this->isColorWriteDisabled()) { | 190 if (this->isColorWriteDisabled()) { |
| 211 *srcCoeff = kZero_GrBlendCoeff; | 191 *srcCoeff = kZero_GrBlendCoeff; |
| 212 *dstCoeff = kOne_GrBlendCoeff; | 192 *dstCoeff = kOne_GrBlendCoeff; |
| 213 } | 193 } |
| 214 | 194 |
| 215 bool srcAIsOne = this->srcAlphaWillBeOne(); | 195 bool srcAIsOne = this->srcAlphaWillBeOne(); |
| 216 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || | 196 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || |
| 217 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 197 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 218 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || | 198 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || |
| 219 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 199 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 220 | 200 |
| 221 // When coeffs are (0,1) there is no reason to draw at all, unless | 201 // When coeffs are (0,1) there is no reason to draw at all, unless |
| 222 // stenciling is enabled. Having color writes disabled is effectively | 202 // stenciling is enabled. Having color writes disabled is effectively |
| 223 // (0,1). | 203 // (0,1). |
| 224 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne)) { | 204 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne)) { |
| 225 if (this->getStencil().doesWrite()) { | 205 if (this->getStencil().doesWrite()) { |
| 226 return kEmitCoverage_BlendOptFlag; | 206 return kEmitCoverage_BlendOptFlag; |
| 227 } else { | 207 } else { |
| 208 *dstCoeff = kOne_GrBlendCoeff; |
| 228 return kSkipDraw_BlendOptFlag; | 209 return kSkipDraw_BlendOptFlag; |
| 229 } | 210 } |
| 230 } | 211 } |
| 231 | 212 |
| 232 bool hasCoverage = forceCoverage || !this->hasSolidCoverage(); | 213 bool hasCoverage = forceCoverage || !this->hasSolidCoverage(); |
| 233 | 214 |
| 234 // if we don't have coverage we can check whether the dst | 215 // if we don't have coverage we can check whether the dst |
| 235 // has to read at all. If not, we'll disable blending. | 216 // has to read at all. If not, we'll disable blending. |
| 236 if (!hasCoverage) { | 217 if (!hasCoverage) { |
| 237 if (dstCoeffIsZero) { | 218 if (dstCoeffIsZero) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if | 346 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if |
| 366 // coverage and color both have A==1. | 347 // coverage and color both have A==1. |
| 367 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && | 348 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && |
| 368 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); | 349 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); |
| 369 | 350 |
| 370 } | 351 } |
| 371 | 352 |
| 372 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); | 353 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); |
| 373 } | 354 } |
| 374 | 355 |
| 375 //////////////////////////////////////////////////////////////////////////////// | |
| 376 | |
| 377 bool GrRODrawState::canIgnoreColorAttribute() const { | |
| 378 if (fBlendOptFlags & kInvalid_BlendOptFlag) { | |
| 379 this->getBlendOpts(); | |
| 380 } | |
| 381 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla
g | | |
| 382 GrRODrawState::kEmitCoverage_BlendOptFlag)
); | |
| 383 } | |
| 384 | |
| OLD | NEW |