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 GrColor coverage; | 424 GrProcessor::InvariantOutput inout; |
425 uint32_t validComponentFlags; | 425 inout.fIsSingleComponent = false; |
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 validComponentFlags = 0; | 428 inout.fValidFlags = 0; |
429 } else { | 429 } else { |
430 coverage = fCoverage; | 430 inout.fColor = fCoverage; |
431 validComponentFlags = kRGBA_GrColorComponentFlags; | 431 inout.fValidFlags = 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->getConstantColorComponents(&coverage, &validComponentFlags); | 437 gp->computeInvariantOutput(&inout); |
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->getConstantColorComponents(&coverage, &validComponentFlags); | 441 processor->computeInvariantOutput(&inout); |
442 } | 442 } |
443 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); | 443 return inout.isSolidWhite(); |
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 uint32_t validComponentFlags; | 758 GrProcessor::InvariantOutput inoutColor; |
759 GrColor color; | 759 inoutColor.fIsSingleComponent = false; |
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 validComponentFlags = kA_GrColorComponentFlag; | 763 inoutColor.fValidFlags = kA_GrColorComponentFlag; |
764 color = 0xFF << GrColor_SHIFT_A; | 764 inoutColor.fColor = 0xFF << GrColor_SHIFT_A; |
765 } else { | 765 } else { |
766 validComponentFlags = 0; | 766 inoutColor.fValidFlags = 0; |
767 color = 0; // not strictly necessary but we get false alarms from to
ols about uninit. | 767 // not strictly necessary but we get false alarms from tools about u
ninit. |
| 768 inoutColor.fColor = 0; |
768 } | 769 } |
769 } else { | 770 } else { |
770 validComponentFlags = kRGBA_GrColorComponentFlags; | 771 inoutColor.fValidFlags = kRGBA_GrColorComponentFlags; |
771 color = this->getColor(); | 772 inoutColor.fColor = this->getColor(); |
772 } | 773 } |
773 | 774 |
774 // Run through the color stages | 775 // Run through the color stages |
775 for (int s = 0; s < this->numColorStages(); ++s) { | 776 for (int s = 0; s < this->numColorStages(); ++s) { |
776 const GrProcessor* processor = this->getColorStage(s).getProcessor(); | 777 const GrProcessor* processor = this->getColorStage(s).getProcessor(); |
777 processor->getConstantColorComponents(&color, &validComponentFlags); | 778 processor->computeInvariantOutput(&inoutColor); |
778 } | 779 } |
779 | 780 |
780 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 781 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
781 if (this->isCoverageDrawing()) { | 782 if (this->isCoverageDrawing()) { |
782 // The shader generated for coverage drawing runs the full coverage comp
utation and then | 783 // The shader generated for coverage drawing runs the full coverage comp
utation and then |
783 // makes the shader output be the multiplication of color and coverage.
We mirror that here. | 784 // makes the shader output be the multiplication of color and coverage.
We mirror that here. |
784 GrColor coverage; | 785 GrProcessor::InvariantOutput inoutCoverage; |
785 uint32_t coverageComponentFlags; | 786 inoutCoverage.fIsSingleComponent = false; |
786 if (this->hasCoverageVertexAttribute()) { | 787 if (this->hasCoverageVertexAttribute()) { |
787 coverageComponentFlags = 0; | 788 inoutCoverage.fValidFlags = 0; |
788 coverage = 0; // suppresses any warnings. | 789 inoutCoverage.fColor = 0; // suppresses any warnings. |
789 } else { | 790 } else { |
790 coverageComponentFlags = kRGBA_GrColorComponentFlags; | 791 inoutCoverage.fValidFlags = kRGBA_GrColorComponentFlags; |
791 coverage = this->getCoverageColor(); | 792 inoutCoverage.fColor = this->getCoverageColor(); |
792 } | 793 } |
793 | 794 |
794 // Run through the coverage stages | 795 // Run through the coverage stages |
795 for (int s = 0; s < this->numCoverageStages(); ++s) { | 796 for (int s = 0; s < this->numCoverageStages(); ++s) { |
796 const GrProcessor* processor = this->getCoverageStage(s).getProcesso
r(); | 797 const GrProcessor* processor = this->getCoverageStage(s).getProcesso
r(); |
797 processor->getConstantColorComponents(&coverage, &coverageComponentF
lags); | 798 processor->computeInvariantOutput(&inoutCoverage); |
798 } | 799 } |
799 | 800 |
800 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if | 801 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if |
801 // coverage and color both have A==1. | 802 // coverage and color both have A==1. |
802 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && | 803 return (inoutColor.isOpaque() && inoutCoverage.isOpaque()); |
803 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); | |
804 | |
805 } | 804 } |
806 | 805 |
807 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); | 806 return inoutColor.isOpaque(); |
808 } | 807 } |
809 | 808 |
OLD | NEW |