| 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 | 9 |
| 10 #include "GrOptDrawState.h" | 10 #include "GrOptDrawState.h" |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 (this->willEffectReadDstColor() && | 414 (this->willEffectReadDstColor() && |
| 415 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff); | 415 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff); |
| 416 } | 416 } |
| 417 | 417 |
| 418 bool GrDrawState::hasSolidCoverage() const { | 418 bool GrDrawState::hasSolidCoverage() const { |
| 419 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 419 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
| 420 if (this->isCoverageDrawing()) { | 420 if (this->isCoverageDrawing()) { |
| 421 return true; | 421 return true; |
| 422 } | 422 } |
| 423 | 423 |
| 424 GrProcessor::InvariantOutput inout; | 424 GrColor coverage; |
| 425 inout.fIsSingleComponent = false; | 425 uint32_t validComponentFlags; |
| 426 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 426 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
| 427 if (this->hasCoverageVertexAttribute()) { | 427 if (this->hasCoverageVertexAttribute()) { |
| 428 inout.fValidFlags = 0; | 428 validComponentFlags = 0; |
| 429 } else { | 429 } else { |
| 430 inout.fColor = fCoverage; | 430 coverage = fCoverage; |
| 431 inout.fValidFlags = kRGBA_GrColorComponentFlags; | 431 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 432 } | 432 } |
| 433 | 433 |
| 434 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 434 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
| 435 if (this->hasGeometryProcessor()) { | 435 if (this->hasGeometryProcessor()) { |
| 436 const GrGeometryProcessor* gp = fGeometryProcessor->getGeometryProcessor
(); | 436 const GrGeometryProcessor* gp = fGeometryProcessor->getGeometryProcessor
(); |
| 437 gp->computeInvariantOutput(&inout); | 437 gp->getConstantColorComponents(&coverage, &validComponentFlags); |
| 438 } | 438 } |
| 439 for (int s = 0; s < this->numCoverageStages(); ++s) { | 439 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 440 const GrProcessor* processor = this->getCoverageStage(s).getProcessor(); | 440 const GrProcessor* processor = this->getCoverageStage(s).getProcessor(); |
| 441 processor->computeInvariantOutput(&inout); | 441 processor->getConstantColorComponents(&coverage, &validComponentFlags); |
| 442 } | 442 } |
| 443 return inout.isSolidWhite(); | 443 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); |
| 444 } | 444 } |
| 445 | 445 |
| 446 ////////////////////////////////////////////////////////////////////////////// | 446 ////////////////////////////////////////////////////////////////////////////// |
| 447 | 447 |
| 448 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(GrDrawState* drawS
tate) { | 448 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(GrDrawState* drawS
tate) { |
| 449 SkASSERT(drawState); | 449 SkASSERT(drawState); |
| 450 fDrawState = drawState; | 450 fDrawState = drawState; |
| 451 fVAPtr = drawState->fVAPtr; | 451 fVAPtr = drawState->fVAPtr; |
| 452 fVACount = drawState->fVACount; | 452 fVACount = drawState->fVACount; |
| 453 fVAStride = drawState->fVAStride; | 453 fVAStride = drawState->fVAStride; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 *dstCoeff = kOne_GrBlendCoeff; | 748 *dstCoeff = kOne_GrBlendCoeff; |
| 749 return kCoverageAsAlpha_BlendOptFlag; | 749 return kCoverageAsAlpha_BlendOptFlag; |
| 750 } | 750 } |
| 751 } | 751 } |
| 752 | 752 |
| 753 return kNone_BlendOpt; | 753 return kNone_BlendOpt; |
| 754 } | 754 } |
| 755 | 755 |
| 756 | 756 |
| 757 bool GrDrawState::srcAlphaWillBeOne() const { | 757 bool GrDrawState::srcAlphaWillBeOne() const { |
| 758 GrProcessor::InvariantOutput inoutColor; | 758 uint32_t validComponentFlags; |
| 759 inoutColor.fIsSingleComponent = false; | 759 GrColor color; |
| 760 // Check if per-vertex or constant color may have partial alpha | 760 // Check if per-vertex or constant color may have partial alpha |
| 761 if (this->hasColorVertexAttribute()) { | 761 if (this->hasColorVertexAttribute()) { |
| 762 if (fHints & kVertexColorsAreOpaque_Hint) { | 762 if (fHints & kVertexColorsAreOpaque_Hint) { |
| 763 inoutColor.fValidFlags = kA_GrColorComponentFlag; | 763 validComponentFlags = kA_GrColorComponentFlag; |
| 764 inoutColor.fColor = 0xFF << GrColor_SHIFT_A; | 764 color = 0xFF << GrColor_SHIFT_A; |
| 765 } else { | 765 } else { |
| 766 inoutColor.fValidFlags = 0; | 766 validComponentFlags = 0; |
| 767 // not strictly necessary but we get false alarms from tools about u
ninit. | 767 color = 0; // not strictly necessary but we get false alarms from to
ols about uninit. |
| 768 inoutColor.fColor = 0; | |
| 769 } | 768 } |
| 770 } else { | 769 } else { |
| 771 inoutColor.fValidFlags = kRGBA_GrColorComponentFlags; | 770 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 772 inoutColor.fColor = this->getColor(); | 771 color = this->getColor(); |
| 773 } | 772 } |
| 774 | 773 |
| 775 // Run through the color stages | 774 // Run through the color stages |
| 776 for (int s = 0; s < this->numColorStages(); ++s) { | 775 for (int s = 0; s < this->numColorStages(); ++s) { |
| 777 const GrProcessor* processor = this->getColorStage(s).getProcessor(); | 776 const GrProcessor* processor = this->getColorStage(s).getProcessor(); |
| 778 processor->computeInvariantOutput(&inoutColor); | 777 processor->getConstantColorComponents(&color, &validComponentFlags); |
| 779 } | 778 } |
| 780 | 779 |
| 781 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 780 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
| 782 if (this->isCoverageDrawing()) { | 781 if (this->isCoverageDrawing()) { |
| 783 // The shader generated for coverage drawing runs the full coverage comp
utation and then | 782 // The shader generated for coverage drawing runs the full coverage comp
utation and then |
| 784 // makes the shader output be the multiplication of color and coverage.
We mirror that here. | 783 // makes the shader output be the multiplication of color and coverage.
We mirror that here. |
| 785 GrProcessor::InvariantOutput inoutCoverage; | 784 GrColor coverage; |
| 786 inoutCoverage.fIsSingleComponent = false; | 785 uint32_t coverageComponentFlags; |
| 787 if (this->hasCoverageVertexAttribute()) { | 786 if (this->hasCoverageVertexAttribute()) { |
| 788 inoutCoverage.fValidFlags = 0; | 787 coverageComponentFlags = 0; |
| 789 inoutCoverage.fColor = 0; // suppresses any warnings. | 788 coverage = 0; // suppresses any warnings. |
| 790 } else { | 789 } else { |
| 791 inoutCoverage.fValidFlags = kRGBA_GrColorComponentFlags; | 790 coverageComponentFlags = kRGBA_GrColorComponentFlags; |
| 792 inoutCoverage.fColor = this->getCoverageColor(); | 791 coverage = this->getCoverageColor(); |
| 793 } | 792 } |
| 794 | 793 |
| 795 // Run through the coverage stages | 794 // Run through the coverage stages |
| 796 for (int s = 0; s < this->numCoverageStages(); ++s) { | 795 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 797 const GrProcessor* processor = this->getCoverageStage(s).getProcesso
r(); | 796 const GrProcessor* processor = this->getCoverageStage(s).getProcesso
r(); |
| 798 processor->computeInvariantOutput(&inoutCoverage); | 797 processor->getConstantColorComponents(&coverage, &coverageComponentF
lags); |
| 799 } | 798 } |
| 800 | 799 |
| 801 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if | 800 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if |
| 802 // coverage and color both have A==1. | 801 // coverage and color both have A==1. |
| 803 return (inoutColor.isOpaque() && inoutCoverage.isOpaque()); | 802 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && |
| 803 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); |
| 804 |
| 804 } | 805 } |
| 805 | 806 |
| 806 return inoutColor.isOpaque(); | 807 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); |
| 807 } | 808 } |
| 808 | 809 |
| OLD | NEW |