| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrDrawState.h" | 8 #include "GrDrawState.h" |
| 9 #include "GrPaint.h" | 9 #include "GrPaint.h" |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // These have no equivalent in GrPaint, set them to defaults | 47 // These have no equivalent in GrPaint, set them to defaults |
| 48 fCommon.fBlendConstant = 0x0; | 48 fCommon.fBlendConstant = 0x0; |
| 49 fCommon.fDrawFace = kBoth_DrawFace; | 49 fCommon.fDrawFace = kBoth_DrawFace; |
| 50 fCommon.fStencilSettings.setDisabled(); | 50 fCommon.fStencilSettings.setDisabled(); |
| 51 this->resetStateFlags(); | 51 this->resetStateFlags(); |
| 52 | 52 |
| 53 // Enable the clip bit | 53 // Enable the clip bit |
| 54 this->enableState(GrDrawState::kClip_StateBit); | 54 this->enableState(GrDrawState::kClip_StateBit); |
| 55 | 55 |
| 56 this->setColor(paint.getColor()); | 56 this->setColor(paint.getColor()); |
| 57 this->setCoverage4(paint.getCoverage()); | |
| 58 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 57 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 59 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 58 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
| 60 | 59 |
| 61 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | 60 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
| 62 this->setCoverage(paint.getCoverage()); | 61 this->setCoverage(paint.getCoverage()); |
| 63 } | 62 } |
| 64 | 63 |
| 65 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
| 66 | 65 |
| 67 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { | 66 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 212 } |
| 214 | 213 |
| 215 // Run through the color stages | 214 // Run through the color stages |
| 216 for (int s = 0; s < fColorStages.count(); ++s) { | 215 for (int s = 0; s < fColorStages.count(); ++s) { |
| 217 const GrEffectRef* effect = fColorStages[s].getEffect(); | 216 const GrEffectRef* effect = fColorStages[s].getEffect(); |
| 218 (*effect)->getConstantColorComponents(&color, &validComponentFlags); | 217 (*effect)->getConstantColorComponents(&color, &validComponentFlags); |
| 219 } | 218 } |
| 220 | 219 |
| 221 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 220 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
| 222 if (this->isCoverageDrawing()) { | 221 if (this->isCoverageDrawing()) { |
| 223 GrColor coverageColor = this->getCoverage(); | 222 GrColor coverageColor = this->getCoverageColor(); |
| 224 GrColor oldColor = color; | 223 GrColor oldColor = color; |
| 225 color = 0; | 224 color = 0; |
| 226 for (int c = 0; c < 4; ++c) { | 225 for (int c = 0; c < 4; ++c) { |
| 227 if (validComponentFlags & (1 << c)) { | 226 if (validComponentFlags & (1 << c)) { |
| 228 U8CPU a = (oldColor >> (c * 8)) & 0xff; | 227 U8CPU a = (oldColor >> (c * 8)) & 0xff; |
| 229 U8CPU b = (coverageColor >> (c * 8)) & 0xff; | 228 U8CPU b = (coverageColor >> (c * 8)) & 0xff; |
| 230 color |= (SkMulDiv255Round(a, b) << (c * 8)); | 229 color |= (SkMulDiv255Round(a, b) << (c * 8)); |
| 231 } | 230 } |
| 232 } | 231 } |
| 233 for (int s = 0; s < fCoverageStages.count(); ++s) { | 232 for (int s = 0; s < fCoverageStages.count(); ++s) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 304 } |
| 306 | 305 |
| 307 bool srcAIsOne = this->srcAlphaWillBeOne(); | 306 bool srcAIsOne = this->srcAlphaWillBeOne(); |
| 308 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || | 307 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || |
| 309 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 308 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 310 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || | 309 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || |
| 311 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 310 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 312 | 311 |
| 313 bool covIsZero = !this->isCoverageDrawing() && | 312 bool covIsZero = !this->isCoverageDrawing() && |
| 314 !this->hasCoverageVertexAttribute() && | 313 !this->hasCoverageVertexAttribute() && |
| 315 0 == this->getCoverage(); | 314 0 == this->getCoverageColor(); |
| 316 // When coeffs are (0,1) there is no reason to draw at all, unless | 315 // When coeffs are (0,1) there is no reason to draw at all, unless |
| 317 // stenciling is enabled. Having color writes disabled is effectively | 316 // stenciling is enabled. Having color writes disabled is effectively |
| 318 // (0,1). The same applies when coverage is known to be 0. | 317 // (0,1). The same applies when coverage is known to be 0. |
| 319 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { | 318 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { |
| 320 if (this->getStencil().doesWrite()) { | 319 if (this->getStencil().doesWrite()) { |
| 321 return kDisableBlend_BlendOptFlag | | 320 return kDisableBlend_BlendOptFlag | |
| 322 kEmitCoverage_BlendOptFlag; | 321 kEmitCoverage_BlendOptFlag; |
| 323 } else { | 322 } else { |
| 324 return kSkipDraw_BlendOptFlag; | 323 return kSkipDraw_BlendOptFlag; |
| 325 } | 324 } |
| 326 } | 325 } |
| 327 | 326 |
| 328 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage | 327 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage |
| 329 bool hasCoverage = forceCoverage || | 328 bool hasCoverage = forceCoverage || |
| 330 0xffffffff != this->getCoverage() || | 329 0xffffffff != this->getCoverageColor() || |
| 331 this->hasCoverageVertexAttribute() || | 330 this->hasCoverageVertexAttribute() || |
| 332 fCoverageStages.count() > 0; | 331 fCoverageStages.count() > 0; |
| 333 | 332 |
| 334 // if we don't have coverage we can check whether the dst | 333 // if we don't have coverage we can check whether the dst |
| 335 // has to read at all. If not, we'll disable blending. | 334 // has to read at all. If not, we'll disable blending. |
| 336 if (!hasCoverage) { | 335 if (!hasCoverage) { |
| 337 if (dstCoeffIsZero) { | 336 if (dstCoeffIsZero) { |
| 338 if (kOne_GrBlendCoeff == *srcCoeff) { | 337 if (kOne_GrBlendCoeff == *srcCoeff) { |
| 339 // if there is no coverage and coeffs are (1,0) then we | 338 // if there is no coverage and coeffs are (1,0) then we |
| 340 // won't need to read the dst at all, it gets replaced by src | 339 // won't need to read the dst at all, it gets replaced by src |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 466 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 468 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 467 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
| 469 } | 468 } |
| 470 | 469 |
| 471 int numCoverageStages = fDrawState->numCoverageStages(); | 470 int numCoverageStages = fDrawState->numCoverageStages(); |
| 472 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 471 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 473 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 472 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 474 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 473 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
| 475 } | 474 } |
| 476 } | 475 } |
| OLD | NEW |